Skip to content

feat(mcpbroker): trust AS-1 for ID-JAGs only at AS-2 - #3002

Merged
ChrisJBurns merged 5 commits into
mainfrom
chris/2533-as2-idjag-only
Nov 27, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
chris/2533-as2-idjag-only

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2533. This covers what the pinned ToolHive release (v0.69.0) allows before stacklok/toolhive#7247 turns on subject resolution. The rest of #2533 waits on that release.

Changes

  • AS-2 trusts AS-1 for ID-JAGs only. acceptedAssertionTypes: [id_jag] (Gate ID-JAG by issuer assertion types toolhive#6678). Until now, AS-2 redeemed plain RFC 7523 assertions from AS-1 with no client authentication. It now refuses them, with or without client authentication.
  • AS-2's access tokens are typed at+jwt (RFC 9068), as step (8) requires. ToolHive's default is typ: JWT; Mecatl now opts in with runner.WithAccessTokenType, only when AS-2 is set up.
  • Fetching AS-1's keys from a private address is now opt-in. as2trust.Trust.AllowPrivateAddresses replaces the hardcoded AllowPrivateIPs: true. Every test that uses a loopback AS-1 now sets it explicitly, and a new test checks that the same trust is refused when AS-2 is built without it.
  • New tests for AS-2's step (8) checks, from Configure the embedded gateway's authorization server as AS-2 #2533's "Done when" and implementation.md ("Credential verification"):
    • refusals carry the reason the broker reads (invalid_assertion, subject_unknown), and each refusal's hint is checked, since many share invalid_assertion;
    • AS-2 refuses an ID-JAG that is expired, has a lifetime over the maximum, names another client, comes from an untrusted issuer, or has a bad signature. AS-2 limits an ID-JAG's lifetime (exp - iat), not its age;
    • of concurrent redemptions of one ID-JAG, exactly one gets a gateway token, and every other one is refused as a replay;
    • a replay-store outage returns server_error, and a gateway token issued before the outage still works at the vMCP;
    • the vMCP returns 401 invalid_token for a gateway token with another issuer, another audience, a bad signature, an ID-JAG typ, or an expired one.
  • Two shortcuts are pinned by tests and marked in code:
  • AS-1 now has a test that it refuses its token endpoint as a client assertion's audience, which replaces a stale comment saying it accepted it.

Not in this PR (waits on stacklok/toolhive#7247 or later)

  • Production trust in AS-1 and subject mode resolve.
  • The company IdP as AS-2's first upstream, and the subject claim.
  • The operator guide's caveats for real company IdPs (consent screen, account picker, conditional access).
  • The delegated-access marker on the gateway token, and the marked-token self-exchange refusal.
  • The actor_denied and resource_denied refusals: AS-2 produces them only in subject mode resolve.
  • Retiring the test-only trust seam, and redeeming through the startup wiring rather than a test hook.
  • Allowing servers in the production gateway entry.
  • The Helm and operator-guide setting for the key fetch. It would do nothing while production trusts no issuer; see the note on Configure the embedded gateway's authorization server as AS-2 #2533.
  • NonFatalSecondaryLegs (Make secondary chain legs optionally non-fatal toolhive#7311, unreleased).

API compatibility

No wire change. Production AS-2 still trusts no ID-JAG issuer. The at+jwt type changes only tokens that AS-2 issues and mecak8s's own vMCP consumes in process; no client sees them.

Testing

  • go test passes for ./internal/adapter/mcpbroker/..., ./internal/identitybroker/..., ./internal/app, and ./cmd/mecak8s. The AS-2 tests also pass with -race.
  • Mutation checks:
    • without AcceptedAssertionTypes, the four plain-JWT cases fail;
    • with AllowPrivateIPs forced to true, the private-address test fails;
    • without the at+jwt option, the gateway-token typ assertion fails.
  • golangci-lint reports no issues on the touched packages, and task docs:check passes. task docs stops at the gRPC reference step because buf isn't installed locally; this PR changes no contracts.

ChrisJBurns and others added 3 commits November 26, 2026 16:49
AS-2 trusted AS-1 for both assertion types, so it redeemed plain
RFC 7523 assertions from AS-1 without client authentication. It now
accepts ID-JAGs only. Key fetches from a private or loopback address
are an explicit trust setting instead of always on.

Tests cover the step (8) refusals and reason codes, concurrent
single use, a replay-store outage, and the vMCP's rejection of bad
gateway tokens, and pin two shortcuts: self-exchange of a gateway
token, and the vMCP accepting typ JWT or none.

Part of #2533.

Co-authored-by: Mecatl <[email protected]>
…AS-1's audience

Point the vMCP typ shortcut at stacklok/toolhive#7345. Replace the
stale note that AS-1 accepts its token endpoint as a client
assertion's audience with a test that it refuses it.

Part of #2533.

Co-authored-by: Mecatl <[email protected]>
AS-2 issued gateway tokens with ToolHive's default typ JWT, not the
at+jwt that step (8) requires. Mecatl now opts in when AS-2 is set
up, so nothing changes with the identity broker off.

The replay-store outage test now also shows that a gateway token
issued before the outage still works at the vMCP. The vMCP's missing
typ check is recorded in the design's ToolHive work list
(stacklok/toolhive#7345).

Part of #2533.

Co-authored-by: Mecatl <[email protected]>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Checked against #2533 and the step (8) design, and ran it locally.

Design fit. This matches the parts of #2533 that v0.69.0 allows: ID-JAG-only trust (acceptedAssertionTypes: [id_jag]), the private-address key fetch moved out of the hardcoded value into the trust, at+jwt gateway tokens, and the "Done when" refusal list. The deferred items line up with what waits on toolhive#7247. The new ToolHive work-list row for the vMCP typ check (toolhive#7345) fills a real gap in the ledger.

Existing users. Nothing changes with the identity broker off, because as2 needs BrokerClient. With it on, WithAccessTokenType also retypes the broker's per-session OAuth login tokens, not just gateway tokens. I checked the consumers. Only the in-process vMCP reads them, and its validator refuses only an ID-JAG typ. The identity broker only reads typ on ID-JAGs. ToolHive's token exchange accepts at+jwt subject tokens, and the pinned self-exchange test shows it. Production AS-2 still trusts no issuer, so AllowPrivateAddresses defaulting to false has no production effect today.

Ran locally:

  • go test -race passes on ./internal/adapter/mcpbroker/... and ./internal/identitybroker/....
  • go test passes on ./internal/app (full package) and ./cmd/mecak8s.
  • Mutation check: dropping AcceptedAssertionTypes fails exactly the four plain-JWT cases in TestAS2RefusesRedemptionsOutsideItsConfiguration.

One sequencing note, non-blocking. The self-exchange shortcut lets the broker client turn a gateway token into a fresh one with a new jti, up to the original's expiry. That's harmless now. Once #2727 and toolhive#7062 make a gateway token single-use per call, it could get around the single-use rule unless the marker refusal (toolhive#7247 / #6404) lands first. Worth stating that ordering on #2727, or checking that the exchanged token can't carry the call's authorization_details.

@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 ID-JAG-only trust, the at+jwt type, and making the private-address key fetch opt-in all do what the description says; I checked them against ToolHive v0.69.0, and production can't turn the private-address fetch on.

Four things to fix, inline: the #7345 shortcut needs a Mecatl-side step to go away, one test checks lifetime rather than age, there's no bad-signature redemption case, and the refusal tests check the reason code but not the cause.

Comment thread internal/adapter/mcpbroker/as2_test.go Resolved
Comment thread internal/adapter/mcpbroker/as2_test.go Resolved
Comment thread internal/adapter/mcpbroker/as2_test.go Resolved
Address review of #3002:
- AS-2 limits an ID-JAG's lifetime, not its age, so test a lifetime
  over the maximum instead of an old iat.
- Add an ID-JAG with AS-1's issuer and key ID signed by another key.
- Check ToolHive's hint for each refusal, since many share the
  invalid_assertion reason, and require a gateway token on the one
  concurrent success and none on each refusal.
- The vMCP typ shortcut ends only when Mecatl pins
  stacklok/toolhive#7345 and turns its check on for AS-2.

Part of #2533.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns

Copy link
Copy Markdown
Contributor Author

@rdimitrov on the sequencing note: the ordering is already safe on the ToolHive side. v0.69.0 refuses an RFC 8693 exchange whose subject token carries authorization_details (stacklok/toolhive#7282; hint "The subject token carries authorization_details and cannot be exchanged."). A call-bound gateway token gets that claim with #2727 / stacklok/toolhive#7061, so the broker client can't exchange it for a fresh token, whether or not the marker refusal (stacklok/toolhive#7247) has landed. Today's self-exchange works only because gateway tokens don't carry the claim yet.

I've added a note on #2727 to extend TestAS2LetsTheBrokerClientExchangeItsGatewayToken to a call-bound token there, so the refusal is pinned rather than assumed.

@ChrisJBurns
ChrisJBurns merged commit c56191e into main Nov 27, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the chris/2533-as2-idjag-only branch November 27, 2026 11:15
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.

3 participants