Repository navigation
fix(mcp-gateway): launch reserved kirocrew-* servers from the managed invocation - #13155
Conversation
|
Intent: A spec that names one of Kiro Crew's own MCP servers ( |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify on a real Toolbox-shim host that the repair clears Suggestions
[DESIGN-REVIEWED] a8efc53 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Manual verification was never run on an affected host — confirm on a real Toolbox install that a bare- Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: make hand-authored specs' reserved
[FIRST-PRINCIPLES-REVIEWED] a8efc53 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsFINDING -- src/kiro_crew/mcp_caller.py:203 -- FINDING -- src/kiro_crew/mcp_gateway/rewriter.py:406 -- [GPT-REVIEWED] a8efc53 False positive or not applicable? A repository writer can comment: |
af46edc to
7fb45cf
Compare
|
Re-pushed as 7fb45cf: the Internal Content Scan Gate flagged ticket ids and a user home path in comments and test fixtures; both replaced with neutral text. No behaviour change. |
|
|
|
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: |
7fb45cf to
a33d558
Compare
|
|
|
|
513bcfc to
a6f50dd
Compare
|
|
|
|
|
… invocation A spec authored outside Kiro Crew (an AIM package, a hand edit) cannot spell the managed command for kirocrew-core / kirocrew-cron: it embeds the data home and the installed version, so the one portable spelling is the bare Toolbox launcher `kirocrew`, which resolves to the shared dispatcher (toolbox-exec), a different file from the versioned binary. gatewayd._spawns_own_control_plane compares the spawned binary by realpath against the managed entry and denied the session token, so every control-plane tool refused `identity_unattested` while the server looked mounted. A version-pinned path fails the same way one upgrade later. Since 0.7.0.8 (which added the check) this stranded every such spec. The rewriter now re-derives a stubbed reserved name's command/args from managed_mcp_spec_entry before it resolves, hashes or bakes anything, so the stub target, KIROCREW_MCP_TARGET_* and the gate's expectation are one value; the kiro ACP projection (kiro_control_plane_servers) repairs the same mismatch instead of skipping the entry, as the codex/opencode projections already REPLACE theirs. The repaired entry is composed from the managed launch outward: the spec's restriction fields carry over, its env is held to the managed-entry ownership rule, and a spec autoApprove or any other key is dropped and named. The gate itself is unchanged: it still refuses the declared launch, the repair is what closes the gap. The managed launch joins the rewrite fingerprint (schema 9) so an upgrade regenerates kept overlays. Diagnostics: the daemon's denial reason rides the forwarded frames as CallerContext.identity_denial and is quoted by the identity_unattested refusal.
e1f2a9f to
a8efc53
Compare
buluoray
left a comment
There was a problem hiding this comment.
Approving at a8efc53.
Verified: the daemon gate keeps all seven deny checks one-for-one (realpath, argv, loader-env, shadow and the rest) and only routes them through a local deny() that also records the reason. The repaired entry is built from the managed launch and keeps only type/timeout/disabled/disabledTools. Its env is filtered through the same ownership rule as the disk writer, and autoApprove is dropped. The repair runs after the muted pass-through, so it cannot unmute an entry. The refusal text is defanged and redacted. Passing env/autoApprove through reddens five named tests. 359 passed, 1 skipped.
Not verified: an override-home install end to end, where KIROCREW_HOME comes from the daemon env rather than the repaired entry.
… invocation (kirodotdev#13155) A spec authored outside Kiro Crew (an AIM package, a hand edit) cannot spell the managed command for kirocrew-core / kirocrew-cron: it embeds the data home and the installed version, so the one portable spelling is the bare Toolbox launcher `kirocrew`, which resolves to the shared dispatcher (toolbox-exec), a different file from the versioned binary. gatewayd._spawns_own_control_plane compares the spawned binary by realpath against the managed entry and denied the session token, so every control-plane tool refused `identity_unattested` while the server looked mounted. A version-pinned path fails the same way one upgrade later. Since 0.7.0.8 (which added the check) this stranded every such spec. The rewriter now re-derives a stubbed reserved name's command/args from managed_mcp_spec_entry before it resolves, hashes or bakes anything, so the stub target, KIROCREW_MCP_TARGET_* and the gate's expectation are one value; the kiro ACP projection (kiro_control_plane_servers) repairs the same mismatch instead of skipping the entry, as the codex/opencode projections already REPLACE theirs. The repaired entry is composed from the managed launch outward: the spec's restriction fields carry over, its env is held to the managed-entry ownership rule, and a spec autoApprove or any other key is dropped and named. The gate itself is unchanged: it still refuses the declared launch, the repair is what closes the gap. The managed launch joins the rewrite fingerprint (schema 9) so an upgrade regenerates kept overlays. Diagnostics: the daemon's denial reason rides the forwarded frames as CallerContext.identity_denial and is quoted by the identity_unattested refusal.
Problem / Motivation
Since 0.7.0.8, an agent spec that launches Kiro Crew's own MCP servers with the ordinary Toolbox command,
"command": "kirocrew", gets servers that mount and list their tools but refuse every call withidentity_unattested. No cron, no subagents, no lessons, no memory. A new session does not help; the spec is what is wrong. Reported from a fleet where every affected spec came from a package manager, on Linux and macOS alike.Why it matters
The managed command embeds the user's home and the installed version (
~/.toolbox/tools/kirocrew/0.7.0.8/bin/kirocrew; on macOS a path inside the app payload). No spec author outside Kiro Crew can write it, and a spec that pins it breaks on the next upgrade. So every hand-authored spec is dead on this check, and the only accurate error line lives in a daemon log no session shows. Two engineers reached three wrong diagnoses before finding it.What changed (motivation → approach → change)
mcp_gateway/rewriter.pykirocrew-*entry launched the spec's command with the spec's env andautoApprove_repair_control_plane_entry), for a spec-declared and asettings/mcp.json-injected reserved name alike: spec restriction fields carry over, env is held to the ownership rule (_owned_control_plane_env), a specautoApproveand every other key are dropped and named; managed launch joins the fingerprint (schema 9)acp/session_mcp.pykiro_control_plane_serversmcp_gateway/gatewayd.py,backend.py,mcp_caller.py,mcp_shared.pymcp-gatewayd.stdoutidentity_denial; the refusal quotes itdocs/architecture/mcp.mdidentityDenialchannelThe bare launcher
kirocrewresolves through PATH to the shared Toolbox dispatcher,toolbox-exec. That is a different file from the versioned binary, sogatewayd._spawns_own_control_plane, which compares the spawned binary by realpath, refused the token. The check was right about the file. It was wrong to trust the spec for what to spawn.A reserved name now always runs the managed source of truth, the same way
agent._enforce_managed_mcp_ownershiprewrites the disk entry and the codex and opencode projections REPLACE theirs. The rewriter does this before it resolves, hashes or bakes anything, so the stub target,KIROCREW_MCP_TARGET_*and the gate's expectation are one value. The gate itself is unchanged and still refuses the declared launch; the repair is what closes the gap, and a third-party binary squatting a reserved name gets our binary, not the token for its own. The grant,disabled,disabledTools,timeoutandtypestay the spec's. The entry'senvis held to the same ownership rule the disk writer and the ACP element already apply: Kiro Crew's reserved namespace, loader channels, home-deriving and launcher-exec keys are dropped, so a spec cannot hand our binary aKIROCREW_APPROVAL_MODE=auto. a specautoApproveis dropped and named (kiro-cli honours it before the PreToolUse gate; no managed declaration carries one). Any other key is dropped and named in the log.Backwards compatibility
Compatible: a spec that already carries the managed launch round-trips byte-identical (test). A spec whose reserved-name command was wrong went from a dead server to a working one. The caller meta gains an optional
identityDenialkey that old backends ignore (schema unchanged, additive).Tests
test/test_mcp_gateway_control_plane_repair.py(new): the ticket's reproduction end to end with the real managed entry and the real gate, for the Toolbox shim and a reaped version pin; target env agrees with the stub; already-managed spec is silent; unreserved names untouched; unresolvable managed name left as declared; every reserved name repaired; the repaired entry composed from the managed source outward (restriction fields kept,autoApproveand stray keys dropped, specautoApprovedropped and named); declared env held to the ownership rule (reserved namespace, loader, home and launcher keys dropped; ordinary key kept) for both a repaired and an exact launch; a scalarargson a reserved or third-party entry no longer aborts the rewrite pass (_spec_args, also used by the stub builder); fingerprint sees the managed launch; gate reports its reason; denied backend gets the reason and never the token; meta round trip.test/test_session_token_identity.py: the oldcommandrestriction case is replaced by a parametrized repair test over spec and settings sources, with a negative control that the declared launch never reaches the element; a scalarargs(8080,true, a dict) on a reserved name is compared, not iterated, sosession/newdoes not abort.test/test_mcp_shared.py: theidentity_unattestedrefusal quotes the daemon's denial when the frame carries it; the existing text is unchanged without it.test/test_mcp_gateway_stub_session_token.py,test/test_mcp_gateway_claim.py: doubles carry the newcontrol_plane_denialfield and the gate'sdenialkeyword.Manual verification
Not run on the reporter's host. The regression test drives the same rewriter and gate the daemon uses on the exact spec shape from the ticket. A reader with an affected spec can confirm after upgrade with
grep "is not the spec's" ~/.kiro/crew/logs/mcp-gatewayd.stdout(stops appearing after a gateway restart).Related Issues
no linked issue: reported through an internal ticket; this PR is the fix.
Pattern harvest
Rule candidate: review-prompt
Pattern: an identity gate that compares a spawned command against a managed value must also own the spawn (REPLACE from the managed source), or every hand-authored consumer fails closed with no path to conform.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)