Skip to content

Imports: a registry preflight authenticates as an owner of its own - #920

Open
schmitch wants to merge 1 commit into
mainfrom
claude/775-preflight-token-owner
Open

schmitch wants to merge 1 commit into
mainfrom
claude/775-preflight-token-owner

Conversation

@schmitch

Copy link
Copy Markdown
Member

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 as import: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 through Upstream::send, which the proxies and the import worker share.
  • crates/server/src/images/import.rs: the owner field's comment says why an owner is never shared.

The cache stays bounded

What I found in cache_token (images/proxy.rs):

  • The cache holds at most 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.
  • An entry lives at most MAX_TOKEN_TTL = 600 s (the upstream's expires_in less 10 s, capped). cached_token ignores an expired entry.
  • Expired entries are not swept on a timer: they stay until the cache is full. A one-shot preflight entry therefore lingers past its expiry, but within the 4096 cap. This is what the worker's import:<id> owners do already; the_upstream_token_cache_stays_bounded covers 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/_catalog to 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 through mirror.gcr.io)
  • cargo test -p forge-server --lib images::proxy: 2 passed
  • cargo xtask check (fmt + clippy -D warnings): clean
  • cargo xtask changelog --check: clean

No admin API changes, so no web UI screen. The issue moved from Backlog to the 2.2.0 milestone, and the fragment is docs/changes/2.2.0/775.fixed.md.


Generated by Claude Code

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

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.

Imports: a registry preflight passes with wrong credentials on a token an earlier preflight got

2 participants