fix(desktop): force token refresh when Docker Desktop returns an expired JWT#3773
Merged
Conversation
…red JWT Assisted-By: docker-agent
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟡 NEEDS ATTENTION
1 medium-severity finding in the new forced-refresh path.
Lower-confidence findings (not posted inline)
- [low] pkg/desktop/login.go:120 — goroutine closes
donechannel after releasing lock (brief window where new caller observes inflight==nil before channel is closed) (confidence: weak 43/100) - [low] pkg/desktop/login.go:150 — poll loop fetches token immediately after POST before async Desktop refresh could occur (minor inefficiency) (confidence: weak 30/100)
- [low] pkg/desktop/login.go:52 — expiry leeway is applied as a 30s grace period after expiry rather than before — may serve tokens expired up to 30s ago (confidence: weak 30/100)
- [low] pkg/desktop/login_test.go:205 — cleanup ordering may expose detached goroutine to restored global values (potential flakiness) (confidence: weak 30/100)
…budget Cap the POST /registry/credstore-updated call to refreshBudget/3 via a new postRefreshNudge helper so a slow Desktop can't exhaust the whole refresh budget before polling begins. Also move close(done) under the refreshState lock to close a brief window where a new caller could observe inflight==nil before the channel is closed. Assisted-By: Claude
trungutt
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Docker Desktop's auth v2 stack (behind the
SIGN_IN_V2feature flag) never refreshes the JWT it holds on aGET /registry/tokenrequest — it returns whatever its in-memory token source currently contains. When Desktop's background refresher stalls on a permanent 4xx (e.g. a PAT/hub token error), it keeps serving the same expired JWT indefinitely, and retrying the endpoint from docker-agent's side never helps.desktop.GetTokennow parses the JWTexpclaim (with 30s clock-skew leeway). When the token is expired, it forces a Desktop-side refresh byPOSTing/registry/credstore-updated— the same hook the Docker CLI triggers afterdocker login, which makes Desktop reload its session from the OS credential store and issue a fresh token — then pollsGET /registry/tokenuntil a non-expired token appears. A single detached goroutine performs the refresh under a hard 10s budget; concurrent callers share its result via singleflight and can bail on their own context cancellation, falling back to the stale token (preserving the previous behavior). After a successful refresh a 30s cooldown applies; after failure, a 2-minute backoff. Non-JWT tokens, empty tokens, and tokens without anexpclaim pass through unchanged.raw_client.gogains aPostmethod to support the new endpoint.Tests use an in-memory fake Desktop backend over
net.Pipeand cover refresh success and failure, backoff, cached-result reuse, 8-way concurrent refresh sharing, caller cancellation, and non-JWT/empty token pass-through.