Skip to content

test(identityharness): add broker client auth, session open, and revocation to AS-1 - #2524

Merged
ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-harness-session-open
Oct 26, 2026
Merged

ChrisJBurns merged 3 commits into
mainfrom
feat/identitybroker-harness-session-open

Conversation

@ChrisJBurns

Copy link
Copy Markdown
Contributor

Closes #2494.

The offline harness's stand-in AS-1 can now do what the sign-in slice needs next: authenticate the identity broker, convert a sign-in into a session-bound refresh token, and revoke it. #2489 (broker client authentication), #2492 (session-open conversion), and #2493 (reopen) can build and test against it before the ToolHive work lands.

Test code only (internal/testutil/identityharness/); no production code changes.

What changes

  • Broker client authentication (design step (5)): AS-1 has a confidential client mecatl that authenticates with private_key_jwt. It checks iss=sub=mecatl, aud equal to AS-1's issuer as the only value, exp - iat within the maximum (60 s by default), a single-use jti, iat/exp/nbf, a string kid naming a registered key, ES256 only, and refuses client_secret and Basic authentication. Tests can mint assertions with each defect, and production code under test registers its own key through Options.BrokerKeys.
  • Session-open exchange (design step (3)): an RFC 8693 token exchange from the AS-1 access token to an opaque refresh token bound to the session, owner, and client, echoed in the response. It never rotates, and a later open of the same session by the same owner replaces and revokes the previous token without extending the hard expiry. Every check and refusal follows the design's table (invalid_client, unauthorized_client, invalid_request/invalid_scope/invalid_authorization_details, subject_invalid, owner_mismatch, session_owned, token_used), and a retry after a lost response is accepted. The mecatl_session entry is parsed strictly: member names must be exact and appear once.
  • Refresh grant: the session refresh token gets invalid_grant there; a public client cannot use token exchange.
  • Revocation (revoke.go): RFC 7009, broker only; revoking the current token closes the session, and a closed session cannot be opened again (session_owned).
  • Faults and state for later tickets: FailNextSessionOpen (a 503 or any error), LoseNextSessionOpenResponse (processed, then the connection drops), MismatchNextSessionOpenEcho, ExpireSession (or the injectable clock), and queries for a session's refresh token, refusals, and closed state.
  • h.ScriptedBroker(): a hand-driven caller holding the broker's credentials, for driving AS-1 directly in tests. It is deliberately not named like the production broker; production code under test uses its own client.
  • Discovery metadata adds private_key_jwt, the token-exchange grant, and the revocation endpoint; public clients keep none, so mecatui sign-in is unchanged.

Design guesses

Where the design is silent, the code marks each choice with // Guess:, also listed in the package doc, so they can be checked against ToolHive (stacklok/toolhive#6886, #6893, #6895, #6897) when it lands:

  1. Revocation is RFC 7009 at {issuer}/revoke, broker only; revoking a replaced or unknown token returns 200 and changes nothing.
  2. Extra members of a mecatl_session entry are accepted and echoed unchanged.
  3. An assertion typed JWT (golang-jwt's default) or untyped is accepted, as is client-authentication+jwt; the production broker's own tests must check the typ it emits.
  4. A retry or later open does not extend the hard expiry (from Refresh tokens through token exchange, as generic grants toolhive#6897); expires_in is the time left until it.
  5. Refusals are recorded for checks 4 to 7.

superseded is not offered as a session-open fault: the design returns it only to an exchange presenting a replaced refresh token, which is the later ID-JAG exchange.

Testing

  • Harness tests for each behaviour: the success path, every refusal with its exact status, code, and reason (check-3 cases assert an empty reason so a later check cannot satisfy them, with a positive control), strict entry parsing, lost-response retry, replacement, invalid_grant, revocation, closed sessions, hard expiry, every client-assertion defect (wrong aud, expired, too long, reused or missing jti, missing iat/exp/kid, future iat, alg: none, HS256, foreign key, client_secret), invalid BrokerKeys options, and each fault.
  • go test -race on the harness and cmd/mecak8s (its existing user); go vet; the offline demo. task lint is clean except the existing gosec finding in environment/microvm/launch_ownership_darwin.go.

API compatibility

No wire, engine API, or stored-data change: test infrastructure only.

…cation to AS-1

The offline AS-1 stand-in now authenticates the identity broker as the
confidential client mecatl with private_key_jwt, converts a sign-in
access token into a session-bound, non-rotating refresh token through
RFC 8693 token exchange with the design's checks and refusal reasons,
refuses that token at the refresh grant, and revokes it (RFC 7009),
closing the session. Faults (error, lost response, mismatched echo,
hard expiry) and state queries let the broker work build and test
against it offline. Design guesses are marked in the code.

Closes #2494.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns merged commit 0cf660d into main Oct 26, 2026
37 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-harness-session-open branch October 26, 2026 21:45
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks

This branch was successfully deployed

1 active deployment
Preview — 6388e3ec Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend the offline harness for session open

2 participants