Repository navigation
feat(identitybroker): limit each agent's gateway calls to its definition's tools - #2937
Conversation
The broker now records runs and delegations per broker session and applies design step (6) checks 4 and 5 to every AuthorizeCall: - ReportDelegation records a delegation from a run of one agent to a new run of another, with the design's six checks in order. An unseen delegating run is recorded as a root run of a root instance. - A call's run must be bound to the acting agent and act under the delegation it names; a new run naming no delegation needs a root instance. The reported run owner must equal the run's owner and the grant's owner, in one function a later membership check can replace. - A first call's run is recorded only once both checks pass. - The grant records its user, and the ID-JAG record carries the delegation, run owner, and grant user. mecak8s reports the runs it already knows: - Every server run entry puts the session's run ID and owner on the engine context; a RunTeam call mints its own run of the root's main agent, owned by the root's owner. - Each helper registration and resume reports a new delegation from its parent agent's current run and keeps it with the helper's credential. - A gateway call names the main agent's run, or the helper's delegated run, and is refused when there is none, replacing the run serial stand-in. - After a broker session reopens, every held delegation is reported again in its original order. Part of #2554. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… none Review follow-ups: - A helper resumed by a parent with no run no longer keeps acting in its earlier run; its gateway calls fail closed, as documented. - Tests pin that one delegation starts one run, that a resume with no run holds no delegation, and that rootedRunContext carries the session's run or masks the caller's. - Shortcut notes name #2805 for runs across replicas; delegations are described as kept until the root is dropped, since the design gives them no end. - The design's delegation report lists the refusal of a receiving run that is already recorded; Service and Core docs cover the delegated run a call can record and another workload's delegation report. - Delegation IDs use rand.Text, as the broker's own IDs do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecks A parallel branch, a Team tool member, a member of a team the API creates and runs, and a subagent resumed after its root's broker session reopened each call the gateway through mecak8s's startup, the real AS-1 and AS-2, and the embedded vMCP. A helper is not a root instance, so each completed call proves mecak8s reported the delegation that started its run and the broker accepted it. Skipping the report fails all four. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Once a session's run and delegation records reach their cap, a delegated run whose record was forgotten is recorded again from its delegation, for the delegation's receiving agent only, and a run whose own delegation was forgotten can no longer delegate. Both refusals were reachable only after forgetting, so no test failed when either was removed. The credential holder's list of delegations to report again forgets its oldest entry at its cap while each helper keeps its current delegation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- One deniedError helper for credential, run and delegation refusals. - Name the run owner shortcut where the server reads the session owner at each run entry (removed by #2569), and cite the run-owner draft by its full path. - startTeamRootRun says that it starts the RunTeam run, not only opens the root's broker session. - Tests: a shared createSession helper, sync.OnceValues for the late-loading mock script, and slices.Repeat for its padding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion's tools The broker now checks design step (6) check 7: each gateway call's exact server and tool must be inside the acting agent's effective ceiling. - The definition loader resolves each definition's ceiling against the servers the gateway routes. A server the definition's mcpServers references is granted whole, minus the tools its disallowedTools names; tools selects no MCP tools, as in the harness. Built-ins name every routed server. No tool list is needed, since listing tools needs a user's grant. - Registration stores each instance's effective ceiling: its definition's, narrowed by its parent's effective ceiling, computed once and never widened. - Check 7 runs after the gateway route check and refuses with PERMISSION_DENIED, recording the ceiling it checked. A call whose tool is not named for its server is now an invalid request, and gateway server names are limited to letters, digits, and single underscores, so "<server>.<tool>" and "mcp__<server>__<tool>" each name one server. - A helper that runs a named definition, as a subagent or team member, now gets the session's gateway tools for the servers its definition references, minus excluded tools, removing #2555's shortcut. A test checks the harness and the broker resolve each definition the same way. Records the resolution rule in mcp-authorization.md and updates the identity broker row in the mecak8s operator docs. Closes #2842. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ChrisJBurns
left a comment
There was a problem hiding this comment.
Review against the agent identity design and #2842 / #2851. This lists only issues, gaps, and questions. Nothing here blocks the PR, and none of the correctness items is an authorization bypass; they all fail closed. Please address each one or reply with your reasoning.
Design and ticket gaps
- The ceiling resolves against the wrong server list (major). The #2842 decision, and this PR's edit to
mcp-authorization.md("Definition-derived ceiling"), say the loader resolves against the operator's MCP configuration (mcp.servers). The code resolves againstcfg.IdentityBrokerGatewayServers(internal/app/identitybroker.go:489), which is a test seam that production leaves nil (internal/app/build.go:996). Either change the code, or say in the doc that this list stands in until #2533. - The harness and the broker read different server lists (major).
defGatewayToolsfilters the MCP broker's routed backends (cfg.helperTools); the broker uses the list in point 1. Nothing keeps the two equal.TestDefGatewayToolsAgreesWithTheBrokersCeilinggives both sides the same list, so it can't catch a mismatch. - Resolution inputs aren't kept, so a restart can widen a ceiling (major). The design requires keeping the resolution inputs, and says restoration never recomputes or widens a ceiling (the "Process restart" row in the
agent-definitions.mdcontinuity table, andimplementation.md"Cedar authorization…" bullet 3). The gateway server set is a hidden input: it isn't inDefinitionRef, the revision, or the provenance. Broker state is in memory, so after a restart the instance registers again and its ceiling is recomputed (agents.go:156). A longer server list then gives more authority under the same definition revision. "Never recomputed or widened" holds only within one process, and no shortcut marker records the gap. - #2842's "Done when" items aren't met (major):
- The cross-check against the harness's delegated-authority intersection (
implementation.md"Cedar authorization…" bullet 3). The new test compares one definition's resolution only. It never compares parent-narrowed effective ceilings with what the harness gives a child. Built-ins aren't compared either:builtinCeiling(loader.go:357) versusreadOnlyExplorerCatalog/writableExplorerCatalog. - Backfill. The "Authority work switched on" row and #2842 require live instances to be backfilled and marked. The PR argues none exist, but changes neither the row nor the ticket. Please record the exception, e.g. "not applicable while broker state is in memory; revisit with #2559".
- The cross-check against the harness's delegated-authority intersection (
- The #2842 decision has no sign-off (question). The decision on #2842 is a proposed comment, and the issue asks for review by the design's author. No sign-off is recorded, but the PR treats it as decided.
- The decision text and the code disagree (minor):
- The decision says nothing has to parse
mcp__<server>__<tool>, butresolveCeilingparses it (loader.go:383), and the server-name restriction exists because of that. - The sentence before the new paragraph in
mcp-authorization.mdstill says "permitted server/tool pairs". So doesimplementation.md"Work breakdown" (~line 367). Granting a whole server, including tools it adds later, is a widening that the pair wording doesn't allow. Reconcile both places.
- The decision says nothing has to parse
- Built-ins get every routed server (minor).
builtinCeilingignores itsdef, but #2842's scope says built-ins get their limit from their built-in fields. If a built-in later setsmcpServersordisallowedTools, the broker ignores them without saying so. - Tool naming is now part of the broker's contract (minor).
ValidatereturnsINVALID_ARGUMENTfor anytools/calltool not named<server>.<tool>(service.go:474). That ties broker validation to the embedded vMCP's naming.Gateway.Routereturns(server, tool)in no fixed format, so an external gateway (#2812) that names tools differently would fail every call. The step (6) failure table incredentials-and-lifecycle.mdhas no row for thisINVALID_ARGUMENT. - Listings aren't limited in practice (minor). Nothing in production reaches the
tools/listbranch of check 7 (ceiling.go:132):ListToolsuses the session's credential (mcpbroker/gateway.go:72) and never callsAuthorizeCall. Excluded tool names and descriptions are still listed. The design's "Tool discovery" paragraph wasn't updated either way. - Ticket accuracy (minor):
- The shortcut at
internal/app/agentdefs.go:604says it's "removed by #2548", but #2548's "Removes shortcut" list doesn't include it. Add it there. - "Cedar replaces only
checkCeiling's body" understates #2849. Cedar also needs per-definition policy generation and a policy-based intersection, so the exportedCeilingtype,intersect, andDefinitionRecord.Ceilingchange too.
- The shortcut at
- Branch hygiene (minor):
- #2939 is now merged. This branch still has the
defDisallowsToolloop that #2939 removed, next to the newregisterHelperToolscall, so a rebase will conflict or duplicate it. The PR body still describes #2939 as pending. - "Closes #2842" doesn't link while the base is
feat/run-delegations(closingIssuesReferencesis empty). Check that the link appears after retargeting tomain.
- #2939 is now merged. This branch still has the
- Operator docs (minor). In
user-docs/operating/mecak8s/identity-and-client-access.md, theidentityBroker.enabledrow has two problems:- "the tools of each server its
mcpServerslists" is inaccurate. Only a server named by reference and routed by the gateway counts; inline entries grant nothing. The doc doesn't give the excluded-tool formmcp__<server>__<tool>, or say thattoolsselects no MCP tools (tools: [Read]plusmcpServers: [github]still gets every GitHub tool). - It describes a refusal that production can't reach yet, because no gateway is configured (#2533). Add a qualifier or link.
- "the tools of each server its
Correctness
- The harness and the broker name servers differently (minor).
GatewayServer()returnsroute.backend(internal/adapter/mcpbroker/runtime.go:660), while check 7 uses the server nameGateway.Route()returns. These agree only becauseembeddedGateway.Routepasses the backend name through unchanged. An external gateway that maps names differently would split the harness from the broker without any error. The doc comment onGatewayServer()is wrong as written. - Check 7 depends on the reported
DefinitionRef(minor). Because of the #2551 shortcut, a root can register assystem/mainand get every server. A child that registers as a built-in gets its parent's whole ceiling instead of its own narrower one. Please note this in the check 7 shortcut comment. - Whitespace in excluded tool names (minor).
NewCeilingtrims whitespace around excluded tool names (ceiling.go:36), butdefDisallowsToolmatches exactly. Formcp__github__ merge, the broker excludes the tool and the harness doesn't. The broker is the stricter side, but the agreement test doesn't cover it. - The ceiling string is ambiguous (minor).
Ceiling.String(ceiling.go:109) escapes nothing. Exclusions come from definition files, so a,, a;, or " except " makes the canonical form recorded inDecisionRecord.Ceilingambiguous. - Nits:
isGatewayServerName's doc says the rule rules out prefix clashes, but leading and trailing underscores still allow them:gitandgit_both producemcp__git___x.- The full ceiling string goes into every decision record and every refusal sent to the caller. It has no size limit, and it shows the child its parent's exclusion list.
effectiveCeilingLockedruns on every re-registration, and the result is discarded (agents.go:148).
Missing tests
- No end-to-end test reaches a check 7 refusal. The harness drops the tool first, so #2851's "refused before any token is issued" is proven only by core unit tests.
- The agreement test (
internal/app/defgatewaytools_test.go:83-91) re-implements the broker's allow logic instead of callingCeiling.allows/checkCeiling. Both sides also go throughagentdef.Parse, despite the comment about "their own parsers". - No cases for:
- tools containing
.or__, throughValidate, the ceiling, and the loader; - mixed-case names;
- an integration case where the child's definition grants a server its parent lacks (only the property test covers this).
- tools containing
- A gateway call is refused unless the gateway routes it to the tool's own backend, so the harness and the broker always mean the same server. - Ceilings match tool names exactly, as the harness does; records quote names holding a separator; a refusal no longer shows the ceiling. - A built-in definition that sets tool fields fails to load instead of having them ignored. - An effective ceiling is computed only for a new instance. - Shortcut markers for restart recomputation (#2563) and reported definitions (#2551). - The agreement test uses the broker's own check and covers built-ins and the main agent as parent; new cases for dotted, mixed-case, and ambiguous names, and a child under an empty ceiling. - Docs: the server list the limit resolves against until #2533, whole-server entries, no backfill while state is in memory, the tool-naming refusal, unlimited listings until #2729, and the operator row's accuracy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A helper that moved to its root's reopened broker session lazily, after the reopen's own move failed, had no delegation reported there, so its gateway calls were refused until it was resumed. The credential holder now reports a helper's current delegation into each broker session it moves to, after the delegations its delegating run descends from, before the move is stored, so a failed report leaves the helper to move again. A delegation set while a move is in flight is reported to the new session too. The reopen no longer re-reports the whole delegation history. The broker also: - checks the owner of a delegating root run it has not seen against the session's owner, so one inconsistent report cannot fix the wrong owner; - rebuilds a delegating run whose record was forgotten at the cap from its kept delegation, as AuthorizeCall does. The design defines the open delegations a reopen reports, and the in-memory record cap is marked as a shortcut. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main now refuses the identity broker with a workspace on the process's filesystem (#2875), so the delegation tests run file-less. Parallel branches and API-created teams need a workspace, which the broker then gets only through Kubernetes execution, so their end-to-end cases are dropped; they report delegations through the same path the remaining tests drive. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in main, whose identity broker refuses a workspace on the process's filesystem (#2875). Named definitions run only in sessions with a workspace, so the named-subagent end-to-end test runs on the Redis filesystem, and the named team member, which needs teams and so Kubernetes execution, is tested through the member factory instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A team member without a filesystem skipped its agent definition entirely, so it got every server-global MCP tool and every gateway tool, including ones its definition excludes, and registered with the identity broker as the built-in member, so the broker allowed them too. With the broker on, file-less is the only setup outside Kubernetes execution (#2875). A file-less member that names a definition now gets the file-less core tools its definition does not exclude, its definition's own MCP servers instead of the server-global ones and CallMcpWithQuery, and its servers' gateway tools, and reports the definition, so the broker checks the same limit. The rest of the definition stays file-oriented and is not applied. The named team member end-to-end test runs again, file-less. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, this was thorough. Point by point; fixes are in 29b94ce, plus aa312f5 for a related gap described at the end. Design and ticket gaps
Correctness
Missing tests
Also changed since
|
# Conflicts: # cmd/mecak8s/identity_broker_delegations_test.go # cmd/mecak8s/identity_broker_harness_test.go # cmd/mecak8s/identity_broker_helpers_test.go # internal/identitybroker/authorize.go # internal/identitybroker/service.go
…a reopened session Co-Authored-By: mecatl <[email protected]>
Co-Authored-By: mecatl <[email protected]>
… tool pairs Co-Authored-By: mecatl <[email protected]>
retainHarnessGeneration returns a nil close when the harness instructions are not generation-backed. The file-less member path called it unguarded, so closing a defined member with its own MCP server panicked, and a failed provider lookup did the same. Guard both, as the file-ful path does. Co-Authored-By: mecatl <[email protected]>
…member The file-less defined member catalog only filtered core tools by the definition's disallowedTools, so a definition limited to a few tools still got WebFetch, WebSearch and every memory tool. Scope the file-less core and memory tools through scopedToolNamesMode, as the member with a filesystem does. MCP and gateway tools keep following the definition's servers and exclusions. Co-Authored-By: mecatl <[email protected]>
Load a definition from files through the real broker path, with the calendar server and one excluded tool, and register a helper running it. Its call to the excluded tool and to a server it does not reference are refused before any ID-JAG exchange, and its call to the server's other tool passes the ceiling check. Co-Authored-By: mecatl <[email protected]>
- Log filesystem tools named in a definition's `tools` at Debug instead of Warn "unknown tool": they do not exist without a filesystem. Genuinely unknown names still warn. Add the member name to the log, as the file-ful path does. - Mention the `tools` allowlist in the buildMemberEngine comments. - Reword the no-filesystem docs so disallowedTools is not described as limited to core and memory tools, and name the tools `tools` limits. - Drop an always-true assertion and fix a stale definition description in the file-less member tests. Co-Authored-By: mecatl <[email protected]>
jhrozek
left a comment
There was a problem hiding this comment.
Leaving this as a comment for now. The follow-ups are in #2956, which is stacked on this branch. Please merge it into feat/agent-tool-limit (or cherry-pick it) before this lands, because it fixes a panic this PR adds; I'll approve once it's in. I found no way for an agent to get a call outside its ceiling: the <server>.<tool> split, check order, the empty ceiling, intersection with the parent, and keeping the ceiling across re-registration all hold.
In #2956
- Panic when a file-less team member closes.
retainHarnessGenerationreturns a nil close function when the harness instructions aren't generation-backed. The new close atbuild.go:8562callsgenerationClose()without a check, so a file-less member whose definition has inline MCP servers panics on teardown. The file-ful path checks for nil at:8774. - The
toolsallowlist on file-less members.newNoFSDefinedMemberCatalogapplied onlydisallowedTools, so a definition withtools: [Read]still gotWebFetch,WebSearch, and the memory tools. Its comment said the definition narrows the member "the same way either way". #2956 scopes core tools withscopedToolNamesMode, as the file-ful path does. Drop that commit if you'd rather keep that narrowing for later. - Check 7 had no test with real definitions. The end-to-end tests never reach the refusal, because the harness hides the excluded tool first, so removing check 7 broke no test. #2956 adds an
internal/apptest that loads a definition from disk and callsAuthorizeCall. It also adds a test that the ceiling survives re-registration in a reopened broker session. - Smaller items.
Ceiling.String()is now computed once instead of on every call.mcp-authorization.md:9no longer says "and their tools". Thetools.mdsentence now says what each field does.
For you to change: the PR description's API compatibility section
"No deployment sees a difference today" isn't quite right. File-less team members that name a definition change whether the broker is on or off: they lose the server-wide MCP tools and CallMcpWithQuery, and they now connect their definition's inline servers. With the broker on, a member whose definition the broker didn't load (one not from --agents-dir) is now refused at registration and doesn't start; before, it ran as system/member. Nothing changes on the wire, so "no wire change" stands, but please name these two behavior changes there and in the release notes.
Not blocking
- A
tools/listthroughAuthorizeCallhas no test; onlycheckCeilingis tested directly. TestNewRefusesAnInvalidGatewaycovers dots,__, and-, but not non-ASCII letters or spaces.
…etter Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. #2956 is in (fast-forwarded, so its commits are here as you wrote them). I checked each fix:
The PR description: the API compatibility section now lists the behavior changes for the release notes:
Not blocking: both added. |
…AuthorizeCall Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes #2842. Part of #2851.
With the identity broker on, each gateway call must now be inside the acting agent's tool limit: its definition's, narrowed by the limit of the agent that started it. Before this, the broker accepted any tool. It implements the decision posted on #2842: resolve each definition's limit against the gateway's servers, with no tool lists.
What changes
Identity broker (
internal/identitybroker)Ceiling, a new value type: the servers an agent may call, each with the tools on it the agent may not. The zero value allows nothing.DefinitionRecordcarries one.mcpServersreferences is granted whole, minus the toolsdisallowedToolsnames asmcp__<server>__<tool>;toolsselects no MCP tools in the harness, so it grants none;AuthorizeCallrefuses a call outside the effective ceiling withPERMISSION_DENIED. It runs after the gateway route check (check 6) and before any ID-JAG exchange. Each decision record names the ceiling it checked. A listing is allowed for any server the ceiling grants.tools/callmust name its tool<server>.<tool>; any other name is nowINVALID_ARGUMENT, so check 7 always sees a tool of the call's server.mecak8s
toolsanddisallowedToolsallow, its definition's own MCP servers instead of the server-global ones andCallMcpWithQuery, and its servers' gateway tools. It also reports the definition, so the broker applies the same limit. Before, it skipped the definition and registered assystem/member.Docs
mcp-authorization.md("Definition-derived ceiling") records the resolution rule.identityBroker.enabledrow in the mecak8s operator docs now describes the named-helper behavior and the limit.Decisions to review
checkCeiling's body. Splitting<server>.<tool>moved into request validation.defGatewayTools) rather than reading the broker's record, marked as a shortcut removed by Sessions run and register the exact definition revision #2548. A test runs one table of definitions through both and fails if they disagree.Shortcuts
Found, not in this PR
Subagenttool, so its main agent can't call the gateway or start helpers. That already happens before this PR and isn't the helper shortcut Per-agent tool limit, checked by the broker #2842 removes. Filed as Sessions started with a named agent definition get their servers' gateway tools #2938.disallowedTools. Fixed separately in fix(app): keep a team member's MCP tools within its definition's exclusions #2939, now merged and included here.API compatibility
Assessment: no wire change. No proto, gRPC, or HTTP surface changes.
Ceiling,DefinitionRecord.Ceiling,CeilingServer,DecisionRecord.Ceiling, and the stricterAuthorizeCallRequest.Validateare in-process Go API in internal packages. #2559 (broker over gRPC) hasn't landed.Behavior changes (for the release notes):
CallMcpWithQuery, connect the definition's own MCP servers, including inline ones, and drop the core and memory tools itstoolslist leaves out or itsdisallowedToolsnames.system/member. A member whose definition the broker didn't load (one not from--agents-dir) is refused at registration and doesn't start; before, it ran.No major bump, no feature identifier, no approval needed.
Testing
Broker:
ceiling_internal_test.go:ceiling_test.go, throughAuthorizeCall:INVALID_ARGUMENT.loader_test.go: resolution against the routed servers, including an inline server, an unrouted reference,toolsnaming a routed server's tool, exclusions, built-ins, and no servers.Harness and broker agree:
internal/appTestDefGatewayToolsAgreesWithTheBrokersCeilingruns one table of definitions through both parsers and both rules.End to end (
cmd/mecak8s, real AS-1, AS-2, and the embedded vMCP):internal/app: a named team member with a filesystem, through the real member factory, gets its servers' gateway tools and never runs the excluded one; a file-less named member keeps to its definition's tools and reports the definition, while a generic one keeps the whole file-less surface. From fix(app): follow-ups to the agent tool limit #2956: a file-less member with atoolslist keeps only those core tools, closes without a harness generation, and a definition loaded from disk has its excluded tool refused atAuthorizeCall;ceiling_test.gokeeps the ceiling when agents register again in a reopened broker session.Mutation checks. Each was applied, a test failed, and the code was restored:
Dropping the harness catalog's exclusion alone is not caught. The engine's capability set excludes the tool too, so that mutant behaves the same.
Gates:
task lintandtask docspass.go test -race:internal/identitybroker/...,internal/adapter/mcpbroker,internal/adapter/server,internal/agentcredential/...,cmd/mecak8s, andinternal/app.Real use, local: I rebuilt
mecak8sand ran it with the broker on. A subagent and a Team-tool team, whose second member runs a named definition, registered and reported their delegations with no broker warnings. The binary has no flag that turns on a gateway, so the gateway path is proven by the end-to-end tests above.Panel review (spec, standards, tests, security, architecture, duplication, reuse) found no blockers. I fixed:
tools, and team-exclusion tests;<server>.<tool>inside the policy check;After review
The review's findings and my answers are in the review reply. Two agents also checked each finding against the design independently. Changes from it:
Sign-off on the resolution rule is requested on #2842.
🤖 Generated with Claude Code