Skip to content

feat(identitybroker): AS-2 trusts the hosted AS-1 in production - #3018

Merged
ChrisJBurns merged 11 commits into
mainfrom
chris/2533-as2-trust-wiring
Nov 28, 2026
Merged

ChrisJBurns merged 11 commits into
mainfrom
chris/2533-as2-trust-wiring

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Closes #2533. Stacked on #3015; review that first.

#3015 made the embedded gateway's authorization server (AS-2) able to trust AS-1 in ToolHive's resolve mode. This PR turns that trust on in production, from mecak8s's configuration.

Changes

  • Startup builds AS-2's trust from the hosted AS-1. It uses:

    • AS-1's issuer and its signing-key URL;
    • the agent trust domain, as the accepted actor issuer;
    • AS-1's company IdP issuer, subject claim, CA and private-address setting.

    AS-2 and AS-1 therefore can't disagree on the IdP or the identifying claim. The trust is carried on the AS-1 the broker uses (IdentityBrokerAS1.AS2Trust), so tests with an external AS-1 set it in the same place. No top-level test-only trust remains.

  • New settings (flags, with matching Helm values under identityBroker.as2). All of them require --identity-broker-as1-issuer:

    • --identity-broker-as2-upstream-client-id and --identity-broker-as2-upstream-client-secret-file: AS-2's own client at the company IdP, with redirect URI <AS-2 issuer>/oauth/callback.
    • --identity-broker-as2-as1-ca-file and --identity-broker-as2-as1-allow-private-addresses: for an AS-1 issuer at a private address or behind a private CA, when AS-2 fetches AS-1's keys. Allowing private addresses requires the CA.
  • Gateway entry. Servers are accepted once AS-1 is hosted and AS-2's client is set.

  • Helm: values, schema (as2 is optional, so --reuse-values upgrades keep working), flag rendering, read-only Secret mounts, the extraArgs ban extended to --identity-broker-as2-*, and the "servers must stay empty" rule replaced.

  • Operator guide:

    • a new section, "Route servers through the gateway": AS-2's registration at the company IdP, when the key-fetch settings are needed, and what real IdPs bring (first-time consent, with admin consent in Entra ID; the account picker; conditional access and MFA; a refresh token needed without a prompt);
    • the current limits;
    • three statements that were no longer true, corrected.
  • Server CLI reference regenerated.

  • New shortcut marker: a cancelled or failed provider leg fails a user's whole first sign-in at AS-2. Removed by Connect link for a missing provider connection, through the gateway's URL elicitation #2973, after Embedded runner: an option to set NonFatalSecondaryLegs toolhive#7370.

Kept shortcuts (in #2451's table)

Tests

  • TestHostedAS1GatewayCallFromFlags starts mecak8s from flags only: hosted AS-1, servers in the gateway entry, and no test-only trust. Before Alice signs in at AS-2, the call is refused with subject_unknown. Afterwards it gets a marked gateway token naming her AS-2 user, the agent and the vMCP, and the served vMCP accepts the token.
  • TestHostedAS1ComposesAS2sTrust: the composed trust carries AS-1's subject claim (oid), IdP issuer and CA. AS-2's key-fetch private-address setting and the IdP's are kept separate. There is no trust without AS-2's client.
  • TestHostedAS1KeysAtAPrivateAddressNeedTheSetting: a private key-set address without the setting fails startup.
  • Refusal tests: TestBuildRefusesGatewayServersAS2DoesNotTrust, TestBuildRefusesAS2SettingsThatWouldDoNothing.
  • Flag rule and mapping tests.
  • Helm tests: render tests and refusal cases. The upgrade fixtures now omit as2, so the nil path is exercised.
  • The rest of Configure the embedded gateway's authorization server as AS-2 #2533's "Done when" (refusals, marker, exchange refusal) is covered at the adapter level in feat(mcpbroker): AS-2 resolves AS-1's ID-JAG users through the company IdP #3015, on the same trust type.
  • Mutation checks: each of these fails a test:
    • a wrong subject claim, IdP issuer, actor issuer, CA, JWKS URL or private-address source;
    • any removed refusal or flag rule;
    • a dropped Helm render or rule;
    • removing the chart's nil guard.

API compatibility

No wire change for existing clients. The new flags and Helm values are additive and off by default, and with them unset nothing changes. With them set, calls to servers listed in the gateway entry fail closed until #2537.

Testing

  • go test passes for ./internal/adapter/mcpbroker/..., ./internal/identitybroker/..., ./internal/app, ./cmd/mecak8s, ./deploy/helm/mecak8s/... and ./deploy/mecak8s-idbroker/....
  • task deploy:helm-unittest and task deploy:check pass.
  • task docs:check and task site:build pass, and golangci-lint reports no issues.
  • task docs:server-cli:check is the one exception: it reports a difference on the existing --workspace default line. That line wraps by the local checkout path's length. The new flags' sections match the generator exactly.

After merge

ChrisJBurns and others added 6 commits November 28, 2026 11:23
v0.70.1 turns on subject resolution at ID-JAG redemption
(stacklok/toolhive#7247), which #2533 needs.

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

With mcpbroker.AS1Trust set, the embedded gateway's authorization
server (AS-2) trusts AS-1's ID-JAGs in ToolHive's subject mode
resolve: it finds the gateway user from the ID-JAG's upstream_subject
through the company IdP, which becomes the first step of AS-2's
sign-in, accepts only the agent trust domain as the actor's issuer, and
issues marked gateway tokens that ToolHive refuses at token exchange.
This replaces the test-only per-subject trust. Composition still sets
the trust only in tests; the next change wires it from mecak8s's
configuration.

What only tests may set (the vMCP's maximum call duration, and a
sign-in client in AS-2's store) moves to mcpbroker.TestSeam, kept out
of production code by an internal package and depguard. mcpbrokertest
signs users in at AS-2 so tests across packages can redeem through
resolution.

Part of #2533.

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

`go work sync` dropped the go.mod hashes the standalone modules need,
so `GOWORK=off` builds failed; `task tidy:module` restores them for
environment/microvm, authn/oidc and the providers. go-redis 9.24
deprecates ScanIterator.Next and Val, so the Redis stores range over
Vals instead.

Co-authored-by: Mecatl <[email protected]>
Startup builds the embedded gateway authorization server's (AS-2) trust
from the hosted AS-1: its issuer and signing keys, the agent trust
domain, and AS-1's company IdP issuer, subject claim and CA, so AS-2
and AS-1 cannot disagree. The operator supplies only AS-2's own client
at the company IdP and, for an in-cluster AS-1, a CA and private-address
setting for fetching AS-1's keys (--identity-broker-as2-* flags and
identityBroker.as2 Helm values).

The embedded gateway entry may now list servers once AS-1 is hosted and
AS-2's client is set; settings that would do nothing are refused, in
mecak8s and in the chart. The trust is carried on the AS-1 the broker
uses, so tests with an external AS-1 set it there and no top-level
test-only trust remains. The operator guide covers AS-2's registration,
the key-fetch settings and the IdP caveats.

Part of #2533.

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

Address review of #3015:
- Check AS-2's trust in AS-1 and the company IdP name collision before
  anonymous discovery contacts any upstream.
- Say that composition must fill the company IdP's issuer, claim and
  CA, and the actor issuer, from AS-1's settings, and what a mismatch
  looks like.
- ToolHive always allows a loopback company IdP, and refuses a private
  key-set host at startup only when it is a literal address.
- ToolHive refuses a future iat within its skew; the lifetime cap
  bounds how old an ID-JAG can be. A refusal row pins the future iat.
- Pin the authorization request the company IdP receives: no prompt
  or max_age, PKCE, AS-2's client and callback, and today's scope.

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

Copy link
Copy Markdown
Contributor Author

Holding until a ToolHive release contains stacklok/toolhive#7347 (provider identities bound to their issuer and claim), per review on #3015. This PR will bump ToolHive to that release before it merges.

@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 trust is built from the hosted AS-1, so AS-1 and AS-2 can't disagree on the IdP, the claim or the actor issuer. With the new settings unset nothing changes, the chart refuses the same combinations as mecak8s, and TestHostedAS1GatewayCallFromFlags covers the whole path from flags alone. One small nit inline.

Base automatically changed from chris/2533-as2-production-trust to main November 28, 2026 17:10
ChrisJBurns and others added 2 commits November 28, 2026 17:11
origin/main's tree equals #3015's final commit, already on this branch,
so every conflict resolves to this branch's side.

Co-authored-by: Mecatl <[email protected]>
The ban's pattern allowed no digit after the flag prefix, so both flags
for AS-2's fetch of AS-1's keys got past it.

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

Copy link
Copy Markdown
Contributor Author

No longer holding. #2533 doesn't need another ToolHive release, so the bump to a release containing stacklok/toolhive#7347 (provider identities bound to their issuer and claim) is tracked in #3019, under slice 4. Until then, the gap needs an operator to switch AS-2's company IdP or identifying claim over an existing store, and the trust is off unless the new flags are set.

@ChrisJBurns
ChrisJBurns merged commit 5fd31d7 into main Nov 28, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the chris/2533-as2-trust-wiring branch November 28, 2026 17:42
rdimitrov added a commit that referenced this pull request Nov 28, 2026
Brings in #3018 (AS-2 trusts the hosted AS-1 in production). The broker
keeps both the audit sink's close and main's AS-1 trust, and the CLI
reference is regenerated with both flag sets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Configure the embedded gateway's authorization server as AS-2

2 participants