Repository navigation
Description
Summary
Docker Compose uses the Docker Desktop Docker Hub session (via client/dockerhub) to authenticate pulls. To turn a session into a credential it can use, Compose wraps the SDK with its own code. Most of that code is not specific to Compose: any consumer that wants "the signed-in user Docker Hub credential" (the CLI, buildx, other tools) would write the same thing.
This issue tracks what client/dockerhub still lacks, checked at client/v1.0.0. Items 1, 2, and 5 of the original list are done; see Resolved.
Compose implementation (on client/v1.0.0, docker/compose#14541): internal/registry/desktop.go
Open
3. An expired session is returned as if it were valid
GetDefaultSession returns the stored token even after it has expired. Every caller checks the expiry itself and defines its own error. Compose, in desktopSession.fetch:
var errSessionExpired = errors.New("the session has expired (not signed in to Docker Desktop?)")
// ...
if exp := session.Claims.ExpiresAt; exp != nil {
validUntil = exp.Add(-sessionExpirySkew)
if !now.Before(validUntil) {
return ..., errSessionExpired
}
}UserSession.ExpiresWithin (item 2) makes the check shorter, but each caller still has to make it and still needs its own error.
Ask: a dockerhub.ErrSessionExpired that wraps ErrNoSession, returned for an expired stored token, ideally with a configurable clock-skew margin.
4. No single check for "no usable session"
To choose between quietly falling back to other credentials and warning the user, Compose checks three unrelated errors, in isSessionUnavailable:
func isSessionUnavailable(err error) bool {
if _, ok := errors.AsType[*seclient.ConnectError](err); ok {
return true
}
return errors.Is(err, dockerhub.ErrNoSession) || errors.Is(err, errSessionExpired)
}Since client/v0.2.0, a failed connection is a *client.ConnectError that matches client.ErrSecretsEngineNotRunning, ErrSecretsEnginePermissionDenied, or ErrSecretsEngineTimeout. That is an improvement, but there is still no single check that covers "cannot reach the engine", "nobody signed in", and "session expired".
Ask: with item 3 in place, document one check for this case, or provide a helper such as dockerhub.IsUnavailable(err).
6. (Optional) A caching, retrying credential source
Compose wraps the lookup in desktopSession: one shared lookup for concurrent pulls, reuse of the credential until shortly before it expires, and a back-off after a failed lookup so it does not ask Docker Desktop on every pull.
This is generic too. A wrapper such as dockerhub.NewCachedAuth(auth, opts...) would help, but it is the most debatable item if the SDK wants to stay stateless.
Proposal
Item 3 and the username could become one call that returns what a registry client needs:
type Credential struct {
Username string
AccessToken string
ExpiresAt time.Time // zero if unknown
}
// GetDefaultCredential returns the default account credential. It returns
// ErrNoDefaultProfile / ErrNoSession when nobody is signed in, and
// ErrSessionExpired (wrapping ErrNoSession) when the stored token has expired.
GetDefaultCredential(ctx context.Context) (Credential, error)With that and item 4, the Compose side shrinks to building a types.AuthConfig from Credential: errSessionExpired, isSessionUnavailable, and the fallback to GetDefaultProfile for the username would go away.
Happy to send PRs for any of these.
Resolved
- 1.
GetDefaultSessiondoes not give you a username. Not changing the API:UserSession.Claims.Usernameis the field to use. It was empty because Docker Desktop did not always parse the token claims when it stored the credential; that is fixed, and a migration makes it consistent for stored credentials. See the first comment. - 2. No token expiry helper.
UserSession.Expired()andUserSession.ExpiresWithin(d)were added inclient/v0.2.1(feat(client/dockerhub): add UserSession expiry helpers #689). - 5. Connecting to Desktop requires the unstable
xmodule.client/config.DesktopSocketPath()is available inclient/v1.0.0, which no longer depends ongithub.com/docker/secrets-engine/x(refactor(client): move socket paths from x/api to client/config #731).
Activity
Benehiko commentedon Oct 9, 2026
Update on items 1 and 2: we won't add a separate
Usernamefield toUserSession.UserSession.Claims.Usernameis the field to use.Claims.Usernamecame back empty because Docker Desktop didn't always parse the access token's claims when it stored the credential. That's fixed, so in most casesClaimsis now filled in, includingexp. A migration is underway that will make this consistent for all stored credentials. Once it's done, Compose'sGetDefaultProfilefallback and its own JWTexpdecoding shouldn't be needed.Closing #683, which added the field. Items 3–6 are unaffected.
Benehiko commentedon Nov 24, 2026
Status update: items 2 and 5 have shipped.
UserSession.Expired()andUserSession.ExpiresWithin(d)were added inclient/v0.2.1(feat(client/dockerhub): add UserSession expiry helpers #689). They readClaims.ExpiresAt, and a session without an expiry counts as expired.x:client/config.DesktopSocketPath()is available inclient/v1.0.0, which no longer depends ongithub.com/docker/secrets-engine/x(refactor(client): move socket paths from x/api to client/config #731). Compose moved to it in chore(deps): bump secrets-engine/client to v1.0.0 and drop secrets-engine/x compose#14541.Item 1 is covered by the earlier comment (
Claims.Username).Still open:
dockerhub.ErrSessionExpired, wrappingErrNoSession, returned for an expired stored token.client/v0.2.0, a failed connection is reported as*client.ConnectError, so today a caller checks for aConnectError, forErrNoSession, and for its own expiry error separately.[-]client/dockerhub: return a ready-to-use Docker Hub credential (username, expiry, expired-session error, Desktop connect)[/-][+]client/dockerhub: expired-session error, single "no usable session" check, optional caching helper[/+]