Repository navigation
fix(security): fence the session identity binding and resolve it in the gateway - #12031
chenmingwei23 wants to merge 1 commit into
Conversation
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS
WatchThe strict resolver's gateway branch caches its first non-empty answer forever ("A peer identity is stable for this MCP process once the gateway has resolved it"), yet the same file orders token-above-env precisely because "a warm-pool process is re-keyed to a new session while the env its MCP children were spawned with keeps naming the PREVIOUS one." If a runtime that reaches the gateway branch (no caller block, no token, no env — the sandboxed case) is ever rebound, the cache resurrects the previous session's identity and strict tools ( Suggestions
[DESIGN-REVIEWED] 18a4e8e |
GPT 5.6 Review — 🔴 changes requested (blocking)GPT 5.6 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/session_pid_sig.py:536 -- identity publication failures leave session claims fail-open [BLOCK-MERGE] 18a4e8e Adjudication (Opus 4.8) — is blocking on each finding proportionate?Adjudicable block is empty (0 findings). One fenced finding, F1. F1 — Rarity record I could NOT complete: the key lives in a masked root a sandboxed process cannot corrupt (peer_resolve.py:77–81), so an in-sandbox attacker cannot themselves cause key-None — but key-None can still arise from benign host events (disk corruption, partial restore, operator cleanup of the masked dir) while a sandboxed attacker is concurrently declaring a victim's live session over the reachable unix socket (the exact threat the docstring at token_auth.py:1684–1686 says this control exists to close). Those roles do not strictly contradict, recovery for an individual successful impersonation is "none" (it self-corrects only for future attempts once the next claim re-mints the key at session_pid_sig.py:535), and the consequence is unbounded cross-session authorization bypass. I cannot certify the key can never go missing during live operation, so the extreme-condition bar for FLAG is not met. [ADJUDICATION] 18a4e8e total=0 uphold=0 downgrade=0 False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS A docs rider point-lists one MCP-only route in the feature map while its own paragraph counts three siblings left unlisted, duplicating the spec that already answers ownership. Not justified as shipped
What this change shipsInventory (10 items) — 9 justifiedIntent: FIX — stop any in-sandbox process from forging the pid→session binding and being admitted as another session's live owner, by moving the binding and its signing key out of the sandbox's reach and answering identity at the gateway from the kernel-attested peer pid.
[FIRST-PRINCIPLES-REVIEWED] 18a4e8e |
Opus 4.8 Review — ✅ no blocking findingsReviewed Review detailsBoth candidates die under falsification. Candidate 1 (gateway route's ancestry walk misattributes a Candidate 2 ( No new grounded finding surfaced while falsifying these; the No findings. [OPUS-REVIEWED] 18a4e8e Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: CONCERNS TIGHTENING: The agent-file-tool path fence ( ADJUDICATED: 14 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (8 rows): tilde-relative reads and listings under both home spellings ( UNADJUDICATED: Three guards in this diff live outside the shell-command composite and got no verdict:
Given these three, [SCOPE-REVIEWED] 18a4e8e |
|
Dispositioning the remaining findings on Fixed, not argued. Four of the five findings across the two lanes were right and are addressed:
One correction. The First Principles review reports that no code path removes the root binding copy, so the fallback in One I am not acting on unilaterally: the feature-map row. The blocking finding asks for a map row for the new handler. I do not think adding one makes the map more truthful, and the map says so itself: it is "One table per area, mapping every user-facing dashboard feature to how a user reaches it", it is "a navigation index, not a contract", and the correctness rule "rejects unrelated or cosmetic map churn".
The mechanical checker agrees, for what it is worth: it fires only when a file is added or deleted under So the honest options are a maintainer override on this one finding, or a decision that the map should carry non-user-facing endpoints, which is a change to the map's stated purpose and not mine to make in this PR. I am not using |
516b572 to
215e259
Compare
|
Update on The feature-map finding is answered with documentation rather than a map row. That entry records what the map row could not usefully say: the route is in The reasoning against a map row is unchanged from the earlier comment: the map indexes user-facing features by the URL and control a user reaches them through, no user reaches this route and no page renders it, and its mechanical checker fires only when a file is added or deleted under Also on this head, from the remaining findings:
One failure on the previous head is still open and is a real regression from this change, called out here rather than left for a reviewer to find: |
9482a22 to
926fecf
Compare
|
Round 3. Two findings fixed, one pushed back with the repository as the evidence. Fixed: Fixed: the route's refusals were absent from SEL. Both 403s are peer-credential denials on the surface that answers "which session is calling", which is the surface an impersonation attempt probes, so an unaudited refusal leaves no record that anyone tried. Each refusal now logs a Pushed back, third time, on evidence rather than on reading. Three sibling routes are strict-internal, MCP-only, and reachable by no user and no page: So the finding asks for the opposite of the convention its own gate enforces, and I am not going to make the map inconsistent to clear it. A comment cannot clear a hard gate, so this one needs a maintainer decision rather than another round. Board. E2E is green. The Windows shard reds have not repeated: three different tests failed on three consecutive heads, |
926fecf to
e744aa8
Compare
…he gateway An in-sandbox process could forge which session it is. It read the key that signs the pid-to-session binding, wrote a binding naming any session, signed it, and every consumer of require_strict_session_key accepted it as that session's live owner tab. The cause is not which list a leaf sits in. Verifying an HMAC needs the same bytes as signing one, so a process that verifies locally can also forge, and the verifier ran inside the sandbox. Both halves of "which session is this" now sit outside the caller's reach: - The authoritative binding lives in a masked session-identity root, fenced from a spawned open() by the sandbox mask and from the agent's own file tools by the read-gate floor. The data-home copy remains for lenient attribution only. - That binding is signed by its own root, minted by the gateway with an exclusive create and never created verify-side, so sel_hmac.key no longer signs identity. It stays readable in the sandbox and signs the audit chain only. - GET /api/session/peer-identity answers identity from the kernel-reported peer pid of an AF_UNIX connection. The caller declares the pid its launcher exported, that pid must appear in the kernel-attested ancestor chain, and the lookup is exact, so a spawn_run subagent cannot inherit its parent slot. - The stale-binding sweeper prunes the fenced pair with the attribution copy, so a dead session's binding cannot outlive its process and meet a recycled pid. Seven prose sites that called the signing key agent-unreadable are corrected. Tests: a forgery signed with a stolen identity key does not change the resolved identity; a genuine on-disk binding does not let a process self-resolve; the replay refusal moves to the verifier with a positive control; the sweeper prunes both copies; the client declares its host pid and fails closed without one; and the new leaf is pinned at both fence layers. Fixes #11963
e744aa8 to
18a4e8e
Compare
|
Round 4. The feature-map finding is accepted and the row is added. My earlier pushback was overruled by the maintainer, and the finding stands.
The remaining finding on the identity channel's endpoint is real and is NOT being patched in this revision. The maintainer owns the choice between the two shapes it can take, and neither is a change I should make unilaterally: one moves the endpoint so its posture matches the binding it reports on, and the other records the gap against a separate issue and leaves this revision's behaviour as it is. Both need the same property to be true in the end, so the property is now pinned as a strict expected-failure in That test was checked both ways before landing, so it is a real property and not a placeholder: it fails against the current layout and passes against a fenced one. No override was requested or posted for either finding. Board on this head: the E2E lane is green, and the Windows reds of previous rounds have not repeated. Four different Windows tests failed across four consecutive heads, each passing on the next, and each a timing assertion with no overlap with this diff. Two defects of my own in the previous round's test are fixed: the cleanup unlinked before closing the descriptor, which Windows refuses while a handle is open, and the test patched a standard-library function process-wide instead of a named module function, which is what disturbed two sibling tests. |
|
Closing without merge (maintainer decision, 2026-09-20): #11963 was closed as not planned — sessions on one Kiro Crew gateway belong to one operator and are intended to read each other's records, so the identity fence this PR builds has no boundary to protect. #12025 was closed for the same reason. For the record, the branch carries four fixes that were found during review and may stand on their own merits independent of the fence — the caller-named ancestor accepted by the identity route, the sweep that missed the fenced binding, a key mint that could wedge strict identity permanently, and refusal paths that reached no audit log. The completed relocation (commit 68f3250f23 on |
What is the problem?
Any in-sandbox shell could forge the strict session identity and be admitted as the owner's live dashboard tab.
The chain: an agent reads the key that signs the pid-to-session binding, writes
session_pid_<own pid>.txtnaming a session of its choosing, signs it, andverify_session_pidverifies.require_strict_session_keythen returns the chosen key and every consumer accepts it. The consumers include the dashboard peer-session tools, cron, computer-use, the work-ledger server and the crew-log server from #11909, whose payload is every session's crew log including full message bodies.The root cause is not which list a leaf sits in. Verifying an HMAC needs the same bytes as signing one, so a process that verifies locally can also forge.
verify_session_pidran in-sandbox, therefore the sandbox had to hold the signing key, therefore the signature could not bind anything against an in-sandbox caller. No additional matcher or path-spelling rule could close that.Six prose sites asserted the opposite, which is why the gap survived review for as long as it did.
mcp_corecalled the key one "which agents cannot read";session_pid_siglisted file forgery as blocked and called key access a "residual risk (an agent evading the deny-list)";peer_resolvejustified itssigned_only=Truediscipline as being "keyed by the agent-unreadable SEL trust root". The sandbox exposes that key deliberately, with no evasion required.Why this issue matters to the user
Session identity is what separates one of a user's sessions from another. A sandboxed agent that can choose its own identity can read the transcripts of sessions the user never pointed it at, send messages as another session, change that session's scheduled jobs, and drive computer-use under its attribution. The user's only visible signal would be actions appearing in a session that did not take them.
How our fix solves it
Symptom: a forged binding is accepted. Cause: the binding is agent-writable and the signature is forgeable by anything that can verify it. So both halves are moved out of the caller's reach.
The binding is split. The copy at the data-home root stays agent-writable and becomes attribution only, read by the lenient resolvers where a wrong answer mislabels an audit line and grants nothing. The authoritative copy moves into a new
session-identityroot that is masked from every sandboxed process and fenced from the agent's own file tools. Both layers are needed and neither covers the other: the read gate answers the agent's tools, the OS mask answers a spawned interpreter callingopen().Identity gets its own signing root inside that directory, minted by the gateway with an exclusive create and never created on the verify side. This makes the two controls independent. The mask stops a binding being written, the key stops one being signed, and neither is load-bearing alone.
The in-sandbox verifier is gone.
GET /api/session/peer-identityanswers "which session is calling" from the kernel-reported peer pid of the AF_UNIX connection the MCP servers already use. It requires no declared session key, because a caller asking the question does not yet know one.token_authpublishes the kernel's answer and its docstring now says plainly that the header is an assertion checked against the kernel rather than a source of truth.That socket is an optional transport:
dashboard/server.pyskips it on Windows and degrades away on any bind failure. So the gateway lookup cannot be the only strict channel, or strict identity would disappear on those hosts. Below it sits a direct read of the same fenced binding. That read is safe precisely because the fence, not the transport, is what denies the sandbox: inside the sandbox both the binding and its signing root are unreadable, so the branch returns""there and only serves hosts the socket cannot.The
session-identityroot is a direct child of the data home, not a subdirectory oftrust. The precreate contract requires that: a nested leaf would have an agent-writable ancestor that a rename could swap out from under the mask.When minting the identity root fails, the operator report and its throttle now name the identity root that actually failed. They previously named
sel_hmac.key, so a failure of the new root was reported against a file that had not been touched, and the throttle keyed on the wrong path.Two things this deliberately does not do.
sel_hmac.keystays readable in the sandbox and now signs the audit chain only, because the in-sandbox audit writer is its second reader and moving that writer is a change to the audit path, tracked in #12025. And.local_secretis left in place, because hiding it would buy nothing:read_local_secretresolvesrun/gateway-<port>.secretfirst, andruncannot be masked since the sandbox launcher lives there. Bearer-token secrecy is therefore not a control this fix can rest on, which is exactly why the kernel peer-credential path carries the guarantee instead.What tests we did
The forgery test plants a binding signed with a stolen identity key, read back from the fenced directory, and asserts the resolved identity is unchanged. That shape is deliberate: the refusal must not depend on an attacker being unable to sign, since the audit key stays readable.
A second test publishes a genuine, verifying binding at the old agent-writable path and asserts the strict resolver still returns nothing. Without it, reinstating a read of the writable copy would look like a harmless fallback.
test_strict_identity_channels.pypins the two-channel contract that keeps the fenced fallback from becoming a hole. One case removes the gateway socket and asserts the fenced read still names the session, so a host without the socket keeps strict identity. Another makes the fenced root unreadable, as it is in the sandbox, and asserts the resolver returns"". Both claims were mutation-verified: deleting the fallback reddens the first, and trusting the writable copy reddens the second.The replay case moved to the verifier, where it now runs, and gained a positive control so a refusal proves the pid binding rather than a broken fixture. New posture tests pin the leaf in both fence registries and pin the attribution copy's deliberate exclusion from the floor. A report test pins the identity-root failure naming and throttling on the identity path rather than on
sel_hmac.key.Two existing tests failed on the first run by planting a correctly signed binding at the old path and expecting it to authorize. That is the property being added, so both moved to the fenced directory rather than being relaxed.
Counts on the current head: 592 in the sandbox governance mask suite, 30 in governance self-protection, 56 in the strict-resolver suite, 30 in dashboard peer-auth, 13 in strict-identity diagnostics, 8 in the new strict-identity channels suite, 18 plus 5 xfailed in identity topology, 26 in session-token signing, 238 in pid lifecycle, and 48 in the
set_projectsuite. 1878 across the error-code contract, denied-command pins and ratchet-audit suites together. mypy, black, isort and flake8 are clean.Any other suggestions on the work
_CREW_SANDBOX_VISIBLE_LEAVEShas no production reader. It is visibility by omission, expanded by nothing, referenced only by two prose comments and five test assertions. The name invites the conclusion that removing a leaf from it changes an OS disposition, which is what the issue's own remedy list assumed. Renaming it, or giving it the expansion its siblings have, would stop the next reader making the same inference.The strict resolver has two further branches that trust what the caller says about itself: a session-token mapping signed with the readable audit key, and a bare environment variable a process can set on any child it spawns, which
cron_scriptalready documents as best-effort friction. Neither is load-bearing once the gateway resolves identity from the kernel, but both would repay the same treatment, and the second is worth its own issue.Pattern harvest
Rule candidate: when a local check is replaced by a lookup over a transport the product documents as optional, the transport's absence becomes a new failure mode for the property being protected, so the fallback must be a channel the attacker still cannot use rather than the removal of the check. Here the AF_UNIX socket is skipped on Windows and degrades away on bind failure; deleting the local branch outright took strict identity with it and reddened E2E. Restoring it against the fenced copy keeps the guarantee, because the fence and not the transport is what denies the sandbox. The reviewable test for this shape is a pair: one case with the transport removed that must still resolve, and one case with the fenced path unreadable that must resolve to nothing.
Second rule candidate: when a failure report names a file, that name has to be derived from the path the operation actually used, not written as a literal. This change moved the signing root and the report kept naming
sel_hmac.key, which also keyed the throttle on a path that had not failed, so repeated failures of the real file could be suppressed by an unrelated one.Fixes #11963