Treat the service parameter as optional in Bearer auth challenges - #901
Open
Syed-Umair wants to merge 1 commit into
Open
Treat the service parameter as optional in Bearer auth challenges#901Syed-Umair wants to merge 1 commit into
Syed-Umair wants to merge 1 commit into
Conversation
`createTokenRequest` rejected any `WWW-Authenticate: Bearer` challenge that omitted `service`, so authenticating to a registry that does not send it failed with "cannot parse service from WWW-Authenticate header". Google Artifact Registry is one such registry: it replies with only `Bearer realm="https://LOCATION-docker.pkg.dev/v2/token"`. `service` is a convention of the Docker registry token spec rather than a requirement of RFC 6750 section 3, and `parseWWWAuthenticateHeaders` already modelled it as optional — `AuthChallengeTests` covers a challenge without it. Only `createTokenRequest` treated it as mandatory, so the two disagreed. Make `TokenRequest.service` optional and omit the `service` query item when the challenge did not supply one. A challenge that does carry `service` is unaffected, so Docker Hub and GHCR behaviour does not change. `realm` stays mandatory, since without it there is nowhere to send the token request.
Syed-Umair
force-pushed
the
optional-service-in-auth-challenge
branch
from
September 3, 2026 10:24
2729ca0 to
4a74154
Compare
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.
What
createTokenRequestrejects anyWWW-Authenticate: Bearerchallenge that omitsservice, so logging in to a registry that does not send it fails with:Google Artifact Registry is one such registry. Its challenge carries only a realm:
This makes
container registry login(and thereforecontainer image push/pull) unusable against Artifact Registry.Why this is the right fix
serviceis a convention of the Docker registry token spec, not a requirement of RFC 6750 §3, so a conforming registry may omit it.parseWWWAuthenticateHeadersalready modelsserviceas optional, andAuthChallengeTestshas a case for a challenge without it. OnlycreateTokenRequesttreated it as mandatory, so the parser and its one caller disagreed. This change makes the caller match the parser.realmstays mandatory — without it there is nowhere to send the token request.Change
TokenRequest.servicebecomesString?.fetchTokenappends theservicequery item only when the challenge supplied one.createTokenRequestpasses the optional through instead of rejectingnil.A challenge that does carry
serviceproduces an identical request to before, so Docker Hub and GHCR are unaffected.Verification
Artifact Registry issues a token when
serviceis omitted:With
containerbuilt against this change, against a real Artifact Registry repository:Both fail on 1.3.1 with the error above. Pushes to Docker Hub still work.
Tests/ContainerizationOCITests/TokenRequestServiceTests.swiftadds coverage for the service-less challenge, the service-present case, and the still-rejected missing realm. It compiles, but I could not execute the suite locally —swift testneedsTesting.frameworkfrom a full Xcode install and every test target fails to load without it, so CI results are the ones to trust here.