Skip to content

fix(security): fence the session identity binding and resolve it in the gateway - #12031

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/sandbox-sel-key-identity-11963
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/sandbox-sel-key-identity-11963

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

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>.txt naming a session of its choosing, signs it, and verify_session_pid verifies. require_strict_session_key then 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_pid ran 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_core called the key one "which agents cannot read"; session_pid_sig listed file forgery as blocked and called key access a "residual risk (an agent evading the deny-list)"; peer_resolve justified its signed_only=True discipline 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-identity root 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 calling open().

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-identity answers "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_auth publishes 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.py skips 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-identity root is a direct child of the data home, not a subdirectory of trust. 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.key stays 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_secret is left in place, because hiding it would buy nothing: read_local_secret resolves run/gateway-<port>.secret first, and run cannot 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.py pins 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_project suite. 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_LEAVES has 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_script already 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

@chenmingwei23
chenmingwei23 requested review from a team and smeyffret September 19, 2026 13:40
@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 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

_GATEWAY_PEER_SESSION_KEY caches identity for the process lifetime, but this module's own warm-pool model says process-keyed identity goes stale on rekey.

Watch

The 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 (monitor_start, set_project, memory writes) mutate the wrong session — the misbinding class this PR closes. The stability invariant is asserted in a comment, not established anywhere in the diff.
Clears when: evidence that no process reaching the gateway branch is ever rekeyed (e.g., sandboxed runtimes are claimed once per process), or the cache is invalidated/re-checked on rekey.

Suggestions

  • Mint identity_hmac.key as a full temp-file write + os.link instead of O_EXCL + incremental write: a hard crash mid-write (SIGKILL/power loss skips the BaseException unlink) leaves a short key that fails strict identity closed for the life of the host, while the ERROR message's remedy — "restart the gateway so the next session claim mints it" — is false for that state, since the exclusive create refuses to overwrite it.

[DESIGN-REVIEWED] 18a4e8e

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 18a4e8e8de8adc4b4454b9ad78de860fc0efcb44. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

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
if key is None:
return
Corrupt identity key -> unsigned peer resolution -> AF_UNIX middleware trusts an asserted victim session -> cross-session authorization bypass.
Anchor: backend-security-controls
Fix: Deny declared session identities when signed peer resolution is unavailable; exempt the keyless peer-identity endpoint.

[BLOCK-MERGE] 18a4e8e
[GPT-REVIEWED] 18a4e8e

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

Adjudicable block is empty (0 findings). One fenced finding, F1.

F1 — session_pid_sig.py:536 (publish path) and its verify-side consumer. Confirmed: when the identity key is unavailable at verify time, verify_session_pid returns "" (session_pid_sig.py:684–702); _verify_unix_peer treats an empty resolution as unresolvable and PROCEEDS, trusting the declared X-Session-Key on the caller's word (token_auth.py:1759–1760). That is fail-open to the pre-hardening baseline for a normally-protected same-uid caller.

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
[GPT-ADJUDICATED] 18a4e8e
[ADJUDICATION-FENCED] 18a4e8e fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/session_pid_sig.py:536 -- key-None degrades peer verification to trusting the declared X-Session-Key on the caller's word; the masked root blocks a sandboxed actor from causing it but benign host loss of the identity key can, so the unbounded cross-session-bypass condition is rare yet not so extreme that residual risk is clearly acceptable.
[GPT-ADJUDICATED-FENCED] 18a4e8e

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

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 18a4e8e8de8adc4b4454b9ad78de860fc0efcb44 — 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: 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

  • Item 8 — undeclared, point patch with counted unfixed siblings: the added paragraph itself concedes the shape — "no page and no Reach it path", "there by review judgment rather than by the gate" — and names 3 same-shaped routes (/api/session-keepalive, /api/session-directive, /api/computer-use/frame) that stay unlisted (grep of docs/feature-map/README.md: 0 rows for them), while "which handler owns this" is already answered by the dashboard-token-auth.md section this same commit adds.
    Subtraction: delete the feature-map row and its exception paragraph; keep the mandated spec section in docs/system-specs/modules/dashboard-token-auth.md as the single home for the route's ownership.
    Clears when: the row and paragraph are deleted, or a maintainer states the map now admits handler-lookup rows as a class.

What this change ships

Inventory (10 items) — 9 justified

Intent: 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.

  1. Sandboxed MCP servers learn their session from the gateway (GET /api/session/peer-identity, AF_UNIX only, caller names nothing) instead of verifying a signed file locally — justified
  2. The authoritative binding moves into a new masked session-identity/ root; the old data-home copy becomes attribution-only — justified
  3. Identity gets its own gateway-minted signing key; sel_hmac.key signs the audit chain only — justified
  4. A correctly signed binding at the agent-writable path no longer authorizes (two prior pins rewritten, declared, with tests failing on base) — justified
  5. On hosts without the socket (Windows, bind failure — confirmed at server.py:2174), strict identity falls back to a direct read of the fenced binding — justified
  6. The stale-pid sweep now enumerates and deletes bindings in both roots — justified
  7. Failure reports, throttle keys, and kirocrew doctor name the identity root; doctor reads unhealthy before the first claim — justified
  8. Feature-map row + exception paragraph for the new route — undeclared, point patch: 3 named siblings stay unlisted; ownership already documented in the spec section
  9. The gateway's answer is cached per process in mcp_core, empty answers retried — justified
  10. A strict-xfail test records the socket path's unfenced parent as a deferred residual for a maintainer decision — rides along: harm-free pin of an out-of-scope sibling

[FIRST-PRINCIPLES-REVIEWED] 18a4e8e

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

Both candidates die under falsification.

Candidate 1 (gateway route's ancestry walk misattributes a spawn_run subagent to its parent): the walk in resolve_peer_identity is source 3 in _resolve_session_key_strict, reached only after source 0 (gateway-injected caller context) and source 1 (the signed per-SESSION token) both come up empty. Source 1 is exactly the mechanism that keeps a shared-runtime subagent off its parent's identity — the docstring names it as "the only source that is both per-session (so a spawn_run subagent does not inherit its parent's identity on a shared runtime)", and test_stream_publishes_each_dedicated_attempt_not_shared pins that a shared subagent's own pid deliberately resolves to dashboard:parent while the token distinguishes the session. A subagent in its own sandbox has its own bound runtime, so the walk stops at its own pid. The candidate's scenario — a shared-runtime subagent with no per-session token, no env key, reaching source 3 — is exactly the "if a caller were to" case: I could not re-derive a concrete reachable input for it from the code, and the candidate itself concedes it could not verify the premise. The server-side walk is also the same one _verify_unix_peer and gatewayd have used pre-PR.

Candidate 2 (_GATEWAY_PEER_SESSION_KEY serves a stale key after an in-place rekey): source 3 is reached only in the sandboxed-dashboard case, which is one process per session, not rekeyed in place. The rekey/warm-pool topology resolves through source 0/source 1 (source 1 is accepted above the env var precisely to defeat rekey staleness), so a source-3-caching process that is rekeyed in place is not a reachable state I could establish — matching the discovery pass's own "low, did not confirm is reachable."

No new grounded finding surfaced while falsifying these; the xfail(strict=True) endpoint-fence test is an intentional, tracked gap, not a defect in changed code.

No findings.

[OPUS-REVIEWED] 18a4e8e

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

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

@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does 18a4e8e8de8adc4b4454b9ad78de860fc0efcb44 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 5 classified, 0 newly refused, 5 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: The agent-file-tool path fence (security/paths.py _CREW_SECRET_LEAVES) and the sandbox namespace mask (sandbox.py _CREW_HIDDEN_LEAVES + _CREW_PRECREATE_HIDDEN_DIR_LEAVES) gain the new leaf "session-identity", expanded under both crew data-home prefixes -- the ONE threat refused is an in-sandbox process forging its own session identity: "A file tool able to WRITE here names its own session as any other, and every consumer of require_strict_session_key then admits it as that session's live owner tab; able to READ the root, it forges the signature instead."

ADJUDICATED: 14 candidates, 0 confirmed newly-refused
No confirmed rows were handed to this review at capture time; the candidate set in candidates.json probes the fence's boundary rather than its middle -- the deliberately-unfenced attribution copy session_pid_<pid>.txt in the data-home root (which this PR's own tests pin as reachable), the data-home root listing (parent of the new leaf), basename collisions on session-identity outside the crew home (the fence is documented as prefix-anchored, not basename-matched), source searches naming the new leaf, the touched modules' own test runs, and the kirocrew doctor/kirocrew status commands the diff's new diagnostics direct operators to.

PLATFORM COVERAGE: posix (8 rows): tilde-relative reads and listings under both home spellings (~/.kiro/crew, legacy ~/.kirocrew -- the diff's leaf is expanded under both prefixes, so both must stay probed), relative-path and home-relative basename collisions, and the maintainer test/search loop. windows (4 rows): %USERPROFILE% with backslash separators, type/dir verbs, an absolute C:\ basename collision, and the corpus-style backslash venv interpreter -- mandatory here because the new leaf is declared via a forward-slash prefix join and because on Windows the PR's own test comments state the namespace mask does not exist, leaving the file-tool registry as the only fence, so a Windows over-match has no second control to hide behind. any (2 rows): bare kirocrew doctor / kirocrew status with no path or separator. macOS shares the posix spellings. Per-leg verdicts are the deterministic fold's to report after capture, not mine.

UNADJUDICATED: Three guards in this diff live outside the shell-command composite and got no verdict:

  1. /api/session/peer-identity admission (dashboard/handlers/sessions.py::api_session_peer_identity, listed in _STRICT_INTERNAL_API_PATHS in dashboard/server.py). Call path: mcp_core._session_key_from_gateway_peer → AF_UNIX socket → token-auth middleware (loopback + X-Internal-Secret) → handler refusals (unix_socket_required 403 on TCP; peer_unverified 403 when check_peer_is_self is not MATCH). Candidate legitimate inputs I could not get a verdict for: the in-sandbox MCP server's GET over the unix socket with the internal secret; a warm-pool runtime before claim and a cron-launched pooled MCP backend, both of which must receive 200 with an empty key rather than a 403; and any host where check_peer_is_self returns UNKNOWN rather than MATCH (containers, uid-mapped namespaces), where the deny-by-default refusal silently empties strict identity.

  2. mcp_core._resolve_session_key_strict. The locally-verified KIROCREW_HOST_PID + HMAC-sidecar branch is replaced by the gateway peer lookup with a fenced-binding read below it. The narrowing I can argue but not confirm: on a POSIX host where the dashboard AF_UNIX site failed to bind (the code itself documents "degrades to TCP-only on any bind or permission failure"), a SANDBOXED session previously resolved strict identity locally (sel_hmac.key and the mapping were sandbox-readable); now the gateway lookup finds no socket and the fenced-binding fallback returns "" inside the mask -- so monitor_start, set_project, memory writes and the workflow tools fail closed in exactly the sessions the replaced branch existed to serve. The corpus rows monitor_start/autonudge_stop name this surface but are MCP flows, not shell lines, so no classifier verdict exists.

  3. session_pid_sig.verify_session_pid now reads the fenced session-identity/ copy alone, signed by a newly-minted identity_hmac.key. Bindings published by a pre-upgrade gateway sit in the data-home root signed by the SEL root, so across the upgrade window every existing session's strict identity verifies as "" until the gateway republishes on the next claim; _verify_unix_peer degrades to status quo on "", but the strict MCP resolvers fail closed for that window.

Given these three, PASS on the strength of the adjudicated half alone would be the false green this lane exists to prevent; CONCERNS is the honest verdict.

[SCOPE-REVIEWED] 18a4e8e

@chenmingwei23 chenmingwei23 changed the title Fence the session identity binding and resolve it in the gateway, so an in-sandbox shell cannot forge it fix(security): fence the session identity binding and resolve it in the gateway Sep 19, 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 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Dispositioning the remaining findings on a5485d57f7.

Fixed, not argued. Four of the five findings across the two lanes were right and are addressed:

  • The advisory note that /api/session/peer-identity matched neither internal-path set was the most valuable finding on this PR, and it was not the blocking one. It is a real functional defect: _STRICT_INTERNAL_API_PATHS is an explicit set, the route was absent from it, so a secret-authenticated call from an in-sandbox MCP server fell through to cookie authentication and was refused. The client reads an unreachable answer as "no identity" and fails closed, so strict identity would have resolved empty in every sandboxed session with nothing in the logs naming the cause. The route is now in that set.
  • request["peer_session_key"] is deleted. The First Principles verdict was correct and the diff's own comment conceded it changed no decision.
  • The premise-risk item was a real regression. The endpoint resolved from the first binding found walking up the caller's ancestry, so a spawn_run subagent, whose MCP child sits under the parent slot's runtime, could have been handed the parent's session. The endpoint now requires the caller to name the pid its launcher exported, requires that pid to appear in the kernel-reported ancestor chain of the connection, and does an exact binding lookup. A caller whose own runtime has no binding gets nothing instead of its parent's identity. The ancestry requirement is a constraint the replaced branch did not have, since it trusted the declared pid outright.
  • Comment-history narration and issue numbers are out of the comments, and the inclusive-language hit is renamed.

One correction. The First Principles review reports that no code path removes the root binding copy, so the fallback in read_session_pid_txt serves a premise that does not exist. session_pid._prune_stale_session_pid_files does remove session_pid_<pid>.txt and its sidecar for dead or recycled pids, so the fallback stays. That finding did surface a real gap of mine in the other direction, which I am fixing: the sweeper does not yet prune the fenced copies, so a stale authoritative binding would outlive its process and could be matched after pid recycling.

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".

GET /api/session/peer-identity is reached by no user and rendered by no page. It is a machine-to-machine lookup on the gateway's unix socket, deliberately unreachable over TCP, whose only caller is an in-sandbox MCP server asking which session it is. Every existing row in the table names a page and a user path; the nearest rows owned by this same handler file are the sidebar history pane, the tool-approval card and the archive browser, all user-facing. Putting a machine identity endpoint in one of their "Reach it" columns would describe a path no user can take.

The mechanical checker agrees, for what it is worth: it fires only when a file is added or deleted under dashboard/handlers/, and this change edits an existing file, which the map documents as never tripping it.

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 /ai-review override myself. Happy to add a row immediately if a maintainer prefers that over either.

@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 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/sandbox-sel-key-identity-11963 branch from 516b572 to 215e259 Compare September 19, 2026 14:55
@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 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Update on 215e2594fa (squashed to one commit).

The feature-map finding is answered with documentation rather than a map row. GET /api/session/peer-identity is now documented where machine endpoints belong: docs/system-specs/modules/dashboard-token-auth.md, in the section on the unix-socket transport that carries it, under Routes on this transport.

That entry records what the map row could not usefully say: the route is in _STRICT_INTERNAL_API_PATHS so it authenticates on loopback plus X-Internal-Secret, it is refused with 403 on TCP because peer credentials are exactly what TCP cannot supply, it requires no declared X-Session-Key since a caller asking which session it is does not yet know one, and its only caller is mcp_core._session_key_from_gateway_peer. It also records why the exact-pid lookup exists, and states plainly that the route is absent from the feature map by that map's own user-facing rule.

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 dashboard/handlers/. A row in a "Reach it" column would describe a path nobody can take.

Also on this head, from the remaining findings:

  • The stale-binding sweeper now prunes the fenced pair alongside the attribution copy. This came out of checking the claim that no code path removes the root copy: session_pid._prune_stale_session_pid_files does remove it, so the read_session_pid_txt fallback stays, but it was leaving the authoritative copy behind, which would let a dead session's binding outlive its process and meet a recycled pid. Fixed with a test.
  • A regression test pins the client half of the exact-pid contract: the lookup declares the launcher-exported host pid, and without one it makes no request and returns empty, which is the same fail-closed outcome an unreachable gateway produces.

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: E2E (stub ACP backend, offline) failed test_private_workflow_memory.py::test_private_workflows_execute_over_real_projected_mcp with the strict-identity refusal, meaning identity stopped resolving in a really-booted gateway with a real projected MCP server. No unit suite reaches that path. I have not diagnosed the mechanism yet and am not guessing at a fix on a security path; the fresh CI round on this head will say whether the exact-pid and host-pid changes above already cover it.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 19, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/sandbox-sel-key-identity-11963 branch from 9482a22 to 926fecf Compare September 19, 2026 18:47
@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 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Round 3. Two findings fixed, one pushed back with the repository as the evidence.

Fixed: _load_identity_key could wedge strict identity permanently. The mint did a single os.write with no cleanup on failure. Because the create is exclusive, a short or failed write leaves a file every later attempt sees as already there, re-reads as too short, and refuses. Strict identity then fails closed for the life of the host, and the only way back is deleting the file by hand, which is a worse state than the write error that caused it. The write now loops until every byte is down, and any failure unlinks the file before propagating, so a retry can still mint. A test fails the write after four bytes, asserts no key is left behind, and asserts the next attempt mints a full one.

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 dashboard.peer-identity-refused denial naming which check refused, matching token_auth's sibling denial, and the audit is best effort so a logging failure cannot turn a denial into an answer. A test drives both paths and asserts two distinct denial records.

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: /api/session-keepalive, /api/session-directive and /api/computer-use/frame. All three are absent from docs/feature-map/README.md, and the Feature Map Gate is green on main with them absent. The two internal endpoints the map does carry, POST /api/browser/command-result and POST /api/computer-use/invoke, appear inside the endpoint column of a row for a feature a user reaches, not as rows of their own. The map states its unit in its own first paragraph: every user-facing dashboard feature, and how a user reaches it. A standalone row for this route would have nothing to put in the how-a-user-reaches-it or frontend columns, and it would be the only route of its class listed. The map's judgment rule also rejects cosmetic churn, which is what adding that row would be.

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, test_runloop_integration throttle parking, test_decisions_gate digest, and test_overload_integration_glue drain-refill, each passing on the next head and each a timing assertion with no overlap with this diff. The identity test that failed once, test_member_turn_publishes_ordinary_signed_pid_and_keeps_execution, has not recurred either.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/sandbox-sel-key-identity-11963 branch from 926fecf to e744aa8 Compare September 19, 2026 19:16
@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 19, 2026
…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
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 19, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/sandbox-sel-key-identity-11963 branch from e744aa8 to 18a4e8e Compare September 19, 2026 19:26
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

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.

docs/feature-map/README.md gains a Session identity row under Chat and sessions, naming the handler and the endpoint. Its Reach it and Page cells say plainly that no user path exists, because none does: the only caller is an MCP server resolving its own identity. The row carries a note that its siblings reached the same way are not yet listed, so the next reader is not left inferring a rule from one entry. The spec paragraph that asserted the opposite is corrected in the same commit rather than left to contradict the map, and it now records that the row is there by review judgment rather than by the gate, since the mechanical check does not require it.

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 test_sandbox_governance_mask.py: it asserts the endpoint's parent carries a posture, fails today, and flips to pass the moment the first shape lands. The suite stays green, and the gap is a failing assertion with a name rather than a paragraph in a review thread.

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.

@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 19, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

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 fix/sandbox-sel-key-identity-11963, rebased onto main 4b85004, gates green locally) is preserved on that branch's local worktree for anyone who wants to cherry-pick a piece as a plain bug fix.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 20, 2026
@chenmingwei23 chenmingwei23 reopened this Sep 20, 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 20, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 20, 2026
@bolichen97
bolichen97 deleted the fix/sandbox-sel-key-identity-11963 branch September 20, 2026 08:57
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.

Sandbox exposes trust/sel_hmac.key, so the strict session identity behind require_strict_session_key is forgeable from any in-sandbox shell

1 participant