Skip to content

fix(identity): give every managed Crew MCP server the session token - #12564

Closed
iamwhatever wants to merge 1 commit into
mainfrom
fix/session-token-work-dashboard
Closed

iamwhatever wants to merge 1 commit into
mainfrom
fix/session-token-work-dashboard

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

With the MCP gateway stubs off (the default install), a kirocrew-work or
kirocrew-dashboard tool call failed with:

identity_unattested: the gateway refused the tool-policy read for session mcp
because the request carried no session token

On the shared ACP runtime the session identity token rides on the injected
mcpServers element, not the process environment. That token was only ever put
on the always-on control plane (kirocrew-core, kirocrew-cron), so any other
managed Crew server launched from the agent spec came up with an empty env and
could not prove which session it was acting for.

Why it matters

A conductor whose spec grants kirocrew-work, or an agent granted
kirocrew-dashboard, could not use those tools at all — every call answered
identity_unattested. The same gap applies to every other managed Crew server
(kirocrew-computer, kirocrew-crew-log, kirocrew-panel), each of which also
posts back to the gateway for its session.

What changed (motivation → approach → change)

Managed Crew servers post back to the gateway to prove their session, but only
the always-on control plane was handed the per-session token, and the recipients
were hand-maintained name lists in two places — so a managed server missing from
either silently got no identity.

Both lists now derive from one source: the managed registry
(mcp_cleanup.KIROCREW_BIN_MCP_SERVERS, the ratchet-pinned mirror of
agent._MANAGED_MCP_SERVERS). In src/kiro_crew/acp/session_mcp.py the KIRO
direct-path identity (IDENTITY_BOUND_OPT_IN_SERVERS) is now every managed
server minus the always-on control plane; in
src/kiro_crew/mcp_gateway/gatewayd.py the stub path (CONTROL_PLANE_BACKENDS)
is the whole registry. The codex/opencode withhold path reads that same site:
src/kiro_crew/providers/mirrors/identity.py identity_bound_crew_servers()
returns frozenset(IDENTITY_BOUND_OPT_IN_SERVERS) rather than recomputing the
subtraction. A new managed server gets identity on every path for free, and none
can drift.

The recipient set is DERIVED at runtime, and a test-side NAME PIN in
test/test_session_token_identity.py fixes the reviewed membership beside the
derivation: a managed server joining or leaving the recipients now needs a
same-commit, reviewed edit to that literal.

src/kiro_crew/mcp_cleanup.py KIROCREW_BIN_MCP_SERVERS now states its
invariant at the definition — membership is what grants the token on both launch
paths, so a server that does not post back must not be listed there. The
architecture doc docs/architecture/mcp.md is updated to describe the derived
recipients (every declared, granted managed server, opt_in and spec_gate
alike) on both paths, replacing the passage pinning the extras to exactly
kirocrew-dashboard.

Invariants unchanged: CONTROL_PLANE_SERVERS stays (core, cron); identity is
carried only when the spec declares the server and tools grants it, never
auto-mounted; and _spawns_own_control_plane still verifies each spawn by
realpath, argv and env, so a gated server resolves to no managed entry and is
denied the token.

Verification: with the stubs off, /proc/<pid>/environ on each managed backend
now carries KIROCREW_STUB_SESSION_TOKEN, where only mcp-core did before.

Backwards compatibility

Compatible: identity is still gated on spec declaration + tools grant + the
byte-exact _spawns_own_control_plane provenance check, so no session gains a
token it was not already entitled to; the always-on mount set and the
codex/opencode withhold set are unchanged.

Tests

  • test/test_session_token_identity.py — pins IDENTITY_BOUND_OPT_IN_SERVERS
    as the derivation (managed registry minus the control plane), that it stays
    disjoint from CONTROL_PLANE_SERVERS, and that identity_bound_crew_servers
    returns that single source verbatim so the direct path and the codex/opencode
    mirror cannot diverge. A test-side NAME PIN asserts the recipient set equals
    {kirocrew-computer, kirocrew-dashboard, kirocrew-work, kirocrew-crew-log, kirocrew-panel} and that CONTROL_PLANE_BACKENDS == frozenset(KIROCREW_BIN_MCP_SERVERS),
    so a new managed server that posts back must be added in the same reviewed
    commit while the runtime stays derived.
  • test/test_mcp_gateway_stub_session_token.py — pins
    CONTROL_PLANE_BACKENDS equal to the whole managed registry
    (= _MANAGED_MCP_SERVERS), containment of CONTROL_PLANE_SERVERS, and that
    each token-only server is opt_in or gated (so it correctly stays out of the
    always-on mount set). The parametrized token-carriage tests now cover every
    managed backend.

A new managed server automatically gets identity; a spec that does not declare a
server still gets nothing.

Follow-up

The dynamic-loader env hardening for token-bearing control planes (fencing
LD_*/DYLD_* overlays a spec adds relative to the gateway's own inherited
environment) is tracked separately in #12615.

Manual verification

N/A — unit coverage sufficient. The identity carriage, the never-auto-mount and
foreign-command guards, and the codex/opencode withhold parity are all asserted
in the two test files above; _spawns_own_control_plane's realpath/argv/env
fences are pinned in the existing gateway suite.

Related Issues

no linked issue: internal identity-plumbing fix surfaced during drive-to-green.

Pattern harvest

Rule candidate: review-prompt
Pattern: any managed Crew server that posts back to the gateway must obtain its
identity from the same registry the launcher uses (KIROCREW_BIN_MCP_SERVERS /
_MANAGED_MCP_SERVERS), never from a hand-maintained name list — two lists of
token recipients drift, and a server missing from one silently loses identity.

@iamwhatever
iamwhatever requested a review from a team September 21, 2026 17:10
@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 21, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of fdecf39e6ace8985085bbb9963bd0c72693c3b53 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify kirocrew-panel and kirocrew-crew-log actually post back to the gateway — the derivation now hands every managed server a session bearer token.

[DESIGN-REVIEWED] fdecf39

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed fdecf39e6ace8985085bbb9963bd0c72693c3b53 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] fdecf39

Verdict parsed from the review's SHA-scoped output markers for commit fdecf39e6ace8985085bbb9963bd0c72693c3b53.

False positive or not applicable? A repository writer can comment:
/ai-review override fable fdecf39e6ace8985085bbb9963bd0c72693c3b53: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of fdecf39e6ace8985085bbb9963bd0c72693c3b53 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] fdecf39

False positive or not applicable? A repository writer can comment:
/ai-review override gpt fdecf39e6ace8985085bbb9963bd0c72693c3b53: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of fdecf39e6ace8985085bbb9963bd0c72693c3b53 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify the widened bearer-token grant: the old ratchet capped recipients at {core, cron, dashboard}; seven managed servers now qualify — confirm _spawns_own_control_plane fences hold for the four newcomers.

I checked the load-bearing premise myself: every managed server module (mcp_work, mcp_dashboard, mcp_computer, mcp_crew_log, mcp_panel) is built on mcp_shared.run_mcp_stdio_loop, whose tool-policy read resolves identity from the session token (session_key_from_env_token, src/kiro_crew/mcp_shared.py:364) — so "every managed server posts back" is verified, not asserted. The deleted token_only == {"kirocrew-dashboard"} pin is declared in the description and replaced by an equivalent five-name pin plus an opt_in-or-gated property check, with the defect's reproduction and base-failing tests as evidence, so lens 8 is satisfied. The fix sits at cause level: two hand-maintained recipient lists were the root cause, and all three sites now derive from KIROCREW_BIN_MCP_SERVERS; I found no remaining hand-maintained token-recipient list.

What this change ships

Inventory (7 items) — 7 justified

Intent: FIX — managed Crew tools like kirocrew-work failed every call with identity_unattested because only core/cron were handed the session token.

  1. Declared+granted managed servers now get the session token on the direct path — justified
  2. Stub path hands the token to four more managed backends (computer, work, crew-log, panel) — justified
  3. Token recipients on all three sites derive from one registry, not hand lists — justified
  4. "Extras = exactly dashboard" test pin replaced by five-name pin + property check — justified
  5. New constant IDENTITY_BOUND_OPT_IN_SERVERS (2 counted consumers: session_mcp loop, mirrors/identity.py) — justified
  6. mcp.md and mcp_cleanup.py invariant text updated in the same commit — justified
  7. Identity path now passes existing include_opt_in parameter to managed_mcp_spec_entry — justified

[FIRST-PRINCIPLES-REVIEWED] fdecf39

@iamwhatever
iamwhatever force-pushed the fix/session-token-work-dashboard branch from 0a3731c to 7f9a82a Compare September 21, 2026 17:47
@iamwhatever iamwhatever changed the title fix(identity): give kirocrew-work/dashboard the session token fix(identity): give every managed Crew MCP server the session token Sep 21, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/session-token-work-dashboard branch from 7f9a82a to b62108c Compare September 21, 2026 18:20
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Both CONCERNS are addressed in the amended commit.

The duplicated subtraction is gone: identity_bound_crew_servers() in providers/mirrors/identity.py now returns frozenset(IDENTITY_BOUND_OPT_IN_SERVERS), so session_mcp is the one site that computes "managed registry minus control plane". The former equality pin is now a single-source test (patches IDENTITY_BOUND_OPT_IN_SERVERS and asserts the function returns it verbatim); codex/opencode withholding stays green.

The docs/architecture/mcp.md passage is rewritten to current behavior: token recipients derive from the managed registry — every managed Crew server the spec declares and grants, opt_in and spec_gate alike — on both the stub path (CONTROL_PLANE_BACKENDS) and the direct path (session_mcp), so the two cannot drift. The stale "pinned to exactly kirocrew-dashboard / update the pin in the same commit" wording is removed.

Addressed in b62108cf1.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for b62108cf1c3ee49e025e4f3073733ef326724024; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b62108cf1c3ee49e025e4f3073733ef326724024: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Fixed. _spawns_own_control_plane now fences the dynamic-loader surface alongside PYTHON*: a new _CONTROL_PLANE_LOADER_ENV_PREFIXES = ("LD_", "DYLD_") constant, and any non-empty child-env key under that prefix denies the control-plane verdict with the same logged reason. A spec keeping the managed command/argv but adding LD_PRELOAD/DYLD_INSERT_LIBRARIES no longer runs a preloaded object in a token-bearing process. Tests are in test/test_mcp_gateway_stub_session_token.py::TestSpawnsOwnControlPlane — each LD_*/DYLD_* key refused, empty value and unrelated key still accepted.

In 9eb66d8f0.

@iamwhatever
iamwhatever force-pushed the fix/session-token-work-dashboard branch from b62108c to 9eb66d8 Compare September 21, 2026 18:55
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Addressed. The invariant — a managed Crew server posts back to the gateway for the session it acts for, so it needs that session's identity — is now stated at the registry definition (KIROCREW_BIN_MCP_SERVERS in mcp_cleanup.py), the single source both launch paths derive from, so a future non-posting addition is a conscious exception rather than a silent grant. The docstring on kiro_control_plane_servers now states the derivation instead of enumerating members. The registry-wide derivation is the design the repo owner requested and approved.

In 9eb66d8f0.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/session-token-work-dashboard branch from 9eb66d8 to 6485514 Compare September 21, 2026 19:36
@iamwhatever

Copy link
Copy Markdown
Contributor Author

The resolver strip closes the blocker: env_target_resolver removes the LD_*/DYLD_* namespace from the inherited env for control-plane backends, so _spawns_own_control_plane sees only spec-declared overlays and ambient LD_LIBRARY_PATH no longer denies the token.
test_loader_namespace_is_stripped_from_managed_spawn_env pins that an ambient LD_LIBRARY_PATH leaves core/cron a loader-free spawn env and the fence still grants the token; spec-declared LD_PRELOAD/DYLD_* stay refused.
The runtime recipient sets stay derived from the registry, with a test-side name pin restored on top so a new posting-back server needs a same-commit reviewed edit.

In 6485514c1.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 21, 2026
@iamwhatever
iamwhatever force-pushed the fix/session-token-work-dashboard branch from 6485514 to fdecf39 Compare September 21, 2026 20:28
@iamwhatever

Copy link
Copy Markdown
Contributor Author

The loader pair is removed from this PR — the identity fix now ships alone (gatewayd.py only adds the registry-derived CONTROL_PLANE_BACKENDS). The hole you flag is pre-existing: core/cron/dashboard on the base branch already reach a token-bearing process, so this fix does not widen it. It's tracked in #12615 with the design that compares a spec's loader overlay against the gateway's own inherited env rather than stripping it. Your finding's anchor line no longer exists on head fdecf39e6 — please re-evaluate.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Agreed, and split out: the LD_*/DYLD_* strip is gone from this PR so the identity fix stands without it. Your suggested design — deny only loader keys the spec overlay adds or alters relative to the gateway's inherited environment, never stripping the operator's inherited loader vars so conda/nix/HPC Pythons keep linking — is captured verbatim as the intended approach in #12615. This PR is now the identity fix only.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Done — the pair is deferred to its own change per your recommendation. Removed here: _CONTROL_PLANE_LOADER_ENV_PREFIXES, the fence hunk in _spawns_own_control_plane, and the strip in env_target_resolver, plus their tests. The identity fix stands on its own. The loader hardening is tracked in #12615 with the compare-against-inherited design.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ⚠️ review incomplete

GPT 5.6 did not produce a complete verdict for fdecf39e6ace8985085bbb9963bd0c72693c3b53; inspect the workflow logs and re-run it.

This comment is updated in place on each push.

See the GPT 5.6 Review job logs; this commit has no completed GPT verdict.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt fdecf39e6ace8985085bbb9963bd0c72693c3b53: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 21, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing: superseded by #12476, merged to main at 20:50 UTC.

#12476 lands the same design this PR converged on -- token recipients derive from the managed registry (IDENTITY_BOUND_SERVERS in session_mcp.py, CONTROL_PLANE_BACKENDS = frozenset(KIROCREW_BIN_MCP_SERVERS) in gatewayd.py) on both launch paths, with the mcp.md passage updated -- and additionally fences the LD_*/DYLD_* loader namespace in _spawns_own_control_plane. A rebase of this branch conflicts on every file it touches, and nothing here is left unaddressed on main.

Thanks to the reviewers whose rounds shaped the shared design.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 21, 2026
@dwu96 dwu96 removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 21, 2026
@bolichen97
bolichen97 deleted the fix/session-token-work-dashboard branch November 6, 2026 07:34
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