Repository navigation
Conversation
Registry bearer tokens are cached by owner, remote and scope, without the credentials. Every preflight of a registry import used the owner "import:preflight", so for up to ten minutes after one passed, another against the same registry passed on its token with a wrong password or none, and the import failed only later in the worker. Each preflight now uses "import:preflight:<uuid>". The token cache is bounded (4096 entries; expired ones are dropped, then the one expiring first), so the one-shot entries do not accumulate. Fixes #775 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJXTLoh81yv4n9VkSmx
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.
Fixes #775
Problem
Registry bearer tokens are cached process-wide under
{owner}:{remote}:{scope}(crates/server/src/images/proxy.rs), without the credentials, for up to 600 s. Every preflight of a registry import authenticated as the same owner,"import:preflight". Within ten minutes of a preflight that passed, another against the same registry reused its bearer for/v2/and the catalog and passed with a wrong password or none; the import was stored and failed only later, in the worker.Change
crates/server/src/admin/imports.rs: each preflight authenticates asimport:preflight:<uuid>, so it finds no token of another preflight and exchanges the credentials it was given. Of the two options the issue names I took the per-preflight owner: it is one line at the call site, and a preflight still reuses its own token between/v2/and the catalog. Bypassing the cache would have needed a new switch throughUpstream::send, which the proxies and the import worker share.crates/server/src/images/import.rs: theownerfield's comment says why an owner is never shared.The cache stays bounded
What I found in
cache_token(images/proxy.rs):MAX_CACHED_TOKENS= 4096 entries. An insert into a full cache first drops every expired entry, and when it is still full, the entry that expires first.MAX_TOKEN_TTL= 600 s (the upstream'sexpires_inless 10 s, capped).cached_tokenignores an expired entry.import:<id>owners do already;the_upstream_token_cache_stays_boundedcovers the cap.So the per-preflight owners add at most one or two entries per preflight (one per scope) to a cache that cannot grow past 4096. A live proxy token could only be evicted early by more than 4096 preflights within ten minutes, and costs that proxy one more token exchange.
Test
a_registry_preflight_checks_its_own_credentials_after_one_that_passed(crates/server/tests/import.rs), against a mock registry that answers/v2/and/v2/_catalogto a bearer token only and whose token service gives the token to the Basic credentials: a preflight with the right credentials (201), then one with a wrong password and one with none against the same registry (both refused), then the right credentials again (201).Without the fix it fails: the wrong-password preflight answers 201.
Checks
cargo test -p forge-server --test import: 26 passed (containers throughmirror.gcr.io)cargo test -p forge-server --lib images::proxy: 2 passedcargo xtask check(fmt + clippy-D warnings): cleancargo xtask changelog --check: cleanNo admin API changes, so no web UI screen. The issue moved from
Backlogto the2.2.0milestone, and the fragment isdocs/changes/2.2.0/775.fixed.md.Generated by Claude Code