Repository navigation
Description
Depends on: stacklok/toolhive#7026 (for the last "Done when" item only)
Mecatl change at startup and in AS-1's configuration.
Problem
AS-1 signs users in, but the identity broker cannot convert their sign-ins there:
- the broker client
mecatlis not registered at AS-1; - AS-1 has no policy limiting which tokens
mecatlmay exchange; - the broker is not pointed at hosted AS-1.
Session open does not need ID-JAG issuance or child grants (stacklok/toolhive#6898, stacklok/toolhive#6897).
Design
- credentials-and-lifecycle.md: (3) Session open and the broker refresh token
- credentials-and-lifecycle.md: (5) Broker client authentication
- implementation.md: ToolHive work list
Requirements
-
mecatl's configuration at AS-1. A pre-provisioned confidential delegate client with:- a fixed
client_idandtoken_endpoint_auth_method: private_key_jwt; - the broker client's public keys as a
jwks_file, neverjwks_uri. ToolHive reads a delegate's keys only from a file, once, at startup, so hosted AS-1 writes the key set to a private temporary file and removes it after AS-1 is built. The signing algorithm (ES256) is derived from the P-256 key; grant_types= the token-exchange grant URN only;- the required
scopes; audiencescontaining the Mecatl API audience (api_audiencemust be listed there);- no client secret and no redirect URIs.
The issuer the broker uses as the assertion audience equals AS-1's
issuerbyte for byte, trailing slash included. - a fixed
-
mecatl's exchange policy at AS-1:token_exchange.self_issued_subject_tokens: restricted. Aprivate_key_jwtdelegate without atoken_exchangeblock fails startup, andrestrictedis the only mode that allowsapi_audience;allowed_source_clients= the TUI's client ID (Studio's in phase 3);api_audience= the Mecatl API audience;token_exchange.exchange_refresh_tokens.id_jag_max_lifetimeset to a documented default until Keys and gateway entries for the identity broker #2538 provides a setting;token_exchange.exchange_refresh_tokens.refresh_token_max_lifetimestays unset until schedule grants (Phase 2, Slice 3: Scheduled runs — A scheduled run calls gateway tools on its own grant, with no one present #2569).
Build this delegate configuration so Configure the embedded gateway's authorization server as AS-2 #2533 can reuse it for AS-2.
-
The broker reaches AS-1. Startup fills
app.Config.IdentityBrokerAS1with production values for AS-1 hosted in mecak8s: its issuer, its token endpoint, and an in-process HTTP client. That client needs a timeout that really bounds the call, because a session open holds its host session's lock for the whole exchange, including one resend. The in-process transport (as1server.InProcessClient) runs AS-1's handler synchronously, sohttp.Client.Timeoutcannot stop it. Two further rules:- Leave
IdentityBrokerAS1.Nowunset (real time); it is a test hook. - No revocation endpoint: phase 1 discards and never revokes (Sign-out and revocation #2568, RFC 7009 token revocation endpoint toolhive#6966).
- Leave
-
Startup order. Create the broker client key, then build AS-1 with that key's public JWK, then the broker. Today
buildIdentityBroker(internal/app/identitybroker.go) builds the broker before AS-1 and keeps only its core, dropping the client signer. Keys and gateway entries for the identity broker #2538 owns loading an operator-supplied key. -
Clock. The echo check at open (
echoMatches,internal/identitybroker/sessionopen.go) is exact: the requested and echoedexpires_atare both absolute times from the broker's own request. The hard-expiry check counts the expiry as reached one clock skew early (credentialClockSkew, interim 30 seconds, until Keys and gateway entries for the identity broker #2538 adds the setting;credentials-and-lifecycle.mdstep (6), check 2), so skew fails closed and the broker never presents a grant AS-1 may already have expired (fix(identitybroker): count a session's hard expiry one clock skew early #2658). -
Assertion checks (
credentials-and-lifecycle.mdstep (5), checks 5 and 6). With v0.60.0, AS-1 caps an assertion'sexpat 5 minutes from its clock and refuses a reusedjti. The 60-second maximum and the clock-skew allowance wait for Authorization server: allow clock skew on private_key_jwt client assertions toolhive#6954. Until then, an "over-long" assertion means one over 5 minutes. The refusal codes are not uniform:- a wrong
audor an unregistered key gets 401invalid_client; - an expired or over-long assertion gets 500
server_error; - a reused
jtigets 400jti_known.
The broker keeps the design's mapping and adds no special case. While ToolHive differs, an expired or over-long assertion surfaces as a retryable
UNAVAILABLE(server_error), and a reusedjtiasINTERNAL(an unknown code). Either way no token is issued, and these cases arise only from a broker bug or clock fault. Phase 1 shortcut, removed by Authorization server: refuse every failed private_key_jwt client assertion with 401 invalid_client toolhive#7028. That issue also tracks requiring the issuer as the onlyaudvalue; v0.60.0 also accepts the token endpoint URL. Tests assert that no token is issued, and pininvalid_clientonly where ToolHive returns it. - a wrong
-
offline_access. The TUI requests it, but v0.60.0 does not require it on the subject token. Phase 1 shortcut (in Phase 1: Signed-in users' agents call gateway tools with their own access #2451), removed in phase 2 by Authorization server: exchange only access tokens issued with offline_access into refresh tokens toolhive#7029 (Phase 3, Track: ToolHive — The remaining ToolHive changes for audit, sign-out, and schedules #2570). Record it as unenforced, with a skipped test that the remover turns on. -
Restarts. AS-1's storage, the broker's sessions, and the broker client key are all in memory (phase 1 shortcuts). A restart therefore loses all of them, and the next request that carries a token opens a fresh broker session. State this in the operating guide.
-
Docs.
user-docs/features/security-and-execution/caller-identity.mddescribes the refusals at session open,bearer_rejectedandsign_in_required(the text removed in 762eb04 is a starting point). -
Tests.
TestIdentityBrokerAgainstOfflineHarnesskeeps the harness's AS-1 through theIdentityBrokerAS1hook, because it injects faults (lost responses, refusals). Add a separate test that starts mecak8s from its flags against the hosted AS-1. Fix the comment incmd/mecak8s/identity_broker_harness_test.gothat still says "No flag sets AS-1's endpoints yet (Host AS-1 in mecak8s #2490)".
How it fits
This is step (3) of the flow: the broker converts the user's sign-in into a refresh token for the session. The broker side exists and is tested against the offline harness; this ticket makes the real AS-1 accept it.
Done when
With mecak8s started from its flags (real startup, not a test hook), the real AS-1 hosted in it, and the offline harness as upstream IdP:
- A session open converts a TUI sign-in.
- After a restart, the next request with a fresh sign-in opens a new broker session.
- AS-1 refuses:
- a wrong
aud; - an expired assertion, or one whose
expis more than 5 minutes ahead; - a reused
jti; - an unregistered key;
- a Mecatl API token issued to a client not in
allowed_source_clients; - the same token presented by another client;
- an attempt by
mecatlto obtain a Mecatl API access token. This item waits for Configured delegate client with api_audience can exchange for API access tokens toolhive#7026.
- a wrong
Activity
feat(mecak8s): host AS-1 for identity broker sign-in
feat(mecak8s): host AS-1 for identity broker sign-in
ChrisJBurns commentedon Nov 2, 2026
Three notes from the #2493 work (PRs #2647, #2648):
app.IdentityBrokerAS1.Nowso tests can move the broker and its AS-1 client assertions past a hard expiry. When this ticket fillsIdentityBrokerAS1in production, leaveNownil (real time).expires_atmust be in the future and no later than requested) and the session's hard expiry (the held refresh token'sexpires_at, checked on every lookup). Decide whether either needs a skew allowance, or whether time sync between the two is assumed and documented.user-docs/features/security-and-execution/caller-identity.mddescribingbearer_rejected(token already used or subject refused) andsign_in_required(sign-in revoked) at session open, because no deployment converts tokens yet. Once this ticket makes conversion live, bring it back.4 remaining items
chore(deps): tidy every module after the ToolHive v0.60.0 bump
chore(deps): settle root go.sum after go work sync
test: follow the ToolHive v0.60.0 bump in the dependency guards
feat(identitybroker): register the broker client at hosted AS-1
test: approve as1server's delegate.go as a ToolHive import leaf
test(e2e): prove hosted AS-1 converts the sign-in at session open
fix(identitybroker): address review of the hosted AS-1 delegate client
docs(agent-identity): skew on the echo check and hard expiry fails cl…
test(identitybroker): pin the delegate refusals and know subject_toke…
fix(mecak8s): refuse hosted AS-1 scopes without offline_access