Skip to content

Use the Docker Desktop Hub session for Docker Hub registry credentials - #14295

Merged
ndeloof merged 12 commits into
docker:mainfrom
Benehiko:desktop-hub-auth
Oct 7, 2026
Merged

ndeloof merged 12 commits into
docker:mainfrom
Benehiko:desktop-hub-auth

Conversation

@Benehiko

@Benehiko Benehiko commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

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/approved issue for this. Opened as a draft to discuss the approach.

Changes made

  • internal/registry: new NewDesktopAuthProvider, layered over the Docker CLI config file. The Desktop OAuth access token is passed as the password of the signed-in account, never as an IdentityToken (which containerd treats as a refresh token), so it reaches the engine in X-Registry-Auth and the OCI resolver as an OAuth password grant.
  • Falls back to the CLI credentials when Desktop isn't running, nobody is signed in, the session is expired or about to expire, or the lookup fails (the last is logged as a warning). The expiry comes from the session claims, or from the JWT when the claims carry none.
  • One session per environment per process, shared by all callers and cached until shortly before it expires; after a lookup finds no usable session, Desktop isn't asked again for a minute. Lookups are bounded by a 5s timeout, since the SDK applies none by default.
  • Production and staging are picked per registry host, so a token is only ever sent to the registry of the environment that issued it (the engine resolves docker.io to production even when Desktop runs in stage mode).
  • Used by pull, push, publish, config --resolve-image-digests, oci:// remote resources and --dry-run. The classic builder and use_api_socket keep CLI credentials, since a short-lived token copied into a container would go stale. Builds through buildx bake, docker model and provider plugins look up credentials themselves and are unaffected.
  • The public ImageDigestResolver keeps its signature; the internal oci.NewResolver now takes a registry.AuthProvider.

Testing done

  • Unit tests pass: make test. Ran go test on the affected packages instead (./internal/..., ./pkg/compose, ./pkg/dryrun, ./pkg/remote, ./cmd/...), the new tests also with -race.
  • E2E tests pass: a subset of make e2e-compose-standalone (TestComposePull, TestPullImagePresentLocally, TestPullNoImageNameGiven, TestPullFailure, TestPullIgnoreFailures, TestUpDryRunMissingImage, TestComposeRunPullAlways, TestPublish).
  • Linting passes: make lint. Ran golangci-lint run locally (v2.14.0) instead: 0 issues.
  • Code formatted: make fmt. Ran golangci-lint fmt instead: clean.
  • Manually tested against Docker Desktop on macOS. With an expired production session, Compose fell back to the CLI credentials and the pull succeeded. With a staging session, Compose used it for 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-helpers v0.9.9 binaries. Each figure is the mean of 50 lookups after 3 warm-ups. Starting the engine is not timed.

OS (keychain) Scenario Secrets engine Credential helper Credential helper vs. secrets engine
macOS 26.6.1 (login keychain, osxkeychain) Normal, first lookup 4.21 ms 7.41 ms 1.8× slower
Normal, repeat lookup 1.99 ms 7.40 ms 3.7× slower
Unavailable 0.031 ms 0.003 ms ~10× faster (both under 0.05 ms)
Hang 5.0 s timeout, then CLI fallback Never returns Unbounded: helpers have no timeout
Linux, Ubuntu 24.04 (gnome-keyring, secretservice) Normal, first lookup 15.01 ms 7.11 ms 2.1× faster
Normal, repeat lookup 9.95 ms 7.78 ms 1.3× faster
Unavailable 0.024 ms 0.005 ms ~5× faster (both under 0.05 ms)
Hang 5.0 s timeout, then CLI fallback Never returns Unbounded: helpers have no timeout
Windows 11 (Credential Manager, wincred) Normal, first lookup 1.64 ms 10.34 ms 6.3× slower
Normal, repeat lookup 1.00 ms 10.50 ms 10.5× slower
Unavailable 0.095 ms 0.46 ms 4.9× slower
Hang 5.0 s timeout, then CLI fallback Never returns Unbounded: helpers have no timeout
  • First lookup is a new secrets-engine client, as on the first lookup of a compose command; Compose then caches the session. The helper starts a new process on every lookup.
  • Unavailable is the engine not running vs. the helper not installed; hang is an engine that never answers vs. a helper that never exits. Neither touches the keychain.
  • Linux is slower on the engine side because a lookup reads the keychain twice (default profile, then session), and the Linux keychain store opens a new D-Bus connection and Secret Service session for each read (5.1 ms each); the helper reads once.
  • Timings exclude registry requests and image downloads, and use a fake account, so registry acceptance of the token is not covered.

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:

  • Should there be a way to turn this off, such as an environment variable?
  • If Desktop denies Compose access to the session, Compose falls back with a warning. Should it fail instead?
  • The local Desktop session is used even when the current context points at a remote engine, as credential helpers are today. Should it only apply when Desktop is the active engine?

…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 docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟡 NEEDS ATTENTION

Lower-confidence findings (not posted inline)

  • [medium] internal/registry/desktop.go:201 — errSessionExpired triggers permanent unavailable=true, but token may be refreshed by Desktop mid-process (confidence: weak 52/100)

Comment thread internal/registry/desktop.go Resolved
Comment thread internal/registry/desktop.go Resolved
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

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.10145% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/registry/desktop.go 98.14% 1 Missing and 1 partial ⚠️
pkg/compose/pull.go 75.00% 1 Missing ⚠️
pkg/compose/push.go 0.00% 1 Missing ⚠️

📢 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>
@Benehiko
Benehiko requested a review from docker-agent October 7, 2026 08:59

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Benehiko
Benehiko marked this pull request as ready for review October 7, 2026 09:51
@Benehiko
Benehiko requested review from a team as code owners October 7, 2026 09:51
@Benehiko
Benehiko requested review from glours and ndeloof October 7, 2026 09:51

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (replacing isStagingRegistry()) correctly strips scheme and trailing slash before comparing hosts.
  • The sessionFor() new case correctly routes dhi.io to the Hub session.
  • The GetAuthConfig override sets auth.ServerAddress = DHIIndexServer only when the Desktop session is used; the CLI fallback path passes the raw hostname and is unaffected.
  • DHIIndexServer omits a trailing slash (unlike IndexServer and StagingIndexServer), but this is intentional: it is used only as an informational ServerAddress value in the returned AuthConfig, not as a credentials-store lookup key. The test TestDesktopAuthProvider_DHIUsesDockerHubSession asserts this behavior explicitly. No real bug is introduced.
  • Comment trimming and the isExpectedMiss → isSessionUnavailable rename are cosmetic with no behavioral change.

@ndeloof
ndeloof merged commit e22de3b into docker:main Oct 7, 2026
62 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants