Skip to content

registry: authorize with Secrets Engine before reading the Docker Desktop session - #14542

Merged
ndeloof merged 3 commits into
docker:mainfrom
Benehiko:registry/desktop-authorize
Dec 4, 2026
Merged

ndeloof merged 3 commits into
docker:mainfrom
Benehiko:registry/desktop-authorize

Conversation

@Benehiko

@Benehiko Benehiko commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Note

Builds on #14541, which bumped github.com/docker/secrets-engine/client to v1.0.0 and is now merged. Tested against Docker Desktop on macOS with a binary that is not signed by Docker (see Docker Desktop test). Not yet tested with a Docker-signed build, on Linux or Windows, or with the E2E suite.

What this PR does

These changes are for Compose binaries that are not signed by Docker: Compose built from source, for local development, and the binaries that run the tests. Docker Desktop prompts the user before it gives such a binary access to the Docker Hub session. Compose binaries signed by Docker should get no prompt: for them Compose makes a version request and an Authorize call before the first session read, and Docker Desktop answers Authorize without asking the user.

  • Calls Authorize on docker/auth/** before reading the Docker Desktop session, so Docker Desktop prompts at most once per process, and gives the user up to 1 minute to answer that prompt. Before this, every lookup from a binary not signed by Docker timed out after 5 seconds while the prompt was still open, and fell back to the Docker CLI credentials.
  • Gives Authorize that time only once the engine has answered a version request within 1 second, so an engine that hangs falls back after 1 second. Builds signed by Docker get no prompt, so for them Authorize answers without waiting on the user.

Related issue

No Compose issue. Builds on #14541 (merged).

Changes made

registry: authorize with Secrets Engine before reading the Docker Desktop session:

  • Before the first session read, desktopSession calls Authorize(docker/auth/**). That pattern covers docker/auth/hub/**, docker/auth/metadata/hub/**, and their hub-staging counterparts, so one decision serves both the production and the staging session.
  • Authorize gets a 1 minute timeout (desktopAuthorizeTimeout), to leave time for the prompt. The session reads keep the 5 second desktopLookupTimeout, now applied through their contexts only: the client-wide WithTimeout(5s) is removed, since it would cut the prompt short.
  • The decision is kept until the expiry Docker Desktop returns; a zero expiry is kept for the life of the process.
  • A deny decision returns secrets.ErrAccessDenied and an Authorize error is wrapped; both fall back to the Docker CLI credentials and are not retried for retryInterval, like any other failed lookup.

registry: wait for the Docker Desktop prompt only when the secrets engine answers and registry: give the secrets engine version check 1 second:

  • The secrets engine API cannot say that it is waiting for the user: Authorize is a unary RPC and Decision is only DENY or ALLOW.
  • Before Authorize, desktopSession calls Version (desktopHub.Ping) within the 1 second desktopPingTimeout. Only if it answers does Authorize get the 1 minute desktopAuthorizeTimeout. Version is not gated by a prompt: it answered in 9.6 ms from a new process, against secrets engine v0.5.0 in Docker Desktop.
  • The ping runs once per authorization decision, not per lookup. A ping that fails, with a ConnectError or a timeout, falls back without calling Authorize or reading the session.
  • A Version timeout is reported as a seclient.ConnectError with ReasonTimeout and the socket path (secrets engine did not respond in time at <socket>), so it is logged at debug level like a missing socket or a refused connection, instead of as a warning with only the RPC deadline error. A timeout on the prompt or on the session reads is still a warning.
  • An expired decision is cleared before authorizing again.
step timeout
Version 1 s
Authorize, after Version answered 1 min
session reads 5 s

Tests: the pattern sent is docker/auth/** and contains the four Hub realms; Ping calls Version, reports a timeout as the engine not responding, and keeps other errors as they are; authorization and the ping happen once across session refetches; authorization happens again after the decision expires; a denial, an access-denied error, or an unanswered prompt falls back without reading the session or pinging again; a failed ping falls back without authorizing; the ping gets at most 1 second and Authorize the longer timeout; the production timeouts are 1 s, 5 s, and 1 min.

Docker Desktop test

A throwaway program, not part of this PR, called registry.NewDesktopAuthProvider against the running Docker Desktop on macOS (darwin/arm64), with a fallback that marks the Docker CLI credentials. It looked up docker.io, index.docker.io, registry-1.docker.io, https://index.docker.io/v1/, dhi.io, registry-1-stage.docker.io, and ghcr.io, twice each. Tokens were never printed. The binary is built by go run, so it is not signed by Docker and Docker Desktop prompts for it.

before this PR (#14541 alone) this PR
Docker Hub addresses timeout after 5.0 s, Docker CLI credentials Docker Desktop session; 5.3 s, the prompt included
dhi.io Docker CLI credentials Docker Desktop session, ServerAddress https://dhi.io
registry-1-stage.docker.io timeout after 5.0 s no second prompt (25 ms); falls back because this account's staging session expired on 2026-10-07
ghcr.io Docker CLI credentials, Docker Desktop not contacted same
second round Docker CLI credentials, no new lookup all from cache, no new lookup

Against the real secrets engine client, without Docker Desktop, after the change to how a Version timeout is reported:

socket Docker Hub lookup result
Accepts connections and never answers 1.0 s debug log only (secrets engine did not respond in time at <socket>), Docker CLI credentials; Authorize never called
Missing 1 ms debug log only (secrets engine is not running at <socket>), Docker CLI credentials
Refuses the connection under 1 ms debug log only (secrets engine is not running at <socket>), Docker CLI credentials
  • A process that looks up both Docker Hub and the staging registry against a hung engine waits 1 second for each; before this PR it waited 5 seconds for each.
  • Authorize returned an expiry about 11 hours ahead.
  • Docker Hub access tokens from Docker Desktop lasted 15 minutes.

Testing done

  • Unit tests pass for internal/registry, with -race
  • E2E tests pass: make e2e-compose or make e2e-compose-standalone
  • Linting passes: golangci-lint run ./internal/registry/... (not the full make lint)
  • Code formatted: golangci-lint fmt ./internal/registry/...
  • Manually tested (describe): against Docker Desktop on macOS with a binary not signed by Docker, and against an engine socket that never answers, a missing socket, and a socket that refuses the connection, see Docker Desktop test. Not tested with a Docker-signed build, or on Linux or Windows.

Open items

  • Is 1 minute right for desktopAuthorizeTimeout? It applies only after the engine has answered a version request, and builds signed by Docker get no prompt, but an engine that answers Version and then hangs on Authorize would still delay the first Docker Hub lookup by up to 1 minute.
  • While the prompt is open, other Docker Hub lookups in the same process wait on the session lock, so they share one prompt. The first Ctrl+C or SIGTERM does not end that wait: it cancels the command context, but the lookup does not receive it, so the command returns only once Authorize does, after at most 1 minute. A second Ctrl+C exits at once. AuthProvider.GetAuthConfig takes no context because it follows the Docker CLI's configfile.GetAuthConfig; passing the caller's context needs to start in the Docker CLI and be picked up here, not in this PR.
  • Is docker/auth/** the realm to authorize? It also covers docker/auth/registry/**, which Compose does not read.
  • Secrets engine: a way for Authorize to report that it is waiting for the user, such as a streamed status or a pending decision, would let clients wait for the prompt and fail fast otherwise, instead of relying on Version.
  • Test with a Docker-signed build, which Docker Desktop does not prompt for, and on Linux and Windows.

AI tool used (if applicable)

AI Tool: alki, an AI coding agent, running Claude Opus 5.5. It wrote the code changes and the tests, ran the tests and the Docker Desktop test, and wrote this description.

@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)

  • [low] internal/registry/desktop.go:171 — s.authorized not reset to false after re-authorization fails (confidence: not verified, low severity)
  • [low] internal/registry/desktop_test.go:596 — TestDesktopAuthProvider_FallsBackWhenNotAuthorized does not assert pingCalls, leaving retry-on-denied behaviour partially untested (confidence: not verified, low severity)

Comment thread internal/registry/desktop.go Resolved
Comment thread internal/registry/desktop.go Resolved
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Benehiko
Benehiko force-pushed the registry/desktop-authorize branch 2 times, most recently from e0d0f44 to bd3e8b7 Compare November 25, 2026 12:22
@Benehiko

Copy link
Copy Markdown
Member Author

On the two lower-confidence findings from the docker-agent review, both addressed in cc2783f: authorize() now clears s.authorized and s.authorizedUntil before asking again once the decision has expired (it was already re-checked through authorizedUntil, so this only makes the state explicit), and TestDesktopAuthProvider_FallsBackWhenNotAuthorized now asserts pingCalls.

@Benehiko Benehiko changed the title registry: authorize docker/auth/** before reading the Docker Desktop session registry: authorize with Secrets Engine before reading the Docker Desktop session Dec 3, 2026
…ktop session

Docker Desktop can prompt the user before it gives a process access to a realm, and reading the default Docker Hub session reads from two realms, docker/auth/metadata/hub/** and docker/auth/hub/**. The 5 second lookup timeout expired before the user could answer, so the lookup fell back to the Docker CLI credentials.

Call Authorize once on docker/auth/**, which covers the production and staging realms, with a one minute timeout, and keep the decision until the expiry Docker Desktop returns. The session reads keep their 5 second timeout. A denied or unanswered authorization falls back to the Docker CLI credentials like any other failed lookup.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
…gine answers

Authorize has a one minute timeout, so the user can answer the Docker Desktop prompt. An engine that accepts the connection but never answers looked the same, and delayed the first Docker Hub lookup by a minute.

Ask the engine for its version first, within the 5 second lookup timeout, and only then call Authorize. The secrets engine API has no way to say that it is waiting for the user, but the version request is not gated by a prompt: it answered in about 10 ms from a new process. An engine that does not answer now falls back after 5 seconds, as before.

A version request that times out returned only the RPC deadline error, which was logged as a warning. Report it as a ConnectError with ReasonTimeout and the socket path, so it reads as the secrets engine not responding and is logged at debug level, like a socket that is missing or refuses the connection. A timeout on the prompt or on the session reads is still logged as a warning.

Clear an expired decision before authorizing again, so a failed authorization does not leave the old one in place.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
The version request that comes before Authorize is not gated by a prompt and answered in about 10 ms from Docker Desktop, so it does not need the 5 second lookup timeout. With 1 second, an engine that accepts the connection but does not answer falls back to the Docker CLI credentials after 1 second instead of 5. The session reads keep 5 seconds and Authorize keeps 1 minute.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko
Benehiko force-pushed the registry/desktop-authorize branch from bd3e8b7 to c5d33a9 Compare December 3, 2026 10:10
@Benehiko
Benehiko marked this pull request as ready for review December 3, 2026 11:27
@Benehiko
Benehiko requested review from a team as code owners December 3, 2026 11:27
@Benehiko
Benehiko requested review from glours and ndeloof December 3, 2026 11:27

@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

Comment thread internal/registry/desktop.go Resolved
@ndeloof
ndeloof merged commit 2beea81 into docker:main Dec 4, 2026
66 of 67 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