Skip to content

feat(identitybroker): fix the AuthorizeCall shape and run the checks before a grant - #2785

Merged
ChrisJBurns merged 1 commit into
mainfrom
split/2535-2-contract
Nov 16, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
split/2535-2-contract

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Part 2 of 4 for #2535. Stack: #2784 → this PR → #2786 → #2783.

The AuthorizeCall contract and the checks before a grant (design step (6), as amended by #2779).

  • Request: method (tools/call or tools/list), server, tool as the gateway routes it, argument hash (tool calls only), operation, run, run owner, delegation, rejected attempt. Target is renamed Server. Response: gateway token, expiry, attempt ID.
  • Checks in design order, with refusals recorded: workload, request, session (closing reason), no_grant, agent credential, route (check 6). Calls that pass every check are still refused here; feat(identitybroker): authorize gateway calls with a per-call ID-JAG and gateway token #2786 adds steps (7) and (8).
  • Recorder port (MemoryRecorder), the rejected-attempt ledger, no_grant and consent_required reasons, Gateway{Servers}, conformance cases.

Shortcuts (marked in code): checks 4, 5 (#2557) and 7 (authority work) accept their inputs; check 6 matches the server, not the tool's route (#2538); one gateway (#2538); records and retry state in memory (#2541, #2563); an unaccepted refusal record is not reported elsewhere (#2541).

API compatibility

No wire change: AuthorizeCall is an in-process Go contract until #2560. All Go callers are in this repository and updated.

…before a grant

AuthorizeCallRequest carries the run, method, server, tool, arguments hash,
and rejected attempt; Authorization adds the expiry and attempt ID. The
broker checks the session, a rejection report, the grant (no_grant), the
credential, and the gateway's servers in design order, recording each
refusal; a call passing every check is still denied until steps (7) and (8).

Co-authored-by: Mecatl <noreply@mecatl.dev>
@ChrisJBurns
ChrisJBurns force-pushed the split/2535-2-contract branch from e903f3e to a9d9519 Compare November 16, 2026 11:08

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the second commit (e903f3e09e) only; the first one is #2784, already merged.

The request and response fields and the check order match credentials-and-lifecycle.md as amended in #2779. Every path ends in a refusal, and a failed record can't turn a refusal into an allow. The shortcuts are marked in the code and match the PR description. I also read the same code on #2786: it consumes the retry allowance under the lock, checks the session again before each external step, and saves the records before it returns a token. So the parts this PR leaves unwired are handled there.

Please rebase onto main before merging. The branch still has the design text from before #2779. For example, audit.md:45 on this branch says "The broker does not inspect V", while the GatewayToken reference in DecisionRecord follows the amended text on main. Anyone who checks the code against this branch's copy of the docs will see contradictions that aren't real.

Three inline comments. Only the first one would change something that's hard to change later.

At time.Time
SessionID string
Workload Workload
// Owner is the broker session's verified owner, or the owner mecak8s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Owner holds the verified owner when the session has one, and otherwise the owner mecak8s reported. Nothing in the record says which one it is.

This matters for refusals recorded before the grant check: a closed session, an unknown rejected attempt, and no_grant itself. For example, a session opened without the user's access token reports alice. A call in it gets no_grant, and the record says Owner: alice, exactly like a record from a session where the broker verified alice.

audit.md:39 (on main) requires each subject to be marked verified or reported:<component>. Once #2541 turns these records into audit events, it can't recover the difference. Could you add OwnerVerified bool, set from s.verifiedOwner != nil in decisionRecord? It's one field now. After #2541 it would be a change to the record format.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added DecisionRecord.OwnerVerified (set from s.verifiedOwner != nil) in #2794, tested on a verified and a tokenless session.

}
}

func TestAuthorizeCallUnroutedServerIsDenied(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test pins the order of the credential check and the server check. The invalid-credential tests all use a server the gateway serves, and this test uses a valid credential. If the two checks in authorize.go were swapped, every test would still pass, and a caller with an expired SVID would get denied ("no gateway routes") instead of svid_expired.

Suggested test: an expired credential and an unrouted server together. Expect CodeUnauthenticated with ReasonSVIDExpired, and a decision record with no agent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #2794: 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.

// Tool is the exact tool name the call sends as params.name, such as
// "github.pull_request_read". Set for tools/call only.
Tool string
// ArgumentsSHA256 is the SHA-256 of the call's arguments, 64 lowercase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could this comment point to the definition in credentials-and-lifecycle.md (step 8, "The argument hash")? The design says it's the SHA-256 of the arguments in RFC 8785 (JCS) form, with {} when there are no arguments. Whoever writes the MCP client side will start from this field, and "the SHA-256 of the call's arguments" could be read as a hash of the raw bytes. That would stop matching the gateway, because the client decodes the arguments and encodes them again before sending.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #2794: the comment now points at step (8), "The argument hash" (RFC 8785 serialization of params.arguments as sent, or {}).

ChrisJBurns added a commit that referenced this pull request Nov 16, 2026
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>
@ChrisJBurns

Copy link
Copy Markdown
Contributor Author

Thanks @jhrozek. All three inline comments are fixed in a separate follow-up PR, #2794, which sits on top of the stack (#2783), so this PR merges as you approved it:

  • Owner verified or reported: DecisionRecord.OwnerVerified, set from s.verifiedOwner != nil, tested on a verified and a tokenless session.
  • Check order: an expired credential for an unrouted server is refused as svid_expired with a record naming no agent; swapping checks 3 and 6 fails the test.
  • Argument hash doc: ArgumentsSHA256 now points at step (8), "The argument hash" (RFC 8785 serialization of params.arguments as sent, or {}).

The rebase you asked for is done: the stack was rebased onto main after #2784 merged, so this branch carries the design text as amended by #2779.

Your two comments on #2784 (fencing the AS-2 trust seam, and the duplicated trusting-AS-2 setup) are addressed in the same follow-up, #2794.

@ChrisJBurns
ChrisJBurns merged commit fe6d2a4 into main Nov 16, 2026
50 of 51 checks passed
@ChrisJBurns
ChrisJBurns deleted the split/2535-2-contract branch November 16, 2026 11:58
ChrisJBurns added a commit that referenced this pull request Nov 16, 2026
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>
ChrisJBurns added a commit that referenced this pull request Nov 16, 2026
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>
ChrisJBurns added a commit that referenced this pull request Nov 16, 2026
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>
@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