Repository navigation
fix(identity): carry session identity to every granted Crew MCP server - #12476
Conversation
|
Intent: A Crew MCP server that an agent spec grants ( |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The bundle argv reorder rests on symmetry alone and widens the stale-spec token-denial window; a 382-line semgrep gate rides along that main already carries. Not justified as shipped
What this change shipsInventory (8 items) — 4 justifiedIntent: make the Crew MCP servers an agent spec grants actually usable by carrying the session's identity token to them on both launch paths — a FIX (issue #12464, tests added).
[FIRST-PRINCIPLES-REVIEWED] 49ce005 |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Stripping all WatchThe backwards-compat sweep proves "no supported configuration reaches the new denial," but [DESIGN-REVIEWED] 49ce005 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsThe project requires Python ≥3.12, so On the given candidate: stripping No findings. [OPUS-REVIEWED] 49ce005 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
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: |
87dfc01 to
4a842ec
Compare
|
Rebased: main moved in src/kiro_crew/apps/builtins/aws_control/backend/backup.py since this head went green (34fe0de -> 1dd5a03). The one red on 87dfc01 was mypy on that file -- main's own defect at 34fe0de, fixed on main by 1dd5a03 -- so this is a rebase-only re-sync with the diff unchanged; CI re-running on 4a842ec. |
4a842ec to
9b1f9a1
Compare
|
Rebased: main moved in src/kiro_crew/agent.py, src/kiro_crew/mcp_gateway/gatewayd.py and test/test_mcp_gateway_stub_session_token.py since this head went green (1dd5a03 -> 53cfc5d; conflict with #12459, which added kirocrew-dashboard to CONTROL_PLANE_BACKENDS and managed_mcp_spec_entry(include_opt_in=True)). Resolved by adopting #12459's resolver on both identity paths and dropping this PR's managed_mcp_granted_entry; the diff no longer touches agent.py. CI re-running. |
9b1f9a1 to
0c0f956
Compare
GPT 5.6 Review —
|
0c0f956 to
6fa78f8
Compare
|
self-added: no
|
|
self-added: no
|
An opt-in Crew server (kirocrew-dashboard, kirocrew-work, kirocrew-crew-log, kirocrew-panel) granted by a spec on the kiro backend was mounted straight from the spec with no session-valued environment, and gatewayd handed the per-frame token only to kirocrew-core, kirocrew-cron and (since #12459) kirocrew-dashboard. Since the tool-policy read requires an attestation, every call on any other such server refused as identity_unattested, and on the kiro backend the dashboard itself still did. kiro_control_plane_servers now re-emits every IDENTITY_BOUND_SERVERS element the spec grants, so the token attach reaches them; CONTROL_PLANE_BACKENDS is the same set, read from the mcp_cleanup leaf. Both paths resolve a granted opt-in name with managed_mcp_spec_entry(name, include_opt_in=True), the form #12459 introduced for the pooled check. The grant itself is unchanged: the spec's tools allowlist still decides what is mounted. Fixes #12464
6fa78f8 to
49ce005
Compare
|
Rebased: main moved in src/kiro_crew/computer_use/launch_macos.py, src/kiro_crew/computer_use/launch_windows.py, src/kiro_crew/crew_log/emit.py and src/kiro_crew/crew_log/projection.py (importers of modules this PR touches) since this head went green (20261b7 -> 14eb805); diff unchanged, overlap-scoped tests green locally; CI re-running on 49ce005. |
|
|
|
buluoray
left a comment
There was a problem hiding this comment.
Verified at head 49ce0056. Approving. The identity carry and the loader-namespace hardening are both sound, and I checked the two advisory CONCERNS against source rather than relaying them -- one holds and deserves an answer before merge, one reduces to cosmetics, and one item is already stale.
The hardening's own rationale is the strongest part of this change and worth restating so it does not get lost in the CONCERNS. A control-plane backend is exactly the process that holds a session identity token, and LD_* / DYLD_* replace code in every binary of the spawn chain -- so an operator-environment variable reaching that child is code injection into the token holder. Stripping the namespace in env_target_resolver and then denying any non-empty entry still present at the verdict is the right pair, and the ORDER is what makes it a guarantee rather than a hope: the classifier sees a cleaned environment, so anything remaining came from a hand-declared overlay. The prefix rule fails closed when Python or a loader adds a variable, which is the correct direction for a list that can go stale.
Design Review's CONCERNS holds and is the one item I would want answered before merge. Not because the strip is wrong -- it is within the threat the change names -- but because it has no operator remedy, and I confirmed both halves in the diff: env_target_resolver removes the namespace from the inherited environment, and the verdict then denies the token on any non-empty entry (if loader_env: return _deny_control_plane(...)). So on a host where the interpreter or its shared libraries resolve through LD_LIBRARY_PATH -- HPC module systems, shared-lib Python builds -- the control-plane child fails to start, and the spec cannot put the variable back, because declaring it is precisely what denies the token. That lands on kirocrew-core and kirocrew-cron, which are mounted in every session.
The PYTHONHOME precedent does accept this class, and Design is right that it is not the same bet: LD_LIBRARY_PATH is load-bearing on far more real installs than any PYTHON* key. The compat sweep in the description covers the denial path thoroughly and does not cover the runtime-dependency side. Either evidence that a control-plane child spawned by absolute interpreter path starts without an inherited LD_LIBRARY_PATH, or a compat note naming what an affected operator does instead, closes it. A host whose work stops with no record that anyone chose to lose it is the outcome worth spending a paragraph to avoid.
First Principles item 5 is mechanically correct but its consequence does not materialise. The verbatim comparison is real -- gatewayd.py:254-256 is if argv != expected_argv: return _deny_control_plane(...), a plain list compare with no normalisation -- so a spec carrying the old -P -s order really would be denied against a launcher emitting -s -P. What closes the window is that entry["command"] / entry["args"] are host-owned and rewritten on the existing-config refresh path at gateway start (agent.py:2507-2515 documents the fresh-build and refresh paths applying the same ownership logic, with args set by the caller on both). You cannot be running the new launcher without having restarted, and that restart rewrites the spec before any session launches an MCP server. So the finding reduces from "denies tokens on every pre-change Windows bundle" to "an unnecessary change" -- which it still is, since both orders behave identically and FP's suggested subtraction costs nothing. Your call, but it is cosmetics rather than a regression.
First Principles item 6 is stale -- do not act on it. It reports semgrep/mock-pid-allocatable.yaml, semgrep-tests/mock-pid-allocatable.py and test/test_mock_pid_gate_wiring.py riding along as byte-identical duplicates of main's 3042f6614. At this head they are not in the diff: the three-dot file list against origin/main is exactly the eight files this PR owns, and mock-pid matches zero of them. Nothing to rebase out.
Item 4 checks out as FP states it -- requires-python = ">=3.12" at pyproject.toml:14, so the deleted Python-3.10 pin was dead weight rather than a dropped guard.
Both blocking-capable lanes carry real verdicts at this head, which I checked by matching the SHA and taking the latest comment rather than reading the rollup: GPT 5.6 and Opus 4.8 both clean at 49ce0056 (20:15 and 20:17). The three "review incomplete" comments in the thread belong to the earlier 9b1f9a19 and 0c0f956d and are not outstanding -- worth knowing, because the repo's App installation has been returning rate limit exceeded on the shared Resolve human override preflight this evening, which is what produces that comment and what is currently reddening review lanes on other PRs.
kirodotdev#12476) An opt-in Crew server (kirocrew-dashboard, kirocrew-work, kirocrew-crew-log, kirocrew-panel) granted by a spec on the kiro backend was mounted straight from the spec with no session-valued environment, and gatewayd handed the per-frame token only to kirocrew-core, kirocrew-cron and (since kirodotdev#12459) kirocrew-dashboard. Since the tool-policy read requires an attestation, every call on any other such server refused as identity_unattested, and on the kiro backend the dashboard itself still did. kiro_control_plane_servers now re-emits every IDENTITY_BOUND_SERVERS element the spec grants, so the token attach reaches them; CONTROL_PLANE_BACKENDS is the same set, read from the mcp_cleanup leaf. Both paths resolve a granted opt-in name with managed_mcp_spec_entry(name, include_opt_in=True), the form kirodotdev#12459 introduced for the pooled check. The grant itself is unchanged: the spec's tools allowlist still decides what is mounted. Fixes kirodotdev#12464 Co-authored-by: Nicholas Bowers <NicholasRBowers@users.noreply.github.com>
kirodotdev#12476) An opt-in Crew server (kirocrew-dashboard, kirocrew-work, kirocrew-crew-log, kirocrew-panel) granted by a spec on the kiro backend was mounted straight from the spec with no session-valued environment, and gatewayd handed the per-frame token only to kirocrew-core, kirocrew-cron and (since kirodotdev#12459) kirocrew-dashboard. Since the tool-policy read requires an attestation, every call on any other such server refused as identity_unattested, and on the kiro backend the dashboard itself still did. kiro_control_plane_servers now re-emits every IDENTITY_BOUND_SERVERS element the spec grants, so the token attach reaches them; CONTROL_PLANE_BACKENDS is the same set, read from the mcp_cleanup leaf. Both paths resolve a granted opt-in name with managed_mcp_spec_entry(name, include_opt_in=True), the form kirodotdev#12459 introduced for the pooled check. The grant itself is unchanged: the spec's tools allowlist still decides what is mounted. Fixes kirodotdev#12464 Co-authored-by: Nicholas Bowers <NicholasRBowers@users.noreply.github.com>
Problem / Motivation
On the kiro backend, every tool on
kirocrew-dashboard--session_send,session_read_message, thechat_folder_*set -- is refused before it runs, in any session whose agent spec grants@kirocrew-dashboard:The audit trail shows the server resolved its session key and only the token was missing (
session_key=dashboard:chat-479-...,token=absent). The same holds for the other opt-in Crew servers (kirocrew-work,kirocrew-crew-log,kirocrew-panel) on both launch paths, and forkirocrew-computerwhen it is not routed through the broker.Why it matters
The peer-session tools are how one session hands work to another. The shipped conductor agents (
kirocrew-conductor,kirocrew-pipeline-conductor,kirocrew-security-conductor) mountkirocrew-dashboardby construction and so are broken out of the box on kiro: the server comes up, advertises its tools, and refuses every call. An operator who grants the server to their own agent gets the same present-but-unusable result with no remedy named.What changed (motivation → approach → change)
acp/session_mcp.py)kiro_control_plane_serversre-emits the element for every granted server inIDENTITY_BOUND_SERVERS, so the session token reaches it.mcp_gateway/gatewayd.py)CONTROL_PLANE_BACKENDSis the same set, read from themcp_cleanupleaf, so any routed Crew server is handed the per-frame token after the same binary/args/env check. That check, and the pre-spawn scrub of the daemon's inherited env, denyLD_*/DYLD_*alongsidePYTHON*(env._SPEC_ENV_DENIED_PREFIXES).agent.py,mcp_discovery.py)<python> [-s] -P -m kiro_crew <sub>:-Pkeeps the spawn CWD offsys.path, so akiro_crew/package in the user's project cannot shadow this install.docs/architecture/mcp.md)Every managed Crew server reads the session's tool policy from the gateway on each call, and the gateway accepts a declared session key only behind an
X-Session-Tokenattestation. Two things carry that token to a Crew server: on the kiro backend the runtime is session-unbound, so identity travels per MCP element andkiro_control_plane_serversre-emits those elements with the token in theirenv; on the pooled path gatewayd injects the token into the caller block. The first covered onlyCONTROL_PLANE_SERVERS, the two always-on servers; the second covered those two pluskirocrew-dashboard. An opt-in server is launched by kiro-cli straight from the spec withenv: {}, so on that path no attestation ever reached it.Handing the token to more servers makes the launch itself worth hardening. kiro-cli spawns a managed server with the user's project as its working directory, and the generic module-form fallback put that directory first on
sys.path; the Windows bundle branch already pinned-Pand the reason the generic branch did not (Python 3.10 support) no longer holds underrequires-python >= 3.12. On the pool, the ownership check refused a child env carryingPYTHON*but not the dynamic-loader channelskiro_crew.envalready treats as the same class.IDENTITY_BOUND_SERVERSis derived from the managed server list (control plane first, in its existing order, thenkirocrew-computerand the opt-in servers), so a server added to that list later is covered by construction and a session that grants only the control plane emits exactly what it emitted before. Both paths resolve a granted opt-in name's expected invocation withmanaged_mcp_spec_entry(name, include_opt_in=True); it still answersNonefor an unmanaged name or a closed spec gate. The grant itself is untouched: the spec'stoolsallowlist still decides what is mounted, an element whose declared command or args differ from Crew's own invocation is still withheld, andCONTROL_PLANE_SERVERS, the set that decides what every session mounts and what survivesdisabledTools, is unchanged.Backwards compatibility
Breaking, narrowly: a Crew control-plane backend whose spawn env carries a non-empty
LD_*orDYLD_*variable is now denied the session token, the same way aPYTHON*variable already was; and the managed module-form argv gains-P, so a spec written before this change carries the old argv until the spec writer regenerates it (require_fresh_derived_spec), during which the pool's args comparison denies the token rather than granting it. Writer sweep onorigin/main20261b763: both writers of a Crew server's env already strip exactlyenv._SPEC_ENV_DENIED_PREFIXES(sanitize_spec_envfor spec-declared env; gatewayd's resolver for the daemon's inherited env), so no supported configuration reaches the new denial. Nothing else changes shape: a spec granting onlykirocrew-core/kirocrew-cronproduces the same elements in the same order, and a granted opt-in server gains anenvtoken it never had.Tests
test_kiro_identity_projection_covers_a_granted_opt_in_server(dashboard, work, crew-log): a spec granting the server yields its element beside the control plane's, with the managed command and args.test_kiro_identity_projection_leaves_an_ungranted_opt_in_server_out: widening the set does not widen the grant.test_identity_bound_set_is_every_managed_server: derived from the managed list, no duplicates, control plane leads in its own order.TestGrantedOptInResolution: every opt-in managed server resolves underinclude_opt_in=Trueand not without it; the flag leaves the control plane's answer unchanged;kiro_control_plane_serversis pinned to pass exactlyinclude_opt_in=True, so dropping the keyword fails a test instead of silently un-granting every opt-in server.test_control_plane_backends_contain_session_mcp_and_justify_the_difference(gatewayd ratchet): the set equalsIDENTITY_BOUND_SERVERS, the control plane is a strict subset, the token-only extras are pinned by name to the opt-in servers pluskirocrew-computer, and each extra is a managed server that is not unconditionally mounted.test_the_real_dashboard_entry_rejects_native_loader_injection(LD_PRELOAD,DYLD_INSERT_LIBRARIES): the real managed invocation is denied the token and the warning names the key; an empty value is still accepted.test_control_plane_target_resolver_strips_inherited_native_loader_env: anLD_PRELOADthe daemon inherited is removed from a control-plane spawn env and kept for a third-party backend.test_agent.py_kirocrew_mcp_invocationassertions pin-s -P -m kiro_crew <sub>for every module-form fallback.managed_mcp_spec_entrywith a keyword-tolerant double, sincekiro_control_plane_serverspassesinclude_opt_in=True.Manual verification
N/A -- unit coverage sufficient: the change is two set-membership widenings, one resolver call, one argv flag and one env-prefix widening, each pinned above; the end-to-end shape (a kiro session's
session/newelement carrying the token) is already covered bytest_kiro_unpooled_control_plane_receives_session_token, which runs unchanged.Related Issues
Fixes #12464
Pattern harvest
Rule candidate: review-prompt
Pattern: an identity/credential carriage keyed on a hand-enumerated allowlist of names, while the set it should track is derived elsewhere -- a member added to the source set silently comes up unauthenticated.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)