Repository navigation
Description
Depends on: #2534 and #2738 (PR #2744: the embedded AS-2 and its startup values). For the real servers: #2533, #2654, stacklok/toolhive#6898, and stacklok/toolhive#6887. Built and tested against the offline harness's AS-1 and ToolHive's authorization server (the version Mecatl pins) as AS-2.
Problem
The gateway needs a token for each call that names both the user and the acting agent. Today it receives the MCP broker's per-session OAuth token, which names no agent, and the identity broker cannot authorize anything (Broker.AuthorizeCall in internal/identitybroker/sessions.go denies every call).
Design
- credentials-and-lifecycle.md: (6) Per-operation authorization: checks, and the request's method, server, and tool
- credentials-and-lifecycle.md: (7) ID-JAG from AS-1
- credentials-and-lifecycle.md: (8) AS-2 access token: one
Vper call, and the rejected-token retry - credentials-and-lifecycle.md: Lifetimes and renewal
- credentials-and-lifecycle.md: Failure matrix and Error reasons
- audit.md: AuditEvent profile: evidence references, including the gateway token's
jti - audit.md: Delivery, protection, and reconciliation: write order and failure
Until PR #2779 merges, the request's method, server, and tool, the rejected-token retry, the revoked rule with no recorded reason, the gateway token's jti, and the record order are in that PR rather than on main.
Shortcuts
| Shortcut | Removed by |
|---|---|
| Production configures no gateway entry for the identity broker, so authorized gateway calls work only in tests | #2533, once AS-2 trusts AS-1 |
| The rejected-token retry state and the call records are kept in memory | #2563 |
AS-2 refusals carry no reason code, so every invalid_grant is retried once with a new ID-JAG |
#2533, after stacklok/toolhive#7030 |
AS-1's upstream_revoked and owner_action_required fail the call but are not recorded against the session, and the session stays open |
#2568 |
| The gateway token is not bound to its call, and its lifetime is AS-2's server-wide access-token lifetime capped at the ID-JAG's | #2538 (lifetime), #2727 (binding) |
No authorization_details on redemption |
#2727 |
The AS-2 port is bound in process after startup, so a call to the configured gateway before it is bound or while it is being unbound fails as UNAVAILABLE |
#2560 (AS-2 over the network) |
| Step (6) checks 4 and 5 (run and owner) and 7 (ceiling) accept their inputs without checking them | #2557, the authority work |
| A gateway token that is not a JWT has no reference in the decision record | #2541 (references AS-2's redemption event) |
| The broker holds one gateway, the embedded one, with one AS-2 binding | #2538 (operator-declared gateway entries, each with its own AS-2) |
The embedded AS-2 trusts the harness's AS-1 only through a test seam (ToolHiveConfig.AS2Trust, set by mcpbrokertest) |
#2533 |
Requirements
"Authorize an MCP call" in the real identity broker, as steps (6) to (8) specify:
- Checks before any grant: the phase 1 subset of step (6): checks 1 to 3 and 6 (check 6 as "a configured gateway routes the server"; tools on protected routes are found at run time). Checks 4, 5 and 7 accept their inputs without checking them (Runs, delegations, and the run owner #2557, the authority work).
- Grant: step (7). Extend the offline harness's AS-1 with the ID-JAG exchange, calling Mecatl's actor-token validator #2534's owner-keyed validator, so AS-1's check 8 runs offline.
- Gateway token: step (8), with the rejected-token retry.
- The
AuthorizeCallshape, fixed now because Identity broker RPC contract and transport #2560 turns it into the gRPC contract: every field step (6) names, and in the response the gateway token, its expiry, and the attempt ID. Reporting dispatch and outcome is a separate call (mecak8s reports gateway call dispatch and outcome to the identity broker #2731). - Which grant a call uses, in one function: today the session's refresh token; scheduled runs (Phase 2, Slice 3: Scheduled runs — A scheduled run calls gateway tools on its own grant, with no one present #2569) and the later chained exchange change only that function.
- Recorder port: a narrow port in
internal/identitybrokerfor call decisions and ID-JAG records, in the write order the audit chapter specifies. Tests use an in-memory recorder. Broker records of who acted #2541 widens it into the full record sink. - Gateway entry: a broker-side gateway entry type in
internal/identitybroker(AS-2 issuer and token endpoint, vMCP resource, routed servers, HTTP client). Keys and gateway entries for the identity broker #2538 exposes it to operators and Helm. - Argument hash: validated for form only (64 lowercase hex characters); who computes it is MCP broker authorizes gateway calls and sends them to the configured gateway #2536's.
- AS-2 in tests: ToolHive's real authorization server in process, with Wire the embedded gateway's authorization server into startup as AS-2 #2738's embedded AS-2 configuration and an exported test seam for its trust of the harness's AS-1, kept out of production code by depguard.
- Grant-path fault injection for the ID-JAG exchange and the AS-2 client, so the failure cases below run.
- Gateway stand-in in
internal/testutil/identityharness, for MCP broker authorizes gateway calls and sends them to the configured gateway #2536 and Connect provider accounts at the embedded gateway #2537: accepts or rejects gateway tokens, can reject one once, and can report a missing provider connection. - Secrecy: the ID-JAG and the gateway token stay out of everything
implementation.md"Credential verification" lists, including the recorder's records and client assertions.
How it fits
Steps (6) to (8) of the flow: the gateway receives a token naming the user and the agent, and the user's provider credential never leaves the gateway.
Done when
Against the offline harness's AS-1 and the real ToolHive AS-2:
- every call obtains its own gateway token from a new ID-JAG, nothing is cached, and each call makes exactly one exchange and one redemption (two of each with the rejected-token retry);
- the gateway token's expiry is no later than the ID-JAG's
exp; - decisions and ID-JAG records are written in the audit chapter's order, with its failure behaviour;
- the rejected-token retry, the
revokedandparent_revokedrules, a lost redemption response, and a session closed during an exchange behave as step (8) and "Error reasons" specify; - AS-2 refuses a reused ID-JAG, and the gateway token carries
actandclient_idmecatl; - a list request needs no tool or argument hash, and a
tools/calldoes; - every failure in the failure matrix that this ticket can reach maps as specified;
- a leak test shows the ID-JAG and gateway token appear in no model or tool content, transcript, log, environment variable, error, diagnostic, recorder record, or client assertion;
- tokens are never shared across users or sessions, and none is issued after the session closes;
- the authorization contract tests (
internal/identitybroker/conformance) gain cases for the new request fields,no_grant, and the retry flag's refusals, and the real implementation passes them.
Activity
3 remaining items
ChrisJBurns commentedon Nov 6, 2026
Decide when starting this ticket: what
serverandtoolmeanThis ticket fixes the
AuthorizeCallrequest shape. #2560 turns it into gRPC, #2541 records the same names, and #2727 and stacklok/toolhive#7061/#7062 bind and check them. Settle this before writing the request.tool: step (8) says it is "the name the vMCP routes by, as sent inparams.name". The embedded vMCP prefixes tools with{workload}.(toolHiveAggregationConfigininternal/adapter/mcpbroker/toolhive_process.go), so the routed name isgithub.pull_request_read. The step (8) examples, andaudit.md, use the unprefixedpull_request_read.server: not defined anywhere. Candidates: the vMCP backend workload the route resolves to, the MCP server name registered in Mecatl, or the gateway entry.Target("the gateway or backend"), notserver(internal/identitybroker/service.go).tools/listrequest needs its own rule for what it names.Suggested:
serveris the vMCP backend workload, andtoolis exactlyparams.nameas sent. Then fix the step (8) examples andaudit.md.Who decides: Chris, with jhrozek and the owner of stacklok/toolhive#7061.
ChrisJBurns commentedon Nov 13, 2026
Answered on 2026-11-13:
toolis the routed name exactly as sent inparams.name(e.g.github.pull_request_read),serveris the gateway's backend name, and aMethodfield distinguishes calls from listings. Recorded in the design, step (6), by docs PR #2779.chore(identitybroker): tidy the per-call test support
fix(identitybroker): respect a gateway token's exp when it has no jti
test(identitybroker): cover every field that binds a rejected attempt
test(identitybroker): cover every attempt-ledger key field and descri…
fix(identitybroker): respect a gateway token's exp when it has no jti
test(identitybroker): cover every field that binds a rejected attempt
test(identitybroker): cover every attempt-ledger key field and descri…