Repository navigation
feat(identitybroker): register the broker client at hosted AS-1 - #2653
Merged
Merged
Conversation
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]>
Part of #2607 Co-authored-by: Mecatl <[email protected]>
ChrisJBurns
force-pushed
the
feat/identitybroker-register-broker-client
branch
from
November 2, 2026 23:23
ee035ee to
e4e12c4
Compare
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]>
- 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]>
…osed Part of #2607 Co-authored-by: Mecatl <[email protected]>
jhrozek
approved these changes
Nov 3, 2026
This was referenced Nov 3, 2026
Merged
Merged
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #2607. The last "Done when" item waits for stacklok/toolhive#7026, which lets a delegate with
api_audienceobtain Mecatl API access tokens.Summary
mecatl:private_key_jwtauthentication 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).jwks_filethat AS-1 reads once at startup and removes; ToolHive reads delegate keys only from a file, not ajwks_uri.IdentityBrokerAS1with an in-process client that honours the request context and applies a 10s per-request timeout (as1RequestTimeout).Decisions
grant_invalidfrom AS-1. An allowance would only let the broker present a grant AS-1 may already have expired. This holds whether or not AS-1 shares the broker's clock. Recorded in the design doc (step (3)) and the Register the broker client at AS-1 and point the broker at it #2607 body.id_jag_max_lifetimedefaults to 12h, which bounds the broker refresh token and so the session's hard expiry. Keys and gateway entries for the identity broker #2538 makes it configurable. Recorded here, onhostedAS1IDJAGMaxLifetime, and in the design doc (step (3) and "Configuration").as1RequestTimeout.Known gaps
api_audiencecan obtain Mecatl API access tokens; the covering test is skipped.offline_accessis not enforced by ToolHive v0.60.0; the covering test is skipped.audor an unregistered key returns 401invalid_client, an expired or over-long assertion returns 500server_error, and a reusedjtireturns 400jti_known. Tracked in Authorization server: refuse every failed private_key_jwt client assertion with 401 invalid_client toolhive#7028.expat 5 minutes).Testing
task lint: no new findings. The run stops at an existing gosec G703 finding inenvironment/microvm/launch_ownership_darwin.go:754, a file this PR does not touch.task test:race: everything this change touches passes. Fifteen tests incmd/mecated,cmd/mecatui,cmd/mecatui/customization,environment/microvm/gitexec,internal/appandinternal/adapter/serverfail in this macOS checkout, and fail the same way on a cleanmain.go run ./cmd/mecademoshows a tool call, a permission ask and approval, and the result.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) andTestDelegateRequiresOfflineAccess(skipped while ToolHive does not enforceoffline_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_tokenchallenge) andsign_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:mecatuirefreshes and retries once onbearer_rejected(cmd/mecatui/client/auth.goisBearerRejected,cmd/mecatui/client/client.go,cmd/mecatui/client/reopen.go) and prompts a new sign-in onsign_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.