Skip to content

test(identitybroker): add the offline agent identity harness - #2459

Merged
ChrisJBurns merged 1 commit into
mainfrom
feat/identitybroker-offline-harness
Oct 21, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
feat/identitybroker-offline-harness

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the offline test harness for the agent identity work: stand-ins for the upstream company IdP and AS-1 sign-in, and an end-to-end test that starts mecak8s with the identity broker on against them.

Builds on #2450, now merged; rebased onto main.

Harness (internal/testutil/identityharness)

  • Upstream IdP: a standard OIDC provider (authorization code, RS256 ID token, JWKS). It issues an upstream refresh token only for offline_access with prompt=consent (OIDC Core §11), which AS-1's later upstream re-check needs. RegisterClient is exported so S3.4 can use it as the upstream of the real ToolHive AS-1.
  • AS-1 sign-in: authorization code with required S256 PKCE. AS-1 signs the user in at the IdP as an OIDC client, verifying the ID token against the IdP's published keys, and issues the access token of design step (1): typ at+jwt, ES256, and iss, sub, sub_id (iss_sub), aud, client_id, iat, exp, jti. The issuer has a path (/as), as AS-1's final issuer URL does, and discovery is served at both the OIDC and RFC 8414 locations. Each company identity keeps one AS-1 subject, never shared. Clients receive a refresh token.
  • Forcing failures: one-shot faults on either stand-in (FailNextAuthorization, FailNextToken, with an optional design reason code at the start of error_description), and MintAccessToken for tokens with a chosen defect: no sub_id, wrong audience, issuer, or typ, expired, or signed with a key AS-1 does not publish.
  • Client side: SignIn and Refresh drive the flow the TUI or Studio would; WriteCACert supplies --oidc-ca-cert-file.

End-to-end (cmd/mecak8s)

mecak8s starts with --enable-identity-broker and the harness's AS-1 as its OIDC issuer. Alice and Bob sign in through AS-1 and the IdP; Alice's token creates a session that Bob cannot list; no token, a foreign key, another audience, another issuer, and an expired token are refused with 401.

The existing OAuth and MCP test servers are package-private _test.go fixtures (for example internal/adapter/server/mcp_broker_multi_upstream_e2e_test.go, cmd/mecatui/oidc_fixture_test.go), so none could be imported. The harness follows the internal/testutil/recoveryhost precedent.

Issue relationship

Closes #2448

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): test infrastructure only; no production code changes

Test plan

Baseline checks

  • Linting (task lint): clean on every module except the pre-existing darwin-only gosec finding in environment/microvm/launch_ownership_darwin.go, untouched here (same as feat(identitybroker): start the identity broker in mecak8s behind an authentication boundary #2450).
  • Fast offline test suite (task test): not run in full; no production code changes. Focused runs below.
  • Pre-review race suite: go test -race passes for ./cmd/mecak8s/ and ./internal/testutil/.... Full task test:race not run; no production code changes.
  • Offline demo (go run ./cmd/mecademo): tool call, permission ask and approval, and result shown.
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

Harness tests cover the step (1) token (verified through both discovery locations), stable and distinct subjects, the upstream offline-access request, refresh for the same user and client only, every forced failure (each fires once), unknown clients and redirect URIs refused without a redirect, code-grant checks (wrong verifier, wrong redirect URI, reuse, missing or plain PKCE), and each minted defect.

Mutation checks: removing AS-1's PKCE check, dropping prompt=consent from the upstream request, or signing Bob in as Alice in the end-to-end test each fails a test.

Changes

File Change
internal/testutil/identityharness/harness.go Harness, Options, defaults, CA helpers, one-shot faults
internal/testutil/identityharness/idp.go Upstream company IdP stand-in
internal/testutil/identityharness/as1.go AS-1 sign-in stand-in and MintAccessToken
internal/testutil/identityharness/signin.go Client-side SignIn and Refresh
internal/testutil/identityharness/oauth.go Shared OAuth helpers
internal/testutil/identityharness/harness_test.go Harness tests
cmd/mecak8s/identity_broker_harness_test.go End-to-end test against mecak8s with the flag on

User-facing change

None.

Special notes for reviewers

  • Scope is the issue's "Done when": the upstream IdP and AS-1 sign-in. The other stand-ins the issue lists arrive with the work that tests them, each in its own files: the session-open exchange and refresh-token revocation (S3.6), private_key_jwt (S3.3), ID-JAG issuance (S4.3), and the gateway stand-in (S4.3/S4.4, to be stated explicitly in those tickets).
  • No AS-2 stand-in, by design: tests use the real embedded ToolHive authorization server.
  • The end-to-end test does not call the identity broker yet; nothing in mecak8s does. It checks that the broker is constructed, and later work extends the test as each step lands, up to the demo scenario S6.1 expects it to cover.
  • The harness is test code under internal/testutil; only tests import it. It uses golang-jwt/jwt/v5, already a direct dependency.

API compatibility: no remote-observable change. Test code only; no protobuf, gRPC, HTTP, or engine API surface changes. No major or feature-identifier change.

Base automatically changed from feat/identitybroker-mecak8s-startup to main October 21, 2026 19:39
Add internal/testutil/identityharness, offline stand-ins for the external
parties of the agent identity credential flow, so identity broker and Mecatl
composition tests share one implementation of the design instead of each
inventing its own.

The upstream company IdP is a standard OIDC provider: authorization code,
an RS256 ID token, and JWKS, issuing an upstream refresh token only for
offline_access with prompt=consent. RegisterClient is exported so a real
AS-1 can use it as its upstream.

AS-1 signs users in with authorization code and required S256 PKCE, signs
them in at the IdP as an OIDC client that verifies the ID token against the
IdP's published keys, and issues the access token of design step (1): typ
at+jwt, ES256, and iss, sub, sub_id, aud, client_id, iat, exp, jti. Its
issuer has a path, as AS-1's final issuer URL does. Each company identity
keeps one AS-1 subject, never shared. Clients receive a refresh token.

Tests force failures with one-shot faults on either stand-in and mint
access tokens with a chosen defect. SignIn and Refresh drive the client
side of the flow.

An end-to-end test starts mecak8s with --enable-identity-broker and AS-1 as
its OIDC issuer: two users sign in, their tokens own the sessions they
create, and tokens AS-1 would not issue are refused.

Co-authored-by: Mecatl <[email protected]>
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-offline-harness branch from 0549567 to 52e412f Compare October 21, 2026 19:40
@ChrisJBurns
ChrisJBurns merged commit f5e3308 into main Oct 21, 2026
40 of 43 checks passed
@ChrisJBurns
ChrisJBurns deleted the feat/identitybroker-offline-harness branch October 21, 2026 19:59
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Oct 23, 2026
2 tasks
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.

Offline test harness

2 participants