Skip to content

refactor(mcpbroker): fence the AS-2 trust test seam and share its defaults - #2794

Merged
ChrisJBurns merged 7 commits into
mainfrom
fix/2535-review-followups
Nov 16, 2026
Merged

ChrisJBurns merged 7 commits into
mainfrom
fix/2535-review-followups

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to jhrozek's review comments on #2784, #2785, and #2786, on top of the last PR in the #2535 stack (#2783).

AS-2 trust reachable from production code (comment)

  • Outside the adapter, Go's internal-package rule already stops code from naming as2trust.Trust, and depguard keeps production code from importing mcpbrokertest. The gap was other production files inside the adapter.
  • New depguard rule internal-adapter-mcpbroker-as2trust-importers: outside tests, only toolhive_construction.go and mcpbrokertest may import as2trust. Go imports are per file, so no other production file can build a trusting AS2Trust. Verified by planting NewAS2Trust(as2trust.Trust{...}) in a production file of the adapter: depguard refuses it.
  • ToolHiveConfig.AS2Trust now says it is removed with Configure the embedded gateway's authorization server as AS-2 #2533 (the shortcut is marked on app.Config.IdentityBrokerAS2Trust).

Duplicated trusting-AS-2 setup (comment)

  • as2_test.go is package mcpbroker, and mcpbrokertest imports mcpbroker, so those tests can't call StartAS2 (import cycle). Moving them to an external test package would need shims for about ten unexported helpers.
  • Instead, both setups now build the trust through as2trust.Trust.WithDefaults (one default for MaxAssertionAge, one copy of Subjects), and newTrustingAS2 documents that it is the in-package counterpart of StartAS2 and why.

#2785: decision record owner (comment)

  • DecisionRecord.OwnerVerified says whether Owner is the owner the broker verified at session open or only what mecak8s reported, so Broker records of who acted #2541 can mark audit subjects verified or reported:<component> (audit.md). Tested on a verified session and on a tokenless one.

#2785: check order (comment)

  • New case: an expired credential for an unrouted server is refused as svid_expired with a record naming no agent. Swapping checks 3 and 6 fails it.

#2785: argument hash doc (comment)

  • ArgumentsSHA256 now points at step (8), "The argument hash": SHA-256 of the RFC 8785 serialization of params.arguments as sent (or {}), not of the raw bytes.

#2786: retry-allowance assertions (comment)

  • Each row of TestAuthorizeCallRetryAllowances now also checks: one decision whose outcome, code and reason match the returned error; one ID-JAG record per ID-JAG AS-1 issued; no gateway token on failure; and that the try after a revoked grant presents the session's new grant (reverting the re-read of the grant fails it).

#2786: dropped error_uri (comment)

#2786: CloseSession comment (review body)

  • Now says a call in progress is refused with the closing reason at its next session check and gets no token, even if AS-2 has issued one.

The #2785 review also asked for a rebase onto main for the amended design text; the stack was rebased onto main after #2784 merged.

#2792 folded in (Jakub Hrozek's fix-ups; authorship kept, (cherry picked from …) in each message)

  • 36dc40138: respect a gateway token's exp when it has no jti (readJWTExp).
  • bf34f9cb4: the rejected-token retry test covers every field that binds an attempt.
  • 3ceed66ed: the attempt-ledger test covers each call-key field on its own, and the ExpiresAt comment describes the broker's use-before deadline.

Each of #2792's three original patches is present in this branch (git apply --check -R succeeds), and their tests pass.

Testing

go build ./...; go test for mcpbroker, identitybroker, identityharness, mecak8s, and the app identity tests; root golangci-lint 0 issues.

API compatibility

No wire change. DecisionRecord gains OwnerVerified; it is an in-process type with no consumer outside the broker until #2541.

@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from 4cec7cd to c135ad2 Compare November 16, 2026 11:12
@ChrisJBurns
ChrisJBurns force-pushed the fix/2535-review-followups branch from b37200e to 8ee1f7b Compare November 16, 2026 11:12
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from c135ad2 to 04257a1 Compare November 16, 2026 12:01
@ChrisJBurns
ChrisJBurns force-pushed the fix/2535-review-followups branch from 9eee8c0 to 0251594 Compare November 16, 2026 12:04
@ChrisJBurns
ChrisJBurns force-pushed the feat/identitybroker-per-call-grant branch from 04257a1 to b630101 Compare November 16, 2026 12:28
@ChrisJBurns
ChrisJBurns force-pushed the fix/2535-review-followups branch from 0251594 to 36793ca Compare November 16, 2026 12:29
Base automatically changed from feat/identitybroker-per-call-grant to main November 16, 2026 13:00
ChrisJBurns and others added 7 commits November 16, 2026 13:00
A depguard rule lets only toolhive_construction.go and mcpbrokertest import
the as2trust package outside tests, so no other production code in the
adapter can build a trusting AS2Trust. Record that the field goes with
#2533.

Co-authored-by: Mecatl <noreply@mecatl.dev>
mcpbrokertest.StartAS2 and the adapter's own newTrustingAS2 now build the
trust through as2trust.Trust.WithDefaults. The adapter's tests cannot call
StartAS2 (mcpbrokertest imports the adapter), so newTrustingAS2 says so.

Co-authored-by: Mecatl <noreply@mecatl.dev>
Address review comments on #2785:
- DecisionRecord.OwnerVerified says whether Owner is the owner the broker
  verified at session open or only the one mecak8s reported, as audit
  subjects must say (audit.md).
- Pin that check 3 comes before check 6: an expired credential for an
  unrouted server is refused as svid_expired.
- ArgumentsSHA256 points at the design's definition of the argument hash.

Co-authored-by: Mecatl <noreply@mecatl.dev>
…lowances

Address review comments on #2786:
- The retry-allowance table now checks one decision matching the returned
  error, one ID-JAG record per issued ID-JAG, no token on failure, and that
  the try after a revoked grant presents the session's new grant.
- Mark the dropped AS-2 error_uri as a shortcut removed by #2735.
- CloseSession's comment says a call in progress is refused at its next
  session check and gets no token.

Co-authored-by: Mecatl <noreply@mecatl.dev>
gatewayTokenExpiry read the gateway token's exp through readJWTRef,
which gives up when the token has no jti, so ExpiresAt could outlast the
token. readJWTExp reads exp on its own.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit f437b4e)
Co-authored-by: Mecatl <noreply@mecatl.dev>
The rejected-token retry test changed only the tool; it now checks a
report that differs in each field of the attempt key, including a second
agent in the same session.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit 385ef77)
Co-authored-by: Mecatl <noreply@mecatl.dev>
…be ExpiresAt

The ledger test now checks each call-key field on its own, and the
ExpiresAt comment says it is the broker's use-before deadline, not the
token's own expiry.

Originally #2792, by Jakub Hrozek; folded into the #2535 follow-up after

(cherry picked from commit b41ccf2)
Co-authored-by: Mecatl <noreply@mecatl.dev>
@ChrisJBurns
ChrisJBurns force-pushed the fix/2535-review-followups branch from d8977f6 to 3ceed66 Compare November 16, 2026 13:04
@ChrisJBurns
ChrisJBurns enabled auto-merge (squash) November 16, 2026 13:10
@ChrisJBurns
ChrisJBurns merged commit 573e557 into main Nov 16, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the fix/2535-review-followups branch November 16, 2026 13:26
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 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.

2 participants