Skip to content

feat(identitybroker): authorize gateway calls with a per-call ID-JAG and gateway token - #2783

Merged
ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-per-call-grant
Nov 16, 2026
Merged

ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-per-call-grant

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2535

Part 4 of 4. Stack: #2784 → #2785 → #2786 → this PR. Review in that order; each PR builds and passes tests on its own, and the four together equal the reviewed tree.

Wiring and tests against the real servers.

  • internal/app: the identity broker's parts, binding AS-2 after the MCP broker is built and unbinding it before the MCP broker closes (a call in flight finishes first). Test-only Config fields: IdentityBrokerGatewayServers, IdentityBrokerAS2Trust (an opaque value only mcpbrokertest can build), IdentityBrokerAS1.UseCredentialVerifier.
  • internal/identitybroker/authorize_integration_test.go: the harness AS-1 and the real in-process ToolHive AS-2 and vMCP: one token per call, expiry no later than the ID-JAG's, write order, the rejected-token retry at a gateway, revoked rules, lost responses, real AS-2 refusals, the real vMCP accepting the broker's token, token secrecy.
  • cmd/mecak8s: offline end-to-end test through the real startup wiring and served mux: sign-in → session → agent → AuthorizeCall → the real vMCP accepts the token → after delete, session_closed. Its doc lists each stand-in and the ticket that retires it.

Shortcuts

All marked in code with // Shortcut: …; removed by #NNNN and listed in #2535:

Shortcut Removed by
Production configures no gateway entry; AS-2 trusts AS-1 only in tests (test-only Config fields) #2533
The harness AS-1 issues ID-JAGs and checks the agent through a test hook #2654
One gateway; check 6 matches the server, not the tool's route #2538
Checks 4, 5 and 7 accept their inputs #2557, the authority work
Records and retry state in memory; unaccepted refusal records not reported; non-JWT token unreferenced #2541, #2563
AS-2 sends no reason codes, so every invalid_grant takes the retry-once path #2533 after stacklok/toolhive#7030
upstream_revoked / owner_action_required not recorded against the session #2568
Gateway token unbound, lifetime from AS-2; no authorization_details #2538, #2727
AS-2 bound late in process #2560

Design: steps (6)–(8), Error reasons, and the audit write order, as amended by #2779.

Testing

  • Each of the four branches: go build, go vet, focused tests (race for the broker), and golangci-lint.
  • This branch: identity, harness, mcpbroker, and mecak8s tests; -race on the app identity tests; root lint 0 issues. go run ./cmd/mecademo shows tool call, permission ask/approval, and result.
  • Failures in internal/app and internal/adapter/server git-worktree, path-escape, and ACP-placement tests reproduce on main in the author's environment and are unrelated.

API compatibility

No wire change. AuthorizeCall and its types are an in-process Go contract until #2560. Go source callers (Target → Server, new required fields) are all in this repository and updated. No stored data changes.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The wiring matches the design: AS-2 is bound before anything is served, and it is unbound, waiting for calls in flight, before the MCP broker closes. Production configures no gateway, and the test-only fields can't be set outside tests.

Since you're travelling, I pushed two fixup! commits for 09b65a69f2 instead of leaving comments. Both change tests only. git rebase --autosquash folds them in.

758aa25: the vMCP signature test changed the audience too. In TestRealVMCPAcceptsTheBrokersGatewayToken, the forged token was signed with a fresh key, but it also had aud set to AS-2's issuer. vMCP only accepts the resource (issuer + "/mcp"), so the 401 could come from the audience check alone. The test would still pass if vMCP stopped checking signatures. I removed the aud line. The real token's header is {alg: ES256, kid, typ: JWT}, the same as the forged one, so now the only difference is the signature, and the test still gets 401.

4cec7cd: the leak scans never looked for the client assertions themselves. TestIdentityBrokerTokensStayOutOfSessionsAndLogs and TestAuthorizeCallKeepsTokensSecretAtAS2 wrote each captured client_assertion into the text being scanned. That checked that an assertion doesn't contain a token, but a change that logged a raw client assertion would have passed. Both tests now:

  • collect the assertions on their own and fail if none were captured;
  • scan the real outputs (transcript, events, diagnostics, errors, records, environment) for tokens and for assertions;
  • keep the old check as a separate step: an assertion's decoded header and payload carry no token;
  • have a positive control that plants an assertion and requires the scan to find it.

Each test fails if an assertion is added to the scanned output. A small cleanup: jwtClaims in the app test now reuses the new jwtSegmentText.

Fixes for the lower commits of the stack (the gateway token's exp ignored when it has no jti, attempt-mismatch tests that only changed Tool, and the ExpiresAt comment) are in a separate PR against split/2535-3-per-call-flow.

Non-blocking, for later:

  • Shutdown can wait a while. Unbinding waits for calls in flight. A stuck call can make up to 3 tries of an AS-1 request and an AS-2 request, with a 10s timeout each, so about 60s. A call refused during shutdown also says "not bound yet".
  • The test hook hands out the whole broker. UseCredentialVerifier(core) passes the concrete *Broker, so a type assertion recovers the full broker. That's fine while only tests use it and #2654 removes it.
  • ToolHive v0.65.0's AS-2 only logs a resource mismatch. When the requested resource differs from the ID-JAG's resource claim, it logs resource_not_covered but doesn't refuse. Design step (8) check 6 wants a refusal. This PR isn't affected, because the broker sends the same value both times. It probably belongs with the reason-code work in stacklok/toolhive#7030.

@ChrisJBurns
ChrisJBurns force-pushed the split/2535-3-per-call-flow branch from 0a48c57 to be15152 Compare November 16, 2026 11:12
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from 4cec7cd to c135ad2 Compare November 16, 2026 11:12
@ChrisJBurns
ChrisJBurns force-pushed the split/2535-3-per-call-flow branch from be15152 to 352a4d3 Compare November 16, 2026 12:00
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from c135ad2 to 04257a1 Compare November 16, 2026 12:01
Base automatically changed from split/2535-3-per-call-flow to main November 16, 2026 12:26
ChrisJBurns and others added 3 commits November 16, 2026 12:27
…ow against the real servers

Build gives the real identity broker a recorder, an ID-JAG issuer, and,
in tests only, a gateway whose AS-2 it binds once the MCP broker starts
and unbinds before the MCP broker closes. Integration tests run per-call
authorization against the real embedded AS-2 and vMCP, in process and
through mecak8s's served startup.

Co-authored-by: Mecatl <noreply@mecatl.dev>
… the flow against the real servers

Co-Authored-By: mecatl <noreply@mecatl.dev>
… the flow against the real servers

Co-Authored-By: mecatl <noreply@mecatl.dev>
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from 04257a1 to b630101 Compare November 16, 2026 12:28
@ChrisJBurns
ChrisJBurns merged commit 9c3bba7 into main Nov 16, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-per-call-grant branch November 16, 2026 13:00
@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.

Per-call grant and gateway token

3 participants