Skip to content

Hold access tokens to image scopes on the registry - #617

Open
rgarcia wants to merge 1 commit into
mainfrom
hypeship/registry-token-scopes
Open

rgarcia wants to merge 1 commit into
mainfrom
hypeship/registry-token-scopes

Conversation

@rgarcia

@rgarcia rgarcia commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The OCI registry under /v2 accepts 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 to instance:read can push images. That was tolerable while every API token was minted by someone holding jwt_secret. Since #608 an authorization server can issue narrowly scoped access tokens, and those can push too.

What changed

  • On /v2, JwtAuth holds an access token to the existing image scopes: GET/HEAD need image:read, PUT/POST/PATCH need image:write, DELETE needs image:delete. A push also reads (GET /v2/, HEAD on blobs), so a pushing client needs image:read and image:write.
  • Without the scope the request gets 403 in the OCI error format, {"errors":[{"code":"DENIED","message":"missing required scope: image:write"}]}, and no WWW-Authenticate challenge, since the token endpoint would only hand the same token back.
  • A token signed with jwt_secret keeps the registry access it has today, whatever its permissions.
  • jwtauth.Verifier.IsAccessToken exposes the decision ParseWithClaims already makes about which keys a token is checked against, so the middleware can tell the two kinds apart.
  • Docs: the sentence in docs/oauth-access-tokens.md that said the registry does not check permissions, and the Images rows of lib/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/token endpoint. 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 /v2 creates an image as POST /images does, pulling reads one, and a registry DELETE removes stored content, so the three scopes map onto the registry as they already read. DELETE is not folded into image:write, because that would let a token delete through the registry what image:delete protects 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_secret tokens: they are not checked. A scoped jwt_secret token can push and pull today, and such a token cannot be told apart from one minted after this change, so any enforcement on jwt_secret tokens would break tokens in use. Access tokens are new with #608, so nothing relies on their registry access yet. The consequence is that a jwt_secret token cannot be minted without registry access; lib/scopes/README.md says 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 -scopes carries no permissions claim, 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 default jwt_secret token and for a * access token.

Tests

TestJwtAuth_RegistryPermissions in lib/middleware sends a pull, a push and a delete with: a jwt_secret token with full access, a jwt_secret token scoped to other resources, access tokens with image:read, image:write, image:delete and *, and an access token scoped to other resources. Removing the check, applying it to jwt_secret tokens, or mapping DELETE to image:write each makes it fail.

Ran gofmt -l cmd lib, go vet and go test -race on cmd/gen-jwt, lib/scopes, lib/jwtauth, lib/middleware and lib/registry, and go 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 with image:read and image:write together. I did not run the full make test locally, as it needs KVM; CI runs it.

Known gaps

  • The bare /v2 path (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.
  • Cancelling an in-progress upload is a DELETE and so needs image: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.

Base automatically changed from hypeship/oauth-access-tokens to main November 27, 2026 20:35
@rgarcia
rgarcia force-pushed the hypeship/registry-token-scopes branch from 9ff8275 to cf5b8a8 Compare November 27, 2026 20:40
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
rgarcia force-pushed the hypeship/registry-token-scopes branch from cf5b8a8 to ad75bfc Compare November 27, 2026 20:55
@rgarcia rgarcia changed the title Hold access tokens to registry scopes under /v2 Hold access tokens to image scopes on the registry Nov 27, 2026

This branch has not been deployed

No deployments
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.

1 participant