Repository navigation
test(identitybroker): add the offline agent identity harness - #2459
Merged
Merged
Conversation
2 of 4 tasks
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
force-pushed
the
feat/identitybroker-offline-harness
branch
from
October 21, 2026 19:40
0549567 to
52e412f
Compare
jhrozek
approved these changes
Oct 21, 2026
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.
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)offline_accesswithprompt=consent(OIDC Core §11), which AS-1's later upstream re-check needs.RegisterClientis exported so S3.4 can use it as the upstream of the real ToolHive AS-1.typat+jwt, ES256, andiss,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.FailNextAuthorization,FailNextToken, with an optional design reason code at the start oferror_description), andMintAccessTokenfor tokens with a chosen defect: nosub_id, wrong audience, issuer, ortyp, expired, or signed with a key AS-1 does not publish.SignInandRefreshdrive the flow the TUI or Studio would;WriteCACertsupplies--oidc-ca-cert-file.End-to-end (
cmd/mecak8s)mecak8s starts with
--enable-identity-brokerand 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.gofixtures (for exampleinternal/adapter/server/mcp_broker_multi_upstream_e2e_test.go,cmd/mecatui/oidc_fixture_test.go), so none could be imported. The harness follows theinternal/testutil/recoveryhostprecedent.Issue relationship
Closes #2448
Type of change
Test plan
Baseline checks
task lint): clean on every module except the pre-existing darwin-only gosec finding inenvironment/microvm/launch_ownership_darwin.go, untouched here (same as feat(identitybroker): start the identity broker in mecak8s behind an authentication boundary #2450).task test): not run in full; no production code changes. Focused runs below.go test -racepasses for./cmd/mecak8s/and./internal/testutil/.... Fulltask test:racenot run; no production code changes.go run ./cmd/mecademo): tool call, permission ask and approval, and result shown.task docs)task site:build)task api:check)task api:update+engine/CHANGELOG.mdHarness 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
plainPKCE), and each minted defect.Mutation checks: removing AS-1's PKCE check, dropping
prompt=consentfrom the upstream request, or signing Bob in as Alice in the end-to-end test each fails a test.Changes
internal/testutil/identityharness/harness.goHarness,Options, defaults, CA helpers, one-shot faultsinternal/testutil/identityharness/idp.gointernal/testutil/identityharness/as1.goMintAccessTokeninternal/testutil/identityharness/signin.goSignInandRefreshinternal/testutil/identityharness/oauth.gointernal/testutil/identityharness/harness_test.gocmd/mecak8s/identity_broker_harness_test.goUser-facing change
None.
Special notes for reviewers
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).internal/testutil; only tests import it. It usesgolang-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.