Skip to content

Service accounts: "Last used" counts only the requests that run as the account - #914

Merged
schmitch merged 1 commit into
mainfrom
claude/586-service-account-last-used
Nov 17, 2026
Merged

schmitch merged 1 commit into
mainfrom
claude/586-service-account-last-used

Conversation

@schmitch

Copy link
Copy Markdown
Member

Fixes #586

The bug

The trusted-header realm recorded a use of the account its headers name (touch_last_authenticated) in TrustedHeaderSource::signed_in, when the principal middleware resolved the principal. Two handlers read a credential of the request's own after that and run the request as someone else:

So behind a proxy that names a network's service account, every npm or docker request with its own token moved that account's "Last used".

The fix

  • TrustedHeaderSource no longer writes when it resolves the principal. The write is TrustedHeaders::record_use, a small trait over PrincipalSource that the middleware's trusted_header source now implements.
  • The middleware puts a NamedAccountUse extension on a request whose principal the headers named, and records the use after the handler has answered, unless the handler marked the principal as replaced.
  • /repository and /v2 mark it when the principal they run the request as is not the one the headers named, or when the request's own token is refused (the request then runs as nobody). A registry token that names nobody (the one the headers alone get from /v2/token) leaves the request running as the header account, and that is still recorded.

I looked for other places a later credential replaces the trusted-header principal and found none: every other handler takes the middleware's principal as it is, and the token-exchange and device-grant endpoints skip the credential chain altogether.

Tests

  • crates/server/tests/trusted_header.rs, a_request_with_its_own_credential_is_no_use_of_the_account_the_headers_name: through a real trusted-header realm, a feed request with a Bearer token, one with a refused token, docker login, a registry token and a refused registry token leave last_auth_source_at of the header account unset; the headers alone (feed, /v2/, /v2/token, and beside the anonymous registry token) set it. Before the fix it failed at the first assertion ("a feed's Bearer token").
  • middleware::principal::tests::a_use_of_the_named_account_is_recorded_unless_the_handler_replaced_it: the middleware's side with a stub source.

Ran locally: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo xtask changelog --check, cargo xtask doc-check, cargo xtask unused, cargo xtask docs --check, and cargo test -p forge-server --lib --test trusted_header --test service_accounts --test registry --test alias_base_urls (all green).

Neighbouring issues, not fixed here

Web UI

No admin API change: Admin → Service accounts shows the same last_used_at, now with the right value.


Generated by Claude Code

…e account

The trusted-header realm recorded a use of the account its headers name
when the middleware resolved the principal, before the handler read a
credential of the request's own in its place: a Bearer API token on
/repository, a registry token on /v2. The middleware now records the use
after the handler has answered, unless the handler says another credential
replaced the principal (or was refused).

Fixes #586

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012e6DJacez28ygnEtA1z3mF
@schmitch
schmitch added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit d84204c Nov 17, 2026
19 checks passed
@schmitch
schmitch deleted the claude/586-service-account-last-used branch November 17, 2026 17:03
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.

Service accounts: "Last used" counts requests another credential authenticated behind a trusted-header realm

2 participants