Repository navigation
feat(identitybroker): authorize gateway calls with a per-call ID-JAG and gateway token - #2783
Conversation
273cc03 to
09b65a6
Compare
jhrozek
left a comment
There was a problem hiding this comment.
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
resourcediffers from the ID-JAG'sresourceclaim, it logsresource_not_coveredbut 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.
0a48c57 to
be15152
Compare
4cec7cd to
c135ad2
Compare
be15152 to
352a4d3
Compare
c135ad2 to
04257a1
Compare
…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>
04257a1 to
b630101
Compare
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-onlyConfigfields:IdentityBrokerGatewayServers,IdentityBrokerAS2Trust(an opaque value onlymcpbrokertestcan 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 #NNNNand listed in #2535:Configfields)invalid_granttakes the retry-once pathupstream_revoked/owner_action_requirednot recorded against the sessionauthorization_detailsDesign: steps (6)–(8), Error reasons, and the audit write order, as amended by #2779.
Testing
go build,go vet, focused tests (race for the broker), and golangci-lint.-raceon the app identity tests; root lint 0 issues.go run ./cmd/mecademoshows tool call, permission ask/approval, and result.internal/appandinternal/adapter/servergit-worktree, path-escape, and ACP-placement tests reproduce onmainin the author's environment and are unrelated.API compatibility
No wire change.
AuthorizeCalland 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.