Repository navigation
fix(mcp): accept the Toolbox dispatcher shim as Crew's own control plane - #13288
bolichen97 wants to merge 1 commit into
Conversation
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the What this change shipsInventory (7 items) — 7 justifiedIntent: FIX — restore Crew's own tools (identity attestation) to agents whose spec names the server by its bare Toolbox command, denied because realpath cannot see through a dispatcher.
Provenance checked: the quoted deny log matches [FIRST-PRINCIPLES-REVIEWED] da0dd63 |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Have one of the two 0.7.0.8 reporters confirm live that Crew tools attest after upgrade — the end-to-end transition was never observed, only the gate. [DESIGN-REVIEWED] da0dd63 |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
dcc4f94 to
5b0bb1d
Compare
|
self-added: yes
|
|
self-added: yes
|
|
|
|
|
Both identity gates -- gatewayd._spawns_own_control_plane (pooled token) and acp.session_mcp.kiro_control_plane_servers (identity element) -- compared the spawn command against agent.managed_mcp_spec_entry as one file: realpath equality in the gateway, string equality in the session projection. A Toolbox install fails both. The managed entry is the versioned ~/.toolbox/tools/kirocrew/<ver>/bin/kirocrew; a spec that names the server by its bare "kirocrew" (every externally managed agent spec does) resolves on PATH to ~/.local/bin/kirocrew -> ~/.toolbox/bin/kirocrew -> one shared toolbox-exec dispatcher, whose realpath is never that binary. So no identity element, no token, and every kirocrew-core / -cron / -dashboard call answered identity_unattested while the servers mounted and listed their tools. Reported twice on 0.7.0.8; ~100 specs across teams carry that spelling. A dispatcher is not a symlink, so realpath cannot see through it. The new leaf managed_launcher reads the one index the real dispatcher reads (measured against toolbox-exec 1.1.9714.0 under an isolated BUILDER_TOOLBOX_HOME: it keys on argv[0]'s basename, reads <root>/tools/globalInfo.json Commands.<name>.Path and execs it verbatim) without executing anything, and same_managed_launcher() holds when the spawn is the managed file by realpath OR the trusted root's dispatcher whose index names that file. Anchored, not widened: the root is the gateway's own $BUILDER_TOOLBOX_HOME or ~/.toolbox, never the command's location, so a tree merely shaped like Toolbox elsewhere stays a foreign binary; the managed entry must live under that root; an index naming another file denies; and a child environment re-rooting the dispatcher denies. The index sits in the same user-owned tree as the managed binary, so trusting it concedes no capability realpath equality did not. The gateway passes the dispatched launcher (not the dispatcher) to the import-shadow check. The session gate resolves a bare command on env.mcp_search_path -- the composition the rewriter and the MCP probe use -- and the element it emits carries the managed command/args, so kiro-cli launches the file that was judged rather than re-resolving a bare word against its own PATH.
5b0bb1d to
da0dd63
Compare
|
self-added: yes
|
|
self-added: yes
|
|
Closing as superseded by #13155 (merged 2026-09-24 10:27 UTC while this PR was in review), which fixes the same defect from the other side: the rewriter and the kiro ACP projection now REPLACE a reserved name's declared launch with the managed invocation, so the Toolbox shim is never what gets spawned or judged, and the gate deliberately stays realpath-only ( |
Pull request was closed
Problem / Motivation
On a Toolbox install (0.7.0.8, two independent reports), every call on
kirocrew-core,kirocrew-cronandkirocrew-dashboardanswersidentity_unattestedwhile the servers mount and list their tools normally. Only agents whose spec declares the server by its bare command --"command": "kirocrew"-- are hit; the specs Kiro Crew writes itself carry the versioned path and keep working. A new session does not help. The daemon log names it:Why it matters
Every Crew capability that posts back for the calling session -- cron, subagents, lessons, memory, notifications, session control -- is dead on those agents, silently: the tools are listed, so the failure reads as the tool being broken rather than the identity being withheld. Roughly a hundred externally managed agent specs use that spelling.
What changed (motivation → approach → change)
Both identity gates compare the spawn command against
agent.managed_mcp_spec_entryas one file:_spawns_own_control_planeinsrc/kiro_crew/mcp_gateway/gatewayd.pyby realpath,kiro_control_plane_serversinsrc/kiro_crew/acp/session_mcp.pyby string equality. The managed entry is the versioned binary. The barekirocrewresolves on PATH to~/.local/bin/kirocrew -> ~/.toolbox/bin/kirocrew -> tools/toolbox/<ver>/toolbox-exec-- one dispatcher shared by every Toolbox tool, which readstools/kirocrew/info.json(current version) andtools/kirocrew/<ver>.json(Executables.kirocrew.BundlePath) and execs the versioned binary. A dispatcher is not a symlink, so realpath cannot see through it and the two never compare equal.The fix reads what the dispatcher reads instead of executing it. Measured against the real
toolbox-exec(1.1.9714.0) under an isolatedBUILDER_TOOLBOX_HOME: it keys onargv[0]'s basename (a link under another name is "not associated with any tool"), reads ONE index --<root>/tools/globalInfo.json,Commands.<name>.Path-- and execs that absolute path verbatim; the per-toolinfo.json/<ver>.jsonare not consulted. New leafsrc/kiro_crew/managed_launcher.py:toolbox_dispatch_target()resolves a dispatcher shim to the file it would exec by reading that index, andsame_managed_launcher()holds when the spawn is the managed file by realpath OR the trusted root's dispatcher whose index names that file._spawns_own_control_planeinsrc/kiro_crew/mcp_gateway/gatewayd.pyuses it and hands the DISPATCHED launcher, not the dispatcher, to the import-shadow check.kiro_control_plane_serversinsrc/kiro_crew/acp/session_mcp.pyresolves a bare command onenv.mcp_search_path(the composition the rewriter and the MCP probe already use) and applies the same predicate; the element it emits now carries the managedcommand/args, so kiro-cli launches the file that was judged rather than re-resolving a bare word against its own PATH.Anchored, not widened. The root is
toolbox_root()-- the gateway's OWN$BUILDER_TOOLBOX_HOME, else~/.toolbox-- never derived from where the command sits, so a tree merely shaped like Toolbox elsewhere is a foreign binary exactly as before. The managed entry must itself live under that root (only a Toolbox install has a launcher a Toolbox dispatcher can front). The index entry must name that file by realpath, so an index rewritten to point elsewhere denies. A child environment that could point its dispatcher anywhere else denies -- aBUILDER_TOOLBOX_HOMEthat is not the trusted root, or aHOME/USERPROFILEthat is not this process's own home, each judged as the child would see it (a relative value resolves against the child'swork_dir, not this process's cwd, so it denies unresolved) -- because the child dispatcher would read an index this verdict never saw. The measured dispatcher does not readHOME(it took the account's home), but a fence modelling one dispatcher version is a false grant waiting for the next, so home divergence denies regardless. The index sits in the same user-owned tree as the managed binary, so trusting it concedes no capability realpath equality did not already concede.Version pinning of the emitted element: it is rebuilt at every session start from the running gateway's own launcher. If a Toolbox update reaps that launcher under a still-running gateway, kiro-cli's spawn of the element fails outright (
No such file or directory, server absent, no token handed to anything) rather than half-launching -- the same shape every Crew-written spec already has today, and it clears with the gateway restart the update needs anyway.Backwards compatibility
Compatible: every spawn the gates accepted before (realpath-equal, literal managed spelling) is still accepted; the only new acceptances are a Toolbox dispatcher shim whose declared target IS the managed launcher, and a bare/absolute spec command that resolves to that same file. The identity element now carries the managed
command/argsinstead of echoing the spec's spelling -- for a declaration that passed the old string-equality gate those are the same values.Tests
test/test_managed_launcher_toolbox_shim.pyrebuilds the Toolbox layout undertmp_path(shim, dispatcher,globalInfo.jsonindex, versioned launcher, the planted~/.local/binentry), pointsBUILDER_TOOLBOX_HOMEat it, and pins:_spawns_own_control_planeand earn the identity element, which carries the managed invocation;BUILDER_TOOLBOX_HOME(absolute-and-different, or relative),HOMEorUSERPROFILE(different from this process's home, or relative), while this process's own home in any spelling passes; an index dispatching elsewhere, foreign args, a managed entry outside the root, and a host with no Toolbox root (realpath only) all deny; the shadow check reads the dispatched launcher'sbin/;toolbox-exec(elsewhere, or under the root but outside the dispatcher directory), a link under another name, and every broken-index shape (not JSON, missing, not an object, entry not an object, relative or emptyPath, name not declared) resolve to nothing; the same root spelled through a symlink is accepted.Before the fix the shim/planted/bare cases fail in both gates (reproduced locally). Mutating
toolbox_dispatch_targetto returnNonefails the shim/planted/bare cases.Manual verification
Against the REAL Toolbox dispatcher binary (a copy of this host's
~/.toolbox/tools/toolbox/1.1.9714.0/toolbox-exec) in an isolated root,BUILDER_TOOLBOX_HOME=/tmp/kc-tbx-probe/.toolbox, withbin/kirocrew -> tools/toolbox/1.1.9714.0/toolbox-exec,.local/bin/kirocrew -> bin/kirocrew, an index namingtools/kirocrew/0.0.1/bin/kirocrew(a script that prints itsargv[0]), and the managed entry pinned to that script:The same probe established the dispatcher's semantics the resolver mirrors: with only
info.json+<ver>.jsonpresent it answersCommand "kirocrew" doesn't appear to be associated with any tool; with onlyglobalInfo.jsonit dispatches; aPathoutside the tree is still what runs;HOMEis not what it reads,BUILDER_TOOLBOX_HOMEis. No Toolbox-installed Kiro Crew gateway is available on the development host, so the session-levelidentity_unattested-> tools-working transition was not observed live; the gate the daemon log names is the one exercised above with the real dispatcher.Related Issues
no linked issue: reported on the internal contributors channel (2026-09-23, two reporters); no GitHub issue was filed.
Pattern harvest
Rule candidate: review-prompt
Pattern: "identity by realpath equality" treats a run-time dispatcher (a shared launcher that execs by reading a pointer) as a foreign binary; any gate that pins a spawn to a file must state what it does with launchers that are not symlinks.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)