Skip to content

fix(identitybroker): review fixups for the per-call authorization stack - #2792

Closed
jhrozek wants to merge 6 commits into
mainfrom
review/2535-stack-fixups
Closed

jhrozek wants to merge 6 commits into
mainfrom
review/2535-stack-fixups

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Review fixes for the lower commits of the per-call authorization stack (#2784 → #2785 → #2786 → #2783), found while reviewing #2783. Each commit is a fixup! for the stack commit that introduced the lines it changes, so git rebase --autosquash folds it into the right place.

Commit Folds into Change
f437b4e4fe 0a48c57833 (#2786) Respect a gateway token's exp when it has no jti
385ef77c2a 0a48c57833 (#2786) Attempt-mismatch test covers every field that binds an attempt
b41ccf2423 e903f3e09e (#2785) Same for the ledger test; ExpiresAt comment

The gateway token's exp was ignored without a jti

gatewayTokenExpiry limits Authorization.ExpiresAt by the gateway token's own exp. It read that exp through readJWTRef, which returns false as soon as jti is missing, before it reads exp. Take a gateway JWT with exp one minute away, no jti and no expires_in, redeemed from an ID-JAG that expires in two minutes. ExpiresAt came out at two minutes, so a caller could send a token the gateway already considers expired, and use up its one rejection retry on it.

The new readJWTExp reads exp without needing a jti. readJWTRef and readIDJAG still require a jti where a record reference is made. TestAuthorizeCallGatewayTokenExpiryWithoutJTI failed before the fix (09:02, want 09:01) and passes after. ToolHive's AS-2 sends both a jti and expires_in today, so this matters only for another AS-2.

Attempt-mismatch tests only changed the tool

TestAuthorizeCallRejectedTokenRetry and TestMemoryAttemptsMatchTheCall checked that a rejection report for a different call is refused, but the only field they changed was Tool. If the operation ID, method, server, argument hash or agent were dropped from the attempt key, the tests would still pass, and an attempt could be reused for a different call. Both tests now run once per callKey field:

  • For each field, a report that differs only in that field is denied, and the attempt is then used up.
  • AuthorizeCall makes no further AS-1 or AS-2 exchange.
  • The agent case uses a second valid agent registered in the same session.

method can't be changed on its own through AuthorizeCall: a tools/list request must not carry a tool or argument hash. So the method case there changes all three, and the ledger test covers method on its own.

ExpiresAt comment

The comment said ExpiresAt is when the gateway token expires. It's the broker's use-before deadline: the earliest of the ID-JAG's exp, AS-2's expires_in and the token's own exp. The authorization server may keep the token valid longer. Comment only.

Testing

Focused runs on internal/identitybroker: the touched tests pass, and go vet, gofmt and golangci-lint report nothing. I didn't run the full suite. An independent check traced the old code path and confirmed that each new test case depends on the field it changes.

Landing

This branch is cut from split/2535-3-per-call-flow. The b41ccf2423 fixup targets #2785's commit, so if #2785 is merged on its own, that commit needs to go to split/2535-2-contract too. After squashing, rebase #2783 onto the result.

API compatibility

No wire change. AuthorizeCall is an in-process Go contract. This changes the computed ExpiresAt value only for gateway JWTs without a jti.

🤖 Generated with Claude Code

ChrisJBurns and others added 6 commits November 13, 2026 19:19
…way stand-in, and AS-2 trust test seam

The identity harness's AS-1 issues per-call ID-JAGs, checking actor tokens
through a test-supplied ActorValidator; FaultTransport fails, drops, or
intercepts requests to any authorization server; and a minimal gateway
stand-in needs a bearer token. ToolHiveConfig.AS2Trust, built only through
mcpbrokertest, lets tests make the real AS-2 trust the harness's AS-1.

Co-authored-by: Mecatl <noreply@mecatl.dev>
…before a grant

AuthorizeCallRequest carries the run, method, server, tool, arguments hash,
and rejected attempt; Authorization adds the expiry and attempt ID. The
broker checks the session, a rejection report, the grant (no_grant), the
credential, and the gateway's servers in design order, recording each
refusal; a call passing every check is still denied until steps (7) and (8).

Co-authored-by: Mecatl <noreply@mecatl.dev>
…and gateway token

A call that passes the checks exchanges the session's refresh token at AS-1
for an ID-JAG (IDJAGIssuer), records it, and redeems it at the gateway's
AS-2 (GatewayAuthServer) for a token used by that call alone, retrying once
per design rule. AS-2 is bound late with BindGatewayAS2; authserverclient
implements both ports.

Co-authored-by: Mecatl <noreply@mecatl.dev>
…ID-JAG and gateway token

Co-Authored-By: mecatl <noreply@mecatl.dev>
…ID-JAG and gateway token

Co-Authored-By: mecatl <noreply@mecatl.dev>
…checks before a grant

Co-Authored-By: mecatl <noreply@mecatl.dev>
@ChrisJBurns
ChrisJBurns force-pushed the split/2535-3-per-call-flow branch 2 times, most recently from be15152 to 352a4d3 Compare November 16, 2026 12:00
Base automatically changed from split/2535-3-per-call-flow to main November 16, 2026 12:26
ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
gatewayTokenExpiry read the gateway token's exp through readJWTRef,
which gives up when the token has no jti, so ExpiresAt could outlast the
token. readJWTExp reads exp on its own.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit f437b4e)
Co-authored-by: Mecatl <noreply@mecatl.dev>
ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
The rejected-token retry test changed only the tool; it now checks a
report that differs in each field of the attempt key, including a second
agent in the same session.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit 385ef77)
Co-authored-by: Mecatl <noreply@mecatl.dev>
ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
…be ExpiresAt

The ledger test now checks each call-key field on its own, and the
ExpiresAt comment says it is the broker's use-before deadline, not the
token's own expiry.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit b41ccf2)
Co-authored-by: Mecatl <noreply@mecatl.dev>
@ChrisJBurns

Copy link
Copy Markdown
Contributor

Thanks @jhrozek. #2785 and #2786 merged before these could be autosquashed, so all three commits are now in #2794 with you as their author and (cherry picked from …) in each message:

  • f437b4e → 36dc401 fix(identitybroker): respect a gateway token's exp when it has no jti
  • 385ef77 → bf34f9c test(identitybroker): cover every field that binds a rejected attempt
  • b41ccf2 → 3ceed66 test(identitybroker): cover every attempt-ledger key field and describe ExpiresAt

Each original patch is present in #2794's branch, and its tests pass. Closing this in favour of #2794.

ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
gatewayTokenExpiry read the gateway token's exp through readJWTRef,
which gives up when the token has no jti, so ExpiresAt could outlast the
token. readJWTExp reads exp on its own.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit f437b4e)
Co-authored-by: Mecatl <noreply@mecatl.dev>
ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
The rejected-token retry test changed only the tool; it now checks a
report that differs in each field of the attempt key, including a second
agent in the same session.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit 385ef77)
Co-authored-by: Mecatl <noreply@mecatl.dev>
ChrisJBurns pushed a commit that referenced this pull request Nov 16, 2026
…be ExpiresAt

The ledger test now checks each call-key field on its own, and the
ExpiresAt comment says it is the broker's use-before deadline, not the
token's own expiry.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit b41ccf2)
Co-authored-by: Mecatl <noreply@mecatl.dev>
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