Skip to content

feat(identitybroker): register the broker client at hosted AS-1 - #2653

Merged
ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-register-broker-client
Nov 3, 2026
Merged

ChrisJBurns merged 5 commits into
mainfrom
feat/identitybroker-register-broker-client

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2607. The last "Done when" item waits for stacklok/toolhive#7026, which lets a delegate with api_audience obtain Mecatl API access tokens.

Summary

  • Builds on the ToolHive v0.60.0 bump in chore(deps): bump ToolHive to v0.60.0 #2656.
  • Hosted AS-1 (mecak8s) registers the identity broker's confidential delegate client mecatl: private_key_jwt authentication with the broker client key, a restricted token-exchange policy (allowed source clients = the TUI, api_audience = the Mecatl API), and exchange of refresh tokens that issue ID-JAGs capped at 12h (hostedAS1IDJAGMaxLifetime).
  • The broker client key is written to a private temp jwks_file that AS-1 reads once at startup and removes; ToolHive reads delegate keys only from a file, not a jwks_uri.
  • Startup creates the broker key, then AS-1, then the broker, filling IdentityBrokerAS1 with an in-process client that honours the request context and applies a 10s per-request timeout (as1RequestTimeout).
  • Session open now converts a TUI sign-in at hosted AS-1.

Decisions

Known gaps

Testing

  • task lint: no new findings. The run stops at an existing gosec G703 finding in environment/microvm/launch_ownership_darwin.go:754, a file this PR does not touch.
  • task test:race: everything this change touches passes. Fifteen tests in cmd/mecated, cmd/mecatui, cmd/mecatui/customization, environment/microvm/gitexec, internal/app and internal/adapter/server fail in this macOS checkout, and fail the same way on a clean main.
  • go run ./cmd/mecademo shows a tool call, a permission ask and approval, and the result.
  • CI's Kind e2e (k8s e2e (kind)) signs in through hosted AS-1 with Dex and now converts the sign-in at session open.

New tests:

  • TestDelegateConvertsASignIn, TestDelegateRefusesASpentSubjectToken, TestDelegateRefusesAnUnlistedSourceClient, TestDelegateRefusesBadAssertions (internal/identitybroker/adapter/as1server).
  • TestDelegateCannotObtainAPIAccessTokens (skipped until Configured delegate client with api_audience can exchange for API access tokens toolhive#7026) and TestDelegateRequiresOfflineAccess (skipped while ToolHive does not enforce offline_access).
  • TestInProcessClientServesTheHandler, TestInProcessClientStopsWaitingAtTheDeadline, TestInProcessClientClosesTheBodyWhenAbandoned, TestInProcessClientClosesARefusedBody.

Updated or existing tests that cover the wiring:

  • TestIdentityBrokerWiringConvertsAtAS1, TestIdentityBrokerHostsAS1, TestIdentityBrokerAS1RequiresTheBroker, TestIdentityBrokerKeysAreSeparatePerRole, TestIdentityBrokerIsReleasedWhenAS1ConstructionFails, TestIdentityBrokerConstructionFailureStopsStartup (internal/app).
  • TestHostedAS1SignsTheTUIIn, TestHostedAS1RoutesMountWithoutConflicts, TestHostedAS1ServesBesideTheMCPBroker, TestHostedAS1AnonymousSurfaceIsBounded, TestHostedAS1RateLimitsAreGlobalPerSurface (cmd/mecak8s).
  • TestInProcessClientServesOnlyTheIssuer, TestSigningKeyFileSurvivesRestart, TestGeneratedSigningKeysDifferPerInstance, TestSignInIssuesAudienceTokenWithCompanyIdentity (internal/identitybroker/adapter/as1server).

API compatibility

Assessed per wire API compatibility. On deployments with hosted AS-1, session open now converts the caller's access token and can return the existing bearer_rejected (HTTP 401, invalid_token challenge) and sign_in_required (HTTP 401) reason codes. No protobuf or code changes to the wire contract: these sentinels and their REST and gRPC mappings already exist (internal/adapter/server/errorcodes.go). Existing conforming clients already handle them: mecatui refreshes and retries once on bearer_rejected (cmd/mecatui/client/auth.go isBearerRejected, cmd/mecatui/client/client.go, cmd/mecatui/client/reopen.go) and prompts a new sign-in on sign_in_required (cmd/mecatui/client/auth.go).

This is not a wire break: the message set is unchanged, and the newly reachable reason codes are already part of the contract clients handle.

ChrisJBurns and others added 2 commits November 2, 2026 23:22
Register the confidential delegate client `mecatl` at hosted AS-1 with
private_key_jwt and a restricted token-exchange policy, writing the broker
client key to a private temp jwks_file read once at startup. Wire the
in-process AS-1 client with a per-request timeout so session open converts a
TUI sign-in. Bump ToolHive to v0.60.0.

Part of #2607

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-register-broker-client branch from ee035ee to e4e12c4 Compare November 2, 2026 23:23
A second session opened with the same access token is refused with
bearer_rejected, before and after a pod restart, which only a real
exchange at AS-1 produces.

Part of #2607

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

This comment was marked as outdated.

- Prefer a finished in-process response over a context that ended at the
  same moment, so a converted token is never thrown away.
- Drop DelegateClient.APIAudience: it could only equal AS-1's audience.
- Lower the in-process AS-1 timeout to 10s and state what it bounds.
- Correct comments: the delegate's limits (toolhive#7026), ClientKey,
  the JWT-bearer grant, and the re-raised panic.
- Design: the hosted broker key is in memory, the hard expiry is 12h,
  and the broker's key set is read only at registration.
- Operating guide: single-use conversion holds within one pod lifetime.
- Tests: pin the grant expiry to the cap, release the abandoned handler
  in cleanup; run the Kind e2e on internal/app/build.go changes.

Part of #2607

Co-authored-by: Mecatl <[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.

2 participants