Repository navigation
Use the Docker Desktop Hub session for Docker Hub registry credentials - #14295
Conversation
…dentials Docker Hub credentials are now read first from the session of the account signed in to Docker Desktop, through the Docker Desktop secrets engine (github.com/docker/secrets-engine/client), and from the Docker CLI config file and its credential helpers otherwise. Other registries keep using the config file only. The OAuth access token is passed as the password of the signed-in account, never as an IdentityToken, which containerd sends as a refresh token. It flows unchanged to the engine in X-Registry-Auth and through the OCI resolver as an OAuth password grant. Compose falls back to the config file when Desktop is not running, nobody is signed in, the session is expired or about to expire, or the lookup fails (the last logged as a warning). The session is shared process wide, cached until shortly before it expires, and an unusable session is not asked for again. Lookups are bounded by a 5s timeout, as the SDK applies none by default. Used by pull, push, publish, config --resolve-image-digests, oci:// remote resources and dry-run. The classic builder and use_api_socket keep config file credentials, as a short-lived token copied into a container would go stale. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
…aims lack it The session payload may carry no claims, in which case the access token was reused for a minute without any expiry check, so an expired token could reach the registry and fail the pull instead of falling back. Read the exp claim from the JWT itself in that case. An expiry that cannot be read is still tolerated. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
…aging registry Docker Desktop keeps the Docker Hub staging session in separate secrets engine realms, read with dockerhub.Staging(). The environment is picked per registry host rather than with a global stage flag: the engine resolves docker.io to the production registry even when Desktop runs in stage mode, so the staging session is only used for registry-1-stage.docker.io and the production session only for the production Hub hosts. A token is never sent to the registry of the other environment. Each environment has its own process-wide session and cache, and falls back to the Docker CLI config file independently. Staging credentials use https://registry-1-stage.docker.io/ as server address. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Shorten the doc comments added for the Docker Desktop credentials provider to what the code does not already say, and drop them from the tests. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
Lower-confidence findings (not posted inline)
- [medium] internal/registry/desktop.go:201 —
errSessionExpiredtriggers permanentunavailable=true, but token may be refreshed by Desktop mid-process (confidence: weak 52/100)
It covered the resolver credential mapping and containerd grant selection, neither changed by this PR. The token-as-password contract is asserted on the provider output and on the encoded X-Registry-Auth in internal/registry. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ookup A lookup that found no usable session disabled Desktop credentials for the rest of the process. That is right within one command, where retrying a hung engine would add the lookup timeout to every image, but the sessions are process wide and pkg/compose is also used as a library: in a long-running process a transient timeout, or signing in to Desktop later, was never picked up. Hold lookups off for a minute instead of for good. Also name the expected-miss classification and test it, including dockerhub.ErrNoDefaultProfile, which wraps dockerhub.ErrNoSession. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
This review covers only the commits pushed since 6e696e4.
Assessment: 🟢 APPROVE
The incremental diff is a focused cleanup: comment and doc-string trimming throughout internal/registry/desktop.go, desktop_test.go, registry.go, pkg/compose/compose.go, pkg/compose/pull.go, pkg/remote/oci.go, and internal/oci/resolver.go, plus the functional fix that replaces the permanently-latching unavailable bool with a retryAt time.Time so a failed Desktop lookup retries after one minute.
The retry boundary logic is correct (now.Before(s.retryAt) uses strict less-than, so now == retryAt correctly allows a retry), TestDesktopAuthProvider_RetriesAfterInterval validates both sides of the boundary, and TestIsExpectedMiss correctly covers the expected-miss sentinel errors (including ErrNoDefaultProfile via its wrapping of ErrNoSession). No bugs found in the introduced lines.
Rename isExpectedMiss to isSessionUnavailable, after what it reports, and shorten or drop doc comments in the Docker Desktop credentials provider. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Match the other compose log messages, which start lowercase. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Docker Hardened Images on dhi.io authenticate with Docker Hub accounts (the registry advertises service=registry.docker.io), so resolve dhi.io credentials from the production Docker Hub session as well, with dhi.io as the server address. Other registries, including look-alikes of dhi.io, still use the Docker CLI credentials. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Docker Desktop stores Docker Hardened Images credentials under https://dhi.io, so return that as the server address of dhi.io credentials, as StagingIndexServer does for the staging registry. Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
This review covers only the commits pushed since 6d96edf26a52b4a7faf7a8992370c440b91f8fa5 (the previous completed review). Earlier commits were already reviewed.
Assessment: 🟢 APPROVE
The incremental diff adds DHI (Docker Hardened Images) registry support by introducing DHIRegistryHost/DHIIndexServer constants and routing dhi.io credentials through the existing Hub Desktop session. The implementation is structurally sound:
- The
registryHost()refactor (replacingisStagingRegistry()) correctly strips scheme and trailing slash before comparing hosts. - The
sessionFor()new case correctly routesdhi.ioto the Hub session. - The
GetAuthConfigoverride setsauth.ServerAddress = DHIIndexServeronly when the Desktop session is used; the CLI fallback path passes the raw hostname and is unaffected. DHIIndexServeromits a trailing slash (unlikeIndexServerandStagingIndexServer), but this is intentional: it is used only as an informationalServerAddressvalue in the returnedAuthConfig, not as a credentials-store lookup key. The testTestDesktopAuthProvider_DHIUsesDockerHubSessionasserts this behavior explicitly. No real bug is introduced.- Comment trimming and the
isExpectedMiss→isSessionUnavailablerename are cosmetic with no behavioral change.
What this PR does
Compose now reads Docker Hub credentials from the account signed in to Docker Desktop, through the Docker Desktop secrets engine (
github.com/docker/secrets-engine/client), before falling back to the Docker CLI config file and its credential helpers. Images on the Docker Hub staging registry (registry-1-stage.docker.io) use Desktop's staging session. Every other registry is unchanged.Related issue
None yet: there is no
status/approvedissue for this. Opened as a draft to discuss the approach.Changes made
internal/registry: newNewDesktopAuthProvider, layered over the Docker CLI config file. The Desktop OAuth access token is passed as the password of the signed-in account, never as anIdentityToken(which containerd treats as a refresh token), so it reaches the engine inX-Registry-Authand the OCI resolver as an OAuth password grant.docker.ioto production even when Desktop runs in stage mode).publish,config --resolve-image-digests,oci://remote resources and--dry-run. The classic builder anduse_api_socketkeep CLI credentials, since a short-lived token copied into a container would go stale. Builds through buildx bake,docker modeland provider plugins look up credentials themselves and are unaffected.ImageDigestResolverkeeps its signature; the internaloci.NewResolvernow takes aregistry.AuthProvider.Testing done
make test. Rango teston the affected packages instead (./internal/...,./pkg/compose,./pkg/dryrun,./pkg/remote,./cmd/...), the new tests also with-race.make e2e-compose-standalone(TestComposePull,TestPullImagePresentLocally,TestPullNoImageNameGiven,TestPullFailure,TestPullIgnoreFailures,TestUpDryRunMissingImage,TestComposeRunPullAlways,TestPublish).make lint. Rangolangci-lint runlocally (v2.14.0) instead: 0 issues.make fmt. Rangolangci-lint fmtinstead: clean.registry-1-stage.docker.io; the registry identified the signed-in account's organization and then refused the image under an image access policy. Not tested on Windows or Linux.Authentication latency per OS (2026-10-07)
Docker Hub credentials lookup from the secrets engine vs. a credential helper, both reading the real OS keychain. Measured once in arm64 VMs with throwaway programs that are not part of this PR: the secrets-engine runtime with the docker-auth plugin and its default keychain store, and the official
docker-credential-helpersv0.9.9 binaries. Each figure is the mean of 50 lookups after 3 warm-ups. Starting the engine is not timed.osxkeychain)secretservice)wincred)AI tool used (if applicable)
AI Tool: alki, a coding agent running Claude Opus 5.5. The investigation, implementation and tests were AI-generated, with the design choices directed by the author.
alki ran the per-OS latency measurements and wrote their table.
Additional context
Open questions for review: