Repository navigation
Conversation
rgarcia
force-pushed
the
hypeship/registry-token-scopes
branch
from
November 27, 2026 20:40
9ff8275 to
cf5b8a8
Compare
The registry under /v2 let every valid API token push and pull without looking at its permissions, so an access token an authorization server issued for, say, instance:read could push images. An access token now needs image:read to pull, image:read and image:write to push, and image:delete for a DELETE request, and is refused with 403 DENIED without the scope. Full access is unchanged: a token without a permissions claim and the wildcard hold all three. A token signed with jwt_secret keeps the registry access it has today, whatever its permissions. Scoped tokens in use push and pull, and they cannot be told apart from new ones.
rgarcia
force-pushed
the
hypeship/registry-token-scopes
branch
from
November 27, 2026 20:55
cf5b8a8 to
ad75bfc
Compare
This branch has not been deployed
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.
Problem
The OCI registry under
/v2accepts a builder's repository-scoped registry token or, failing that, any valid API token, without looking at the API token's permissions. A token limited toinstance:readcan push images. That was tolerable while every API token was minted by someone holdingjwt_secret. Since #608 an authorization server can issue narrowly scoped access tokens, and those can push too.What changed
/v2,JwtAuthholds an access token to the existing image scopes:GET/HEADneedimage:read,PUT/POST/PATCHneedimage:write,DELETEneedsimage:delete. A push also reads (GET /v2/,HEADon blobs), so a pushing client needsimage:readandimage:write.403in the OCI error format,{"errors":[{"code":"DENIED","message":"missing required scope: image:write"}]}, and noWWW-Authenticatechallenge, since the token endpoint would only hand the same token back.jwt_secretkeeps the registry access it has today, whatever its permissions.jwtauth.Verifier.IsAccessTokenexposes the decisionParseWithClaimsalready makes about which keys a token is checked against, so the middleware can tell the two kinds apart.docs/oauth-access-tokens.mdthat said the registry does not check permissions, and the Images rows oflib/scopes/README.md.Unchanged: builder registry tokens and their repository scoping, the 502 mirror fallback, the rejection of builder tokens on API routes,
revoked_token_hashes, and the/v2/tokenendpoint. That endpoint returns the token it was given and grants nothing, so the check lives in one place, on the registry requests themselves.Design choices
The image scopes govern the registry; no new scopes. Pushing to
/v2creates an image asPOST /imagesdoes, pulling reads one, and a registryDELETEremoves stored content, so the three scopes map onto the registry as they already read.DELETEis not folded intoimage:write, because that would let a token delete through the registry whatimage:deleteprotects on the API. The cost is coupling: an authorization server cannot grant image metadata on the API without also granting pulls. Dedicated registry scopes would separate the two and can be added if that is wanted.Compatibility for
jwt_secrettokens: they are not checked. A scopedjwt_secrettoken can push and pull today, and such a token cannot be told apart from one minted after this change, so any enforcement onjwt_secrettokens would break tokens in use. Access tokens are new with #608, so nothing relies on their registry access yet. The consequence is that ajwt_secrettoken cannot be minted without registry access;lib/scopes/README.mdsays so. Lifting this needs a way to tell old tokens from new ones, such as a marker claim on new mints, which is left out here."Default scopes". The code has no single default scope set. A token minted without
-scopescarries nopermissionsclaim, which means full access, and the*wildcard is the other form of full access. Both already hold the image scopes, so both include the registry and no definition had to change: a token minted with the defaults can use every API endpoint and push, pull and delete on the registry. The test pins this for a defaultjwt_secrettoken and for a*access token.Tests
TestJwtAuth_RegistryPermissionsinlib/middlewaresends a pull, a push and a delete with: ajwt_secrettoken with full access, ajwt_secrettoken scoped to other resources, access tokens withimage:read,image:write,image:deleteand*, and an access token scoped to other resources. Removing the check, applying it tojwt_secrettokens, or mappingDELETEtoimage:writeeach makes it fail.Ran
gofmt -l cmd lib,go vetandgo test -raceoncmd/gen-jwt,lib/scopes,lib/jwtauth,lib/middlewareandlib/registry, andgo build ./cmd/api/; all pass. Not committed: a go-containerregistry run that pushed and pulled real images through the middleware, the token endpoint and the registry with each kind of token, both sending the token with every request and through the challenge flow; its results matched the test table, and a push succeeded only withimage:readandimage:writetogether. I did not run the fullmake testlocally, as it needs KVM; CI runs it.Known gaps
/v2path (no trailing slash) is not matched as a registry path, as before, so any valid API token still gets the version probe there. It exposes no image data.DELETEand so needsimage:delete. A push does not cancel uploads unless it fails, and abandoned uploads are removed when idle.Reviewed with sol-loop: 3 rounds with openai-codex/gpt-6.2-sol on extra-high reasoning. Sol verdict: approved.