Repository navigation
feat(identitybroker): authenticate the broker to AS-1 and AS-2 with private_key_jwt - #2573
Merged
Merged
Conversation
This was referenced Oct 27, 2026
ChrisJBurns
added a commit
that referenced
this pull request
Oct 27, 2026
The error-reasons table named only HTTP 503 as retryable. A 429, 502, or 504 from a proxy or rate limiter in front of AS-1 or AS-2 is a passing outage too, not a configuration fault, so map it to UNAVAILABLE as the broker's token-endpoint client already does (#2573). Co-authored-by: Mecatl <[email protected]>
jhrozek
approved these changes
Oct 27, 2026
jhrozek
left a comment
Contributor
There was a problem hiding this comment.
Looks good. The assertion matches rfc7523bis (issuer as the sole aud, typ, fresh jti), refusals can't carry server text, redirects are refused on a copy of the caller's client, and the key is kept apart from the agent issuer key.
A few non-blocking nits inline. The first two matter most because session open and redemption will build on IsConfigurationFault / IsUnavailable; fixing them here or in a follow-up is fine.
ChrisJBurns
added a commit
that referenced
this pull request
Oct 27, 2026
…icate failures Address review on #2573: - server_error and temporarily_unavailable are retryable at any status, as design steps (7) and (8) say; the error-reasons table now says so. - A reason that is not a known code (for example fosite's prose error_description) counts as no reason, so the refusal is a configuration fault, as the design treats it. - A cancellation while reading the response returns the context error, and a certificate that does not verify returns ErrTransportConfiguration, a configuration fault, not a retryable ErrNoResponse. - The AS-1 test decodes the client_assertion the harness received and checks its kid against the published key set. Co-authored-by: Mecatl <[email protected]>
…rivate_key_jwt Add client assertions for the broker's OAuth client mecatl (RFC 7523, design step (5)): ES256 over a crypto.Signer, typ client-authentication+jwt, kid as the RFC 7638 thumbprint, iss=sub=mecatl, aud the server's issuer, a lifetime of at most 60 seconds, and a random jti, with the public key published as an inline JWK set. Add the authorization-server refusal types and the design's mapping to configuration faults and retryable errors in the broker package, and a token-endpoint client (internal/adapter/authserverclient) that posts forms with a fresh assertion, never a client secret, refuses redirects, and caps responses. mecak8s generates a separate broker client key at startup, kept inside the broker wiring until session open uses it. The harness's AS-1 now allows the clock skew on assertion exp and iat, so a replay just after exp is refused by its used jti. Closes #2489. Co-authored-by: Mecatl <[email protected]>
…dentitybroker Move the authorization-server client to internal/identitybroker/adapter/authserverclient so everything that belongs to the identity broker lives in one tree and can move into its own service together. The core's no-network depguard rule now excludes adapter/**; a new rule limits the adapters to the standard library, the broker core, and golang-jwt; and only internal/app may import them. Co-authored-by: Mecatl <[email protected]>
…usal codes Treat 429, 502, 503, and 504 as retryable, never as configuration faults: a proxy or rate-limit response is a passing outage, not a broker bug. The design names 503; the others are a deliberate extension. Report a request that got no response by a fixed kind (timeout, dns, tls, connection refused, connection closed, other) instead of the transport error's text, which a custom transport or a malformed status line could fill with request or server-echoed data. Show only known OAuth error codes and the design's reason codes; any other value is reported as unknown, so a server echoing an opaque token cannot put it into an error. Co-authored-by: Mecatl <[email protected]>
…icate failures Address review on #2573: - server_error and temporarily_unavailable are retryable at any status, as design steps (7) and (8) say; the error-reasons table now says so. - A reason that is not a known code (for example fosite's prose error_description) counts as no reason, so the refusal is a configuration fault, as the design treats it. - A cancellation while reading the response returns the context error, and a certificate that does not verify returns ErrTransportConfiguration, a configuration fault, not a retryable ErrNoResponse. - The AS-1 test decodes the client_assertion the harness received and checks its kid against the published key set. Co-authored-by: Mecatl <[email protected]>
…able The design's error-reasons table now lists 429, 502, and 504 next to 503, so they are no longer an extension of it. Co-authored-by: Mecatl <[email protected]>
ChrisJBurns
force-pushed
the
feat/identitybroker-client-auth
branch
from
October 27, 2026 14:18
da74940 to
0b0c175
Compare
1 of 14 tasks
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.
Closes #2489.
The identity broker can now prove to AS-1 and AS-2 that it is the OAuth client
mecatl: it signs a freshprivate_key_jwtclient assertion (RFC 7523) for every token-endpoint request, with its own key. #2492 (session open), #2533 and #2535 (grant and redemption), and #2538 build on this.What changes
Client assertions (
internal/identitybroker/clientassertion.go):NewClientAssertionSigner(crypto.Signer, lifetime)mints assertions as design step (5) specifies: headertyp: client-authentication+jwt,alg: ES256,kid= the key's RFC 7638 thumbprint; claimsiss=sub=mecatl,aud= the server's issuer as a single string,iat,expwith a lifetime of 1 to 60 seconds (default 60), and a randomjtiper assertion.JWKS()publishes the public key as an inline JWK set, which is how ToolHive registers it (it rejectsjwks_urion purpose). P-256 keys only, throughcrypto.Signerso the key can later move to a KMS or HSM. The agent SVID signer shares onepublicJWKhelper for the thumbprint; SVID output is unchanged.Refusals (
internal/identitybroker/serverrefusal.go):ServerRefusal{Status, Code, Reason},ErrNoResponse, and the design's mapping (credentials-and-lifecycle.md, "Error reasons"):IsConfigurationFault(invalid_client,unauthorized_client,invalid_target, an OAuth refusal with no reason or with a reason that is not a known code, or a certificate that does not verify,ErrTransportConfiguration) andIsUnavailable(status 429, 502, 503, or 504, the codeserver_errorortemporarily_unavailableat any status, or no response). This matches the design's error-reasons table, which this PR extends withserver_errorandtemporarily_unavailablenext to HTTP 503, 429, 502, and 504. A cancellation while reading the response returns the context error. They live in the broker package, which has no network code, so Convert the sign-in at session open #2492 and Per-call grant and gateway token #2535 can map them to gRPC statuses inside the broker. Only known OAuth error codes and the design's reason codes are kept and shown; anything else becomesunknown, so a server cannot put free text or a token into an error. A request that got no response is reported by a fixed kind (timeout, dns, tls, connection refused, connection closed, other), never the transport error's text.Token-endpoint client (
internal/identitybroker/adapter/authserverclient): posts forms to a configured token or revocation endpoint (https only, no user info) withclient_assertion_typeand a fresh assertion whose audience is that server's issuer; never a client secret or Basic authentication, and refuses forms that try to carry client credentials. It requires the caller's*http.Client, always refuses redirects (on a copy of that client, so a redirect cannot resend the form elsewhere), caps the response at 1 MiB, and returns the core refusal types. Retry is the caller's choice: each call mints a new assertion andjti, andErrNoResponsesays a caller may retry once.Layout for extraction: everything that belongs to the broker now lives under
internal/identitybroker/: the core (no network code, as before) and its adapters underinternal/identitybroker/adapter/, so the broker can move into its own service as one tree. Lint rules keep it that way: the core's no-network rule excludesadapter/**; the adapters may import only the standard library, the broker core, and golang-jwt; and onlyinternal/appmay import the broker's adapters.The broker client key (
internal/app/identitybroker.go): generated at startup, separate from the agent issuer key (one key per role), and kept inside the broker's wiring; it is not exposed onBuilt. Nothing uses it until Convert the sign-in at session open #2492 passes it into the broker. Until Keys and gateway entries for the identity broker #2538 supplies an operator key it is per process, so an external server holding it inline would need it re-registered after a restart; in-process servers register it at each build.Harness (
internal/testutil/identityharness): AS-1's assertion check now allows the clock skew onexpandiat, as the design does (ClientAssertionClockSkew), so a replay just afterexpis refused by the usedjti, not by expiry.Design: the error-reasons table in
credentials-and-lifecycle.mdnow also lists the error codesserver_errorandtemporarily_unavailableas retryable, matching steps (7) and (8).Not in this PR
mecatlin the real servers: AS-1 in Host AS-1 in mecak8s #2490; the embedded AS-2 in Configure the embedded gateway's authorization server as AS-2 #2533, which also tests the broker's assertions against the real AS-2 once a ToolHive release accepts the issuer as the assertion audience (Accept issuer as client assertion audience toolhive#6946, merged after v0.57.0).jtistore shared across replicas; ToolHive caps assertion lifetime at 5 minutes rather than 60 seconds): ToolHive track (Phase 1, Track: ToolHive — The authorization server and gateway changes the phase 1 flow needs #2543).Testing
jtiper call, lifetimes 1 s, 30 s, and 60 s accepted and 61 s, below 1 s, and negative refused, non-P-256 and opaque signers, and the JWK set round-tripping to a key that verifies an assertion, with thekidchecked against an independently computed thumbprint.invalid_target, a missing body, a 307, wrapped errors, andErrNoResponse.typ,alg) and claims (iss,sub,aud, lifetime, non-emptyjti) are checked;jti, and an unregistered key are refused withinvalid_clientand classified as configuration faults;invalid_clientandunauthorized_clientwith a reason are configuration faults, a 400 with a reason is not, and a 503 is unavailable;expbut within the skew is accepted, and a replay of a used assertion within that window is refused (mutation-checked againstjtiretention);go test -raceoninternal/identitybroker,internal/adapter/authserverclient, the harness, and the app's identity broker tests;cmd/mecak8s;go vet; the offline demo.task lintis clean except the existing gosec finding inenvironment/microvm/launch_ownership_darwin.go.API compatibility
No wire, engine API, or stored-data change. New internal packages and types only; nothing user-visible changes.