Repository navigation
fix(mcp): stop answering MCP identity per process on a runtime hosting several sessions - #17524
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The stated repair path for a cleared tokenless stub doesn't exist: the stub carries no token, so no "claim carrying its own token" can ever name it. Watch
[DESIGN-REVIEWED] 07e39bd Description read[DESCRIPTION-READ] d6023bfacb35164af4b0c079efa836dfa280394532ada4938f17c9ed4ede7e0a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsAdvisory only. One finding survived and nothing blocks the merge. FINDING — src/kiro_crew/mcp_core.py:742 — When the host pid's mapping lists several sessions and the SEL trust root is healthy, [OPUS-REVIEWED] 07e39bd Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS
Not justified as shipped
What this change shipsInventory (7 items) — 4 justifiedIntent: stop a worker's MCP tool calls being credited to a co-tenant session on a shared runtime. FIX.
[FIRST-PRINCIPLES-REVIEWED] 07e39bd Description read[DESCRIPTION-READ] b2be412c71025f5ec39655aef39b8fd928cb35d42fc14620f8d4b552510bcd4a That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
|
Disposition for the two findings on SAST (Semgrep) - fixed. The rule reads a logger literal mentioning a token as a possible secret. No token value reaches this call: the interpolated Swept the rest of this change for the same shape: no other added logger literal mentions a token. PR Hygiene - fixed. The description was written to the 5-section house format, but this gate requires the template's own headings verbatim. The body is rebuilt on Security Scope Review - was not a finding. Its annotation said Ordering note: the body edit landed before the push, so the round the push starts is the one that gets adjudicated rather than being cancelled mid-flight. Local re-verification on the new head: both owning test files 196 passed, 1 skipped, 5 xfailed; |
ca6fed8 to
29f6f24
Compare
|
Disposition for the two findings on Backend Lint & Type Check (3.12) - fixed. PR Hygiene (Enforce commit count) - fixed. The branch carried 3 commits against a cap of 2. It is now 2, split along the two concerns rather than squashed flat:
Re-verified on the rebased tree, not carried over from the pre-rebase run: both owning test files 196 passed, 1 skipped, 5 xfailed; black, flake8, isort clean on all 6 files; 66 lanes were already green on |
29f6f24 to
9385af9
Compare
|
Disposition for the Design and First Principles CONCERNS on Both verdicts were advisory, but Design's first item is a defect this PR itself introduced, and a defect in code this PR adds is always in scope. All four items are fixed rather than deferred. Design 1, "shared really means ever shared" - fixed, and it was a real regression. The predicate is now
Pinned by Design 2, a parent with no usable token loses strict tools - stated and pinned. This is the chosen trade, now explicit in First Principles 1, the shared ladder's sibling rung - fixed. Correct and the more useful of the two findings: guarding only the strict helper left rung 3 of
First Principles 4, duplicate predicate - fixed. Verification on |
9385af9 to
5d01d78
Compare
|
Disposition for the Design and First Principles CONCERNS on Design 1, "the gateway site does not refuse anything" - fixed, and the verdict was right. The connection's caller is now cleared, which is the same fail-closed state the register path gives a token it cannot resolve. No caller on the wire, strict tools refuse with a diagnosis, and a claim carrying that stub's own token repairs it. Design 2, the third identity site and two wrong statements in the description - fixed. All three were accurate:
Design suggestion, the fixture docstring - fixed. First Principles 4, two copies of the same check - fixed. Correct, and they had already diverged on whether they passed Verification on One ordering note against myself: the body edit in this round was attempted before the push, as it should be, but it silently did not apply and I only caught that afterwards, so the body landed after the push rather than before it. The round this push started will therefore be re-rolled once by that edit. |
A claim carrying a session token re-targets a connection that carries no token, on the grounds that such a connection has no finer identity than the process tree the claim named. When the runtime serves exactly one ACP session that tree does name it. When it serves several, the PID names the runtime and not a session, so the attribution is a guess, and the stub it lands on answers as a co-tenant: its work_brief and work_report read and write the claiming session's ledger. The connection's caller is CLEARED in that case, not left alone. Whatever it holds is an earlier guess by the same PID, so a stub belonging to the second tenant would go on answering as the first -- the misattribution would stop moving without stopping. Clearing is a VERDICT, not an absence, and two things follow: * The connection is marked refused and the stub-initiated recaller rejects it. The recaller may fill exactly one state -- a key-less, tokenless connection nothing has named yet -- and a cleared connection is indistinguishable from that. Unmarked, a refused stub could name any session it liked, with a key from its own process-tree walk: the very per-runtime answer the refusal rejected. Only claim-push, naming this connection's own token, may name it. * Its subscriptions are evicted alongside the retargeted ones. A subscription granted while it answered as the old session must not outlive that identity, because resource-update URIs can carry tokens or presigned params, and the cleared connection never reaches the retarget list eviction walks. "Serves several sessions" is read from the LIVE connection index, not from the token bindings. A binding is append-only until the LRU cap evicts it, so the bindings say which sessions a pid was EVER claimed for: a warm-pool runtime claimed by A and later by B would read as two tenants while B is the only one left, and the stub would be stranded on A. Live connections also need no process start token, since a dead process's connections are already gone from the index. Connections carrying the claim's own token are excluded, because a slot's own stubs still show the previous session at the moment it is re-keyed. Every other topology is byte-for-byte: a tokened claim still reaches its own session's stubs, and a tokenless claim keeps its PID-wide reach, which a deployment whose sessions predate the token depends on. Replacing a DIFFERENT live identity on a shared runtime moves from INFO to WARNING. On a single-session runtime that replacement is the warm-pool rekey the path exists for and stays at INFO. The log line names what it is about rather than the stub's missing token: a logger literal mentioning a token reads to the credential-disclosure scanner as a possible secret, and no token value reaches that call.
… runtime ``KIROCREW_SESSION_KEY`` is stamped once per runtime and inherited by every MCP child of it. One runtime hosts many ACP sessions, so on a runtime the mapping records as multi-tenant the var names ONE tenant and cannot say which one is calling. Returning it attributes the caller to a co-tenant and lets a state-mutating tool write another session's state -- a work_report landing on another worker's ledger item. Both copies of that rung refuse it now, on the same ground the signed-pid source already refuses such a pid: source 2 of ``mcp_core``'s strict resolver, and rung 3 of ``mcp_caller.resolve_own_identity``, which is the one client-side ladder every other resolver shares. Guarding only the strict helper would leave the identical process-keyed rung answering for every caller that goes through the ladder -- the lenient resolver and the managed-tool-policy lookup among them. ``mcp_shared``'s audit-attribution read stays per-process, as its own contract already says misattribution is harmless for a read-only caller. One helper, ``mcp_caller.host_pid_is_shared``, serves both resolvers, so they cannot drift on how many sessions a pid serves nor on which read decides it. It takes the UNSIGNED mapping, matching the co-tenancy refusal the pid rung already performs, because this answer only ever DENIES an identity: a forged tenant section costs its target a refusal that names the reason, while demanding the MAC would make the guard inert wherever the SEL trust root is missing. Absence of a mapping is not evidence of sharing, so a single-session install keeps the var untouched on both rungs. A session_sharing parent whose own token cannot be verified is refused on a runtime a subagent has joined, even though the env var names that parent. That is the chosen trade and a test pins it: answering would hand the parent's key to whichever session is calling, and a silent write to another session's state is not recoverable where a named refusal is.
5d01d78 to
07e39bd
Compare
|
Disposition for the GPT 6.1 BLOCK on Both findings are security-class, both were upheld by adjudication, and both are direct consequences of the identity clearing added in the previous round. Confirmed in the code before fixing, and both are now fixed with their own mutation-verified test. F1, A clearing is now recorded as a verdict rather than an absence: F2, Cleared connections are now collected and evicted in pass 2 alongside the retargeted ones. They are evicted but not counted in Both are pinned, and each mutation is caught by its own test while the sibling still passes:
The description now declares both, under "What changed": that clearing is a verdict not an absence, and the two consequences that follow from it. Verification on |
|
Disposition for the two advisory CONCERNS on All five are accurate and are filed with the reviewers' own coordinates and clears-when in #17612:
Item 3 is the one I would act on first, since it is why the lanes are reviewing without the evidence section. |
|
Reviewed, not approving (crew-pr-reviewer). This changes how MCP identity is answered on a shared runtime. That is an identity boundary, so it needs a security owner. |
buluoray
left a comment
There was a problem hiding this comment.
Approve. On a runtime the pid mapping records as hosting several sessions, both process-keyed identity sources now refuse rather than name a co-tenant. A single-session runtime behaves exactly as before.
What was verified
- The fix does what it says.
mcp_core._resolve_session_key_strict(source 2) andmcp_caller.resolve_own_identity(rung 3) both skipKIROCREW_SESSION_KEYonly whenhost_pid_is_shared()reports positive evidence (PidMapping.shared=tenant_count > 1). Execution then falls through to the signed-pid source, which already refuses co-tenants, so the outcome is fail-closed"". The per-session token rung and the gateway caller block still sit above it, so a tokened caller keeps resolving correctly. - In
_apply_claim, a tokened claim that meets a tokenless connection on a pid with two or more live token-carrying tenants clearsconn.caller, setsidentity_refused, audits the change as denied and evicts that connection's subscriptions. This is fail-closed. The recaller rejects a refused connection, which closes the self-naming route. Tokenless claims keep their PID-wide reach, and that compatibility contract is untouched. _pid_live_tenantsreads the live connection index and excludes the claimant's own token. The token is minted once perAcpClientand survivesrekey(), so a warm-pool rekey of one slot is not counted as sharing.- Statelessness holds.
mcp_core/mcp_callergain no module global, andhost_pid_is_sharedreads the mapping on every call and never raises. The new per-connection flag lives on gatewayd's existing_StubConn, not in an MCP tool process. - Every new guard was disabled one at a time, and each mutation reddens a named test: the four env-var tests, the tokenless-co-tenant test, the recaller-after-refusal test, the subscription-eviction test, and the rekey-is-not-sharing and shared-runtime-warning tests.
- Targeted suites pass at this head, with one exception:
test_a_proven_recycle_is_not_unverifiablefails identically onmainin the reviewer's environment, so this PR did not cause it. CI is 85 success, 13 skipped, 0 failure on this head.
Blocking findings: none.
Non-blocking follow-ups
- The comments in
control.pyandidentity.py, and the PR body, say a cleared stub is repaired by "a claim carrying ITS token". A cleared connection is tokenless by construction, so no such claim can exist. What actually restores it is a later tokened claim after the pid stops being shared, or a tokenless PID-wide claim. Both reachconn.caller = updated_callerin pass 1. The comments should say that instead. Note also thatidentity_refusedis never reset after a repair. That is harmless while the caller is set, but it should be documented or cleared at line 329. host_pid_is_shared()adds one mapping-file read to every resolution that reaches the env-var rung. This is cheap, but it now sits on a per-call path for strict tools.docs/system-specs/modules/security.md(the "Strict Caller-Identity Classification" section) still lists the strict sources without the new shared-pid exception for the env var. It should get a one-line update.
Upgrade impact: none on a single-session install. A mapping with no tenant section, or with one tenant, leaves the env var authoritative on both rungs, and publish_turn_identity writes a tenant section only when it sees more than one session on the pid. The behaviour narrows only on a pid recorded as shared, where the old answer was a guess.
Audience fit: the default path is unchanged. The new refusals apply only to multi-tenant runtimes, which is the case being fixed.
Problem / Motivation
Goal: a worker's MCP tool call stops being attributed to a different session that happens to share its runtime process, so one worker can no longer read or write another worker's ledger item.
When one kiro-cli runtime hosts several ACP sessions, two identity sources still answer per process, so a tool call made by one session can resolve to a co-tenant of that runtime.
Site 1,
gatewaydretargets a tokenless stub connection PID-wide._apply_claimnarrows a claim to the session itsstub_session_tokennames, but a connection carrying no token is retargeted by any claim on its pid:That is correct when the pid hosts one session, because the process tree really does name it. When the pid hosts several, the tree names the runtime, the retarget is a guess, and the stub it lands on answers as whichever session claimed last.
Site 2,
KIROCREW_SESSION_KEYis process-keyed and unguarded.mcp_core._resolve_session_key_strictreturns the env var without consulting how many sessions the host pid serves. The var is stamped once per runtime and inherited by every MCP child of it, so on a shared runtime it names one tenant and cannot say which one is calling.Source 3 of that same resolver, the signed
session_pid_<pid>.txtlookup, already refuses this exact case.session_pid_sigstates the reason verbatim: "without it the pid answers with whoever published last." Source 2 is equally process-keyed and has no such guard.Why it matters
A misattributed caller does not fail visibly, it writes the wrong session's state. With the work ledger that means a worker's
work_briefreturns another worker's item and itswork_reportlands on that item, so one item collects a stranger's report while its own worker's never arrives. The same misattribution reaches anything else keyed by session:spawn_runparentage, session-scoped memory writes, monitors.Several sessions per process is not hypothetical on
maintoday.agent.session_sharingputs aspawn_runsubagent on its parent's process, and the open chat-runtime-sharing work (#15325) puts N top-level chat sessions on one.Not a goal
What changed (motivation -> approach -> change)
Symptom: a worker's
work_briefreturns a co-tenant's item on a shared runtime.Root cause: two identity sources answer by process.
gatewaydretargets a connection that names no session whenever any claim arrives on its pid, and the strict resolver trusts an env var that is stamped once per runtime.Change: both sites stop answering by process once the process is known to host several sessions, which turns a silent misattribution into a refusal that names its reason.
gatewayd(_apply_claim). A tokened claim no longer attributes a tokenless connection on a pid serving 2+ live sessions. It does not merely decline to re-target it: the connection's caller is cleared, which is the same fail-closed state the register path gives a token it cannot resolve. Leaving the earlier identity in place would let a stub belonging to the second tenant go on answering as the first, which stops the misattribution moving without stopping it. After clearing, the stub's calls carry no caller, strict tools refuse with a diagnosis, and a claim carrying that stub's own token repairs it. Audited as denied.Clearing an identity is a verdict, not an absence, and two things follow from that, both of which the clearing would otherwise get wrong:
recallerrejects it. The recaller may fill exactly one state, a key-less tokenless connection nothing has named yet, and a cleared connection looks identical to that. Without the mark, a refused stub could name any session it liked, using a key from its own process-tree walk, which on a shared runtime is the very per-runtime answer the refusal rejected."Serves 2+ live sessions" is read from the live connection index, not from the token bindings. A binding is append-only until its LRU evicts it, so the bindings answer "which sessions was this pid ever claimed for": a warm-pool handover from A to B would read as two tenants while B is the only one left. Connections carrying the claim's own token are excluded, so re-keying one slot is not mistaken for a second tenant.
The env-var rung, in both copies.
KIROCREW_SESSION_KEYis skipped when the host pid's mapping records several sessions, falling through to the signed-pid source rather than guessing. Two resolvers read that rung and both are guarded:mcp_core._resolve_session_key_strict, source 2, used by tools that demand a strict identity.mcp_caller.resolve_own_identity, rung 3. This is the shared client-side ladder, so the change also reaches its other consumers: the lenient resolver, the managed-tool-policy lookup, and read-only audit/telemetry callers. For those the effect is a key resolved one rung later, by the pid mapping, which already refuses co-tenants;mcp_shared's audit-attribution read is deliberately left per-process, since the module's contract already states misattribution is harmless for a read-only caller.Both call one helper,
mcp_caller.host_pid_is_shared, so the two resolvers cannot drift on how many sessions a pid serves nor on which read decides it.Logging. Replacing a different, still-live identity on a shared runtime moves from
INFOtoWARNING. On a single-session runtime the same replacement is the warm-pool rekey the path exists for, and stays atINFO.One deliberate asymmetry. The shared helper uses the unsigned mapping read, matching the co-tenancy refusal the pid rung already performs, because this answer only ever denies an identity. A forged tenant section costs its target a refusal that names the reason, while demanding the MAC would make the guard inert wherever the SEL trust root is missing, which is where identity is already weakest. Source 3 still demands the MAC, because source 3 grants a key.
Premise correction
This started from the theory that gateway stub identity was still keyed by pid and needed a per-session token. That is already shipped: #10324 mints a per-ACP-session token, narrows
_apply_claimby it, and makes the register path fail closed on any unresolved token. What was actually left are the two process-keyed sources above.Backwards compatibility
Compatible. Absence of a mapping is not evidence of sharing, so a single-session install keeps
KIROCREW_SESSION_KEYexactly as authoritative as it was, on BOTH guarded rungs; only a pid recorded as serving several sessions loses it. That holds for the sharedresolve_own_identityladder too, so its lenient, policy and audit consumers are unchanged on every single-session topology, and on a shared pid they resolve one rung later instead of naming a co-tenant.A tokenless claim keeps its PID-wide reach. A tokened claim still reaches its own session's stubs. A warm-pool rekey and a sequential handover both still re-target a tokenless stub, because neither is two live tenants.
Two behaviours narrow, both only on a pid recorded as serving several sessions: a tokened claim meeting a tokenless connection now clears that connection's identity instead of misattributing it, and the env-var rung stops answering. A caller that was being answered correctly by luck on such a pid is refused, which is the point: the value is identical for every child of the runtime, so a caller it happens to name cannot be told from one it does not.
Tests
Four new regression tests, each verified by mutation to fail with the fix reverted and pass with it applied.
test_a_tokenless_stub_is_not_handed_to_a_co_tenantassert 2 == 1, the tokenless stub was handed to the co-tenant; and with the clearing alone mutated out, the stub stays frozen on the first claimant's keytest_sequential_claims_on_one_runtime_are_not_sharingtest_a_rekey_of_one_slot_is_not_sharingtest_the_shared_ladder_refuses_the_env_var_on_a_shared_pidSOURCE_ENVwith a co-tenant's keytest_a_parent_with_no_usable_token_is_refused_on_a_shared_runtimetest_a_refused_stub_cannot_name_itself_with_a_recallertest_clearing_an_identity_evicts_its_subscriptionstest_replacing_a_live_identity_on_a_shared_runtime_warnsassert 0 == 2, no warning publishedtest_strict_refuses_the_env_var_on_a_shared_pidtest_strict_refuses_even_when_the_env_var_names_the_other_tenantTwo controls pin the compatibility promise and survive both mutations, so each mutation is specific to the refusal rather than breaking the path wholesale:
test_strict_keeps_the_env_var_on_a_sole_tenant_pidandtest_strict_keeps_the_env_var_when_no_mapping_is_published.Mutation procedure: the source file was copied outside the repo, mutated at exactly one asserted site, re-run, then restored by copy and re-verified by
sha256sumagainst the pristine digest, so no mutation residue reached a commit.Both owning test files in full: 196 passed, 1 skipped, 5 xfailed.
mypywith the repo venv binary:Success: no issues found.flake8,isortand the comment-history gate clean.Manual verification
A pod on the chat-runtime-sharing branch, three worker sessions proven by the runtime's own log to share one pid (
tenants=3), each bound to its own ledger item.work_briefreturned worker A's item and B's report landed on it, while B's own item stayed empty.kasbackend,kirocrew-workstubbed): each session's first turn resolved correctly and each item carried only its own worker's report. Re-running the two older tenants after the third joined made both return the third's item.That last result is the separate mount mechanism named under "Not a goal".
Pattern harvest
Rule candidate: semgrep.
Pattern: an identity resolver answering from a PROCESS-keyed source (an env var stamped at spawn, a pid-to-session mapping, a
/procancestor walk) without first establishing that the process serves exactly one session. Every instance of this class misattributes a caller to a co-tenant instead of failing closed, and the failure is silent because the answer is a well-formed session key.This PR fixes two instances;
mcp_callerand the signed-pid source had already fixed theirs independently, which is what makes it a class rather than a one-off. A rule that flags a return ofos.environ.get("KIROCREW_SESSION_KEY")or of a pid-keyed lookup from any function named*resolve*session*, unless a multi-tenancy check is reached first, would have caught both sites here and would catch the next resolver added.Fixes #17523