Repository navigation
fix(auth): a shared-pid token must name a session the pid still hosts - #15529
Conversation
On a shared runtime the peer check admits a declared X-Session-Key when the pid's roster records it and a per-session token verifies to it. The token is a bearer credential in the runtime's environment, so a same-uid process that can read /proc/<pid>/environ presents a sibling's token and satisfies that check, and the roster it is compared against is a per-turn snapshot on disk. Require the declared key to hold a LIVE entry in one of the two ownership tables for the peer's ancestry as well: the lease table for a session that owns its runtime, the tenancy table for a sharing sub-agent or task run that does not. Tables that cannot speak about the pid answer empty, which stays today's semantics; only a non-empty answer that names other sessions and not this one denies, with 403 peer_session_unbound and an SEL record. A 1:1 pid never reaches this arm and is unchanged. A sub-agent's turn now records which session it is for, so the tenancy binds the key its stubs declare rather than only defending the process.
59458cf to
0afb441
Compare
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS A silently skipped turn claim now hard-fails the whole turn: auth admission rides on a kill-gate record that was designed to fail quiet. Watch
[DESIGN-REVIEWED] 0afb441 Description read[DESCRIPTION-READ] 0916f3d9359d55b1ed16a68f55b956b5d4c7f99db3233e43eb22becf006011db 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 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify the turn-scoped tenancy spans every legitimate stub call — a tool call landing after release is refused on positive evidence, beyond the declared cancelled-turn case. Not justified as shipped
What this change shipsInventory (5 items) — 4 justifiedIntent: make a lifted shared-pid session token unusable unless the gateway's own in-memory tables place that session on the calling process — a FIX.
Counts run: [FIRST-PRINCIPLES-REVIEWED] 0afb441 Description read[DESCRIPTION-READ] 338680d059deaebf63e3ae18d37e3db9e486f6ea9719ba49d0020bae68186a8b That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
|
Disposition for the Design Review finding on Accepted as real, deferred rather than folded in: #15557. The finding is correct. Deferred because the path is not reachable today and the remedy is not free. The cancelled-turn window the same theme touches is a separate, already-accepted |
Problem / Motivation
Goal: make a shared-pid session token unusable by a neighbour who lifted it, by requiring the key it names to be a session the process still hosts.
On a shared runtime one kiro-cli process hosts several ACP sessions, so the peer's pid names none of them. The dashboard's unix-socket peer check closes that with two facts: the pid's published roster records the declared
X-Session-Key, and anX-Session-Tokenverifies to exactly that key.The token is a bearer credential living in the runtime's environment. Any same-uid process that can read
/proc/<pid>/environlifts it and satisfies the name check with it — the token proves which session the caller claims to be, never that the session is on the process the call arrived from. The roster it is compared against does not close the gap either: it is a snapshot written to disk once per turn, in a directory the agent sandbox can write, so a session it lists may be long gone.Why it matters to the user
The key admitted on this arm is what
derive_caller_appderives app confinement from. A neighbour that borrows a session's token inherits that session's reach over the internal API — its sessions, its crons, its memory — and every one of those calls is attributed to the borrowed name in the audit trail, so the owner appears to have made them.Not a goal
403there is in the same position as one handling theAcpProcessDiedthe same teardown produces. Widening the window would mean a binding that outlives the turn, which is the stale-binding shape D10 rejects.What changed
Symptom: a same-uid neighbour makes internal API calls as another session.
→ It declares that session's key and presents that session's token.
→ Both checks pass, because a token is readable from the environment and the roster is a per-turn file.
→ Neither check asks the one question the neighbour cannot answer: is that session on this process?
→ Root cause: nothing in the check reads the gateway's own record of where it placed each session.
The gateway has exactly that record, in memory, in this process, in two tables an agent cannot edit:
RUNTIME_OWNERSHIP(leases)RUNTIME_TENANCY(tenancies)runtime_ownership.py—RuntimeOwnership.lease_keys_on_pidandRuntimeTenancy.tenant_keys_on_pidanswer which sessions, beside the counts the kill gate already reads;session_keys_bound_to_pidunions them. Live entries only, the same rule the gate's counts follow: a dead runtime names nobody._Claimcarries asession_key, andclaim()/claim_runtime_tenancy()take it as an additive keyword. Not parsed back out ofholder: that is a label written for a human reading a refusal log and free to reword, and an auth decision must not rest on a log format. A claimer with no session — the mint child — passes nothing and binds nothing, while still being defended by the gate exactly as before.acp/session_provider.py—_claim_shared_turnpassessession_key=self._session_key, the same key this session's stubs declare inX-Session-Key. For a sharing sub-agent that claim is the only record naming it: it holds no lease, andSessionManager.runtime_pids()never registers it.dashboard/token_auth.py—_bound_session_keys_on_chainwalks the peer's ancestry peer-first and the nearest pid either table knows decides. The peer is an MCP stub whose kiro-cli ancestor is the process sessions are placed on, so the answer is never on the peer pid itself._attest_sharedconsults it after the token resolves: a non-empty answer that omits the declared key is403 peer_session_unbound+ SELdashboard.peer-session-unbound; an empty answer is no evidence and changes nothing. The admitted record now carriesbinding=confirmedorbinding=no evidence, so the trail separates the hardened path from the one that fell open.Fail-open is the direction on purpose, and the tests pin it: the tables describe runtimes this gateway placed sessions on, so a warm-pool runtime before its claim, a pooled MCP backend, a cron script and anything from another install are all absent from them while being entirely legitimate. An empty answer that denied would 403 every one of those. The token check is untouched, so this arm is never weaker than before — only stricter where there is positive evidence.
Tests
test/test_dashboard_peer_auth.py50 → 58 passed. Three arms plus five contracts:admits_a_co_tenant_its_tables_still_place_herebinding=confirmeddenies_a_token_for_a_session_the_pid_no_longer_hostspeer_session_unboundsilent_tables_keep_todays_semanticsbinding=no evidenceunion_both_tables_and_walk_the_chainno_evidence_when_a_table_raisesno_session_key_binds_nothingdead_runtime_binds_no_sessionbinds_the_session_its_stubs_declareNeighbours unchanged:
test_runtime_ownership.py,test_acp_session_provider.py,test_acp_session_provider_shutdown.py— 222 passed with the file above. Ratchetstest_pid_reader_ratchet.py+test_kill_chokepoint_ratchet.py24 passed, both numbers unchanged.Mutations — 10 applied, 10 caught, every file restored byte-identical. The harness selftests itself first by breaking a pinned record on purpose and requiring the parser to name the expected test, so a silent run cannot read as a pass.
denies_a_token_for_a_session_the_pid_no_longer_hostssilent_tables_keep_todays_semanticsunion_both_tables_and_walk_the_chainunion_both_tables_and_walk_the_chainunion_both_tables_and_walk_the_chainno_evidence_when_a_table_raisesno_session_key_binds_nothingdead_runtime_binds_no_sessiondead_runtime_binds_no_sessionbinds_the_session_its_stubs_declareManual verification
Driving a real
AcpSessionProvidershared turn against the real tables, with the principal holding a lease on the same runtime, and reading the binding at the three points a tool call can arrive:dashboard:chat-1-abcdashboard:chat-1-abc,subagent:chat-1-abc-childdashboard:chat-1-abcThe window is exactly the turn, which is where every MCP tool call lands:
mcp_coreis the only client that sendsX-Session-Keyfrom a sub-agent's process, and it has noatexithook, no background thread and no timer, so each of its requests is driven by a tool call inside a model turn. The sub-agent's own teardown (_teardown_run_session_impl→shutdown()) runs in the gateway process and never crosses the socket, andspawn_continueis a new turn with a new claim. Gates run locally: black, flake8, mypy (Success: no issues found in 2 source files), comment-history (passed),pr-description-check.sh(success).Any other suggestions
_claim_shared_turnstill swallows an unexpected exception at debug level, and with this change a claim that silently failed costs the turn its binding rather than only its defence. Unreachable in practice —claim()does a guardedgetattr, a guarded liveness probe and dict work, and re-raisesRuntimeTeardownCommitted— but the level is worth revisiting when the wider bearer fix lands.PeerTenancy.admits/membership_completeand this binding now answer three overlapping questions about one pid. Worth folding once the roster stops being a disk snapshot.Pattern harvest
A credential that proves who the caller is does not prove where the caller is, and a check that conflates the two is satisfied by anyone who can read the credential. Bind the name to a record of placement that the holder of the credential cannot write.
The record has to be the one the attacker cannot edit, which ruled out both obvious candidates: the published roster is a file in a sandbox-writable directory, and the session manager's snapshot omits sharing sub-agents entirely. The in-process ownership tables were the only account of a pid's tenancy an agent cannot reach.
And the direction of the unknown decides the whole design: "these tables place the session elsewhere" is evidence, while "these tables say nothing" is not, so only the first may deny. Writing it the other way would have turned a hardening into an outage for every caller outside this gateway's own placements.
Rule candidate: when a check gains a second source of truth, decide what its SILENCE means before deciding what its answer means — and if silence is the ordinary state for a legitimate caller, silence may not deny.
Refs #14357 #14646