Repository navigation
Description
What is the issue?
Container.withRegistryAuth changes the cache identity of an otherwise unchanged container. Image pulls and downstream executions then miss the cache across Dagger sessions.
Registry credentials are session state and are not stored in core.Container. Therefore, adding credentials should not change the container filesystem or invalidate downstream execution cache entries.
The problem occurs even when the configured registry address is unrelated to the image being pulled:
client.Container().
WithRegistryAuth("registry.example.com", "anyuser", secret).
From("alpine:3.20").
WithExec(...)The same execution without WithRegistryAuth is cached across sessions. The authenticated branch runs again and produces a different random value.
This reproduces with Dagger v0.21.8, v1.0.0-beta.9, and current main at b068d8a7b. The original user report is in Discord.
Expected
withRegistryAuth registers credentials in the current session without changing the identity of the returned container. If the resolved image digest and execution inputs are unchanged, image and execution cache entries should be reusable across sessions.
Actual
The authenticated branch has a different identity in every session. The digest-qualified Container.from operation runs instead of reporting CACHED, a nested pull span appears, and downstream withExec runs again.
Root cause
withRegistryAuth is registered with dagql.PerSessionInput. Its resolver mutates the session authentication provider and returns the unchanged Go container pointer. However, dagql.Func wraps that pointer in a new result whose recipe contains the session ID.
That session-scoped result becomes the receiver of Container.from and all later operations. It also prevents the canonical From path from assigning its stable image content identity because the direct parent call is withRegistryAuth, not the bare container call.
The behavior was introduced by 3fde468ad and first appeared in v0.21.1. That change fixed a real problem where the authentication side effect could be skipped in a new session, but it coupled session-local side-effect execution to the semantic identity of the returned container.
withoutRegistryAuth has the same identity and mutable-side-effect concerns.
Suggested fix
Treat withRegistryAuth and withoutRegistryAuth as non-cacheable session operations while returning the attached parent container result. This keeps explicit credential mutations ordered and ensures that registry authentication does not become part of the container identity.
Dagger version
dagger v0.21.8 (image://registry.dagger.io/engine:v0.21.8) linux/amd64
Also reproduced with:
client-version=v1.0.0-beta.9
server-version=v1.0.0-beta.9+1c6e07b1
Steps to reproduce
Create a Go program using dagger.io/dagger v0.21.8:
package main
import (
"context"
"fmt"
"os"
"strings"
"dagger.io/dagger"
)
func main() {
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stderr))
if err != nil {
panic(err)
}
defer client.Close()
stamp := []string{"sh", "-c", "cat /proc/sys/kernel/random/uuid > /stamp; cat /stamp"}
control := client.Container().
From("alpine:3.20").
WithExec(stamp)
bug := client.Container().
WithRegistryAuth(
"registry.example.com",
"anyuser",
client.SetSecret("s", "dummy"),
).
From("alpine:3.20").
WithExec(stamp)
controlStamp, err := control.File("/stamp").Contents(ctx)
if err != nil {
panic(err)
}
bugStamp, err := bug.File("/stamp").Contents(ctx)
if err != nil {
panic(err)
}
fmt.Println("CONTROL", strings.TrimSpace(controlStamp))
fmt.Println("BUG ", strings.TrimSpace(bugStamp))
}Run it in two separate sessions:
go mod init registry-auth-cache-repro
go get dagger.io/[email protected]
go run .
go run .To test v1.0.0-beta.9, add this connection option and run the program directly:
dagger.WithEnvironmentVariable("DAGGER_X_RELEASE", "v1.0.0-beta.9")Log output
Session 1
CONTROL 3c58afe2-abf3-4aa3-90a3-ec5c0f381c70
BUG cb70c53c-12ae-413a-9b16-892d34178fbd
Session 2
CONTROL 3c58afe2-abf3-4aa3-90a3-ec5c0f381c70
BUG 10087caa-e917-4062-aebe-f761d87a14be
Verbose spans show the difference:
# Control branch
Container.from CACHED
Container.withExec CACHED
# withRegistryAuth branch, in both sessions
pulling docker.io/library/alpine:3.20@sha256:... DONE
Container.from DONE
Container.withExec DONE
Activity