Skip to content

fix(identitybroker): read AS-1's named reasons for refused subject tokens - #2625

Merged
ChrisJBurns merged 2 commits into
mainfrom
fix/identitybroker-subject-token-reasons
Oct 30, 2026
Merged

ChrisJBurns merged 2 commits into
mainfrom
fix/identitybroker-subject-token-reasons

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Summary

Aligns the identity broker with the reasons ToolHive's AS-1 token exchange sends for a refused subject token at session open, as agreed on stacklok/toolhive#7003 and recorded in the design catch-up #2616.

  • subject_token_invalid (a fresh access token can pass) → subject_invalid: the server answers the tagged bearer_rejected 401, and the client refreshes and retries once.
  • subject_token_audience, subject_token_source_client (configuration faults) and grant_invalid (unknown or expired grant) → known reasons, classified as configuration faults → INTERNAL.
  • An invalid_request with no reason, or AS-1 sending the broker's own subject_invalid, is no longer read as a subject problem: it is a broker bug or configuration fault → INTERNAL. Matching a named reason is sturdier than reading meaning into a missing one.
  • The offline harness's AS-1 now sends subject_token_invalid for every check 4 refusal, as ToolHive does. It does not tell the two configuration-fault reasons apart (the audience check happens inside JWT parsing, and a token can fail several checks); the broker's own tests cover them.

Issue relationship

Relates to #2492, #2616, stacklok/toolhive#7003

API compatibility

No protobuf or handler change. The only client-observable difference is under the experimental --enable-identity-broker with AS-1 conversion configured (app.Config.IdentityBrokerAS1, set by no deployment until #2607): a reasonless invalid_request from AS-1 at session open now reaches clients as internal instead of bearer_rejected. Additive otherwise; no major or feature change.

Test plan

  • go test -race on internal/identitybroker/..., internal/testutil/identityharness, cmd/mecak8s, the server's identity broker tests, and internal/app identity broker tests
  • Mutation checks: breaking the subject_token_invalid mapping, or mapping a reasonless invalid_request to subject_invalid again, fails the mapping tests
  • task lint: clean except the pre-existing gosec finding in environment/microvm/launch_ownership_darwin.go

…kens

AS-1 refuses a session-open subject token with subject_token_invalid
when a fresh access token can pass, or subject_token_audience /
subject_token_source_client for configuration faults, and an unknown
grant with grant_invalid (agreed on toolhive#7003). The broker maps
subject_token_invalid to subject_invalid; the other three are known
reasons classified as configuration faults; a reasonless
invalid_request is now a broker bug or configuration fault rather than
a subject problem. The offline harness sends subject_token_invalid as
ToolHive does.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns merged commit 9794b3a into main Oct 30, 2026
38 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/identitybroker-subject-token-reasons branch October 30, 2026 15:58
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

2 participants