Skip to content

perf(datasource): cut cold Docker Hub and GHCR round trips - #411

Merged
sweepies merged 3 commits into
mainfrom
perf/cold-docker-lookups
Nov 24, 2026
Merged

sweepies merged 3 commits into
mainfrom
perf/cold-docker-lookups

Conversation

@sweepies

@sweepies sweepies commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Part 4 of the performance series: fewer round trips for cold Docker/OCI lookups.

Changes

  1. Docker Hub tags/list?n=50000 (docker.rs tags_url). Only registry-1.docker.io starts with n=50000; every other host keeps n=1000 (GHCR defaults to 100, ECR Public returns 405 on n=10000, Quay caps at 100). Link: rel="next" is still followed. Measured live: grafana/loki goes from 29 pages (~26 s) to 1 request (~2 s).
  2. Anonymous pull token fetched before the first read on registry-1.docker.io (auth.docker.io/token) and ghcr.io (ghcr.io/token), so a cold image no longer costs a 401 round trip.
    • The 401 path and this new path call one shared mint helper: realm_trust, credential selection, token parsing, issued_at/Age/expires_in expiry, and SQLite persistence (anonymous tokens only).
    • The token is minted under the per-scope token.lock(), so concurrent reads of one image share a single token.
    • It only applies to anonymous reads. Reads under an operator entry keep the 401 exchange: a bearer entry sends its own secret, and a basic entry already sends credentials on the first request.
    • It only applies when the read would actually reach the registry. A new Cached::registry_fresh checks the cache first, using the same prepare/fresh logic get_representation now uses, so a warm digest read never mints a token.
    • Registry reads are never mirrored, so the read and the token service are always the registry's own. The code also checks that the URL host is the registry host.
    • If minting fails, the read fails, matching what happens after a 401. If the registry rejects the new token with a 401, the existing challenge flow takes over.
  3. Cosign .att/.sbom HEADs sent in parallel (join_all). Results are still processed in the old order (child .att, index .att, child .sbom, index .sbom): the first SBOM found wins, and an error ahead of it fails the read, as before.
  4. Current pinned-image SBOMs read alongside lookup and digest (engine/src/lookup.rs). The key set (current_sbom_reads) comes from the same needs.sboms, digest and imagePlatforms rules once plan_lookups has run, and is always a subset of what read_images would read. The image phase then reads only the new digests and fallback platforms. A key read without revalidation is read again if a retried dependency wants it fresh.

Tests and fixtures

  • New tests:
    • only_docker_hub_asks_for_every_tag_in_one_page (unit).
    • cold_docker_hub_and_ghcr_reads_mint_one_token_before_the_first_read: one token for two concurrent reads; a Docker Hub mirrorOf entry changes nothing.
    • a_read_the_cache_answers_mints_no_token.
    • a_failed_token_before_the_first_read_fails_the_read.
    • cosign_tags_are_asked_about_at_once_and_taken_in_order: precedence, error ordering, and at least 4 HEADs in flight at once.
  • Cassettes: removed the 401s that are no longer sent for Docker Hub and GHCR, and changed five Docker Hub n=1000 URLs to n=50000. Replay ignores order, so nothing else had to change.
  • Recorded Docker Hub token bodies carry an old issued_at, which made every replayed token already expired, so each read minted again. The recorder (testkit::undate_token) now drops issued_at from token answers, and the existing cassettes had it removed the same way.
  • Simulated tests that used GHCR as a stand-in for any registry (registry protocol, engine advisories) now use registry.example. Token-flow tests stay on GHCR and Docker Hub and include the new token request.
  • Version bumps, because the parity checks hash whole files: oci-config-notes, oci-tags, anonymous-registry-pull-token 2→3; image-platform, sbom-os 5→6; state osv-advisory 7→8, catalog, catalog-controls 28→29, changelog 15→16. This invalidates those cache entries once after upgrade.

Verification (boat VM)

  • cargo test --workspace --locked --no-fail-fast -- --skip lockfiles::tests::real_: all green. The last change after that run was test-only; registry_protocol was re-run, 37 passed.
  • mise run fixtures:check: 57 cassettes, no possible secrets.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo fmt --all --check: clean.
  • Transcript and depth snapshots are unchanged.

Docs updated: internals/cache.md (registry pull tokens), internals/image-sboms.md, guide/sources.md.

Follow-ups

  • Fetching the token early for basic-auth Docker Hub entries could save the same round trip for authenticated pulls. It was left out because no recording covers that exchange.

View guided diff Turn on auto-fix

@sweepies
sweepies marked this pull request as draft November 24, 2026 08:45
@sweepies
sweepies marked this pull request as ready for review November 24, 2026 09:08
- Docker Hub tags/list starts at n=50000, so even 28k-tag repositories
  list in one request; every other registry keeps n=1000 and Link paging.
- Anonymous reads on registry-1.docker.io and ghcr.io mint their pull
  token from the known token service before the first read, under the
  scope's lock, instead of after a 401. A read the cache answers mints
  nothing; a failed mint fails the read; a rejected token still falls
  back to the challenge. The 401 path and the preemptive one share one
  mint helper (realm trust, credentials, expiry, persistence).
- The four cosign .att/.sbom HEADs are sent at once and taken in the
  sequential order, with the same error precedence.
- Current pinned-image SBOM reads overlap the lookup and digest stages;
  the image stage reads only the new digests and fallback platforms.
- The recorder drops a token answer's issued_at so replays do not see
  every recorded token as expired; cassettes lose their now-unsent 401s.
- Derived and state versions bumped for the touched sources.
@sweepies
sweepies force-pushed the perf/cold-docker-lookups branch from 1d939a1 to fbc53d2 Compare November 24, 2026 19:11
@sweepies
sweepies merged commit 4665813 into main Nov 24, 2026
14 checks passed
@sweepies
sweepies deleted the perf/cold-docker-lookups branch November 24, 2026 19:18
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 24, 2026

This branch was successfully deployed

1 active deployment
docs-preview — fbc53d26 Deployed Nov 24, 2026 by sweepies via Docs: preview #49
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