Skip to content

fix(identity): one resolver ladder, pid mapping records its tenants - #14357

Merged
iamwhatever merged 1 commit into
mainfrom
identity/token-session-resolver-w6
Sep 29, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
identity/token-session-resolver-w6

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: make a process's session identity come from its own per-session token, and make the pid mapping record which sessions share a pid, so a shared runtime stops misattributing one session's calls to another.

session_pid_<pid>.txt maps a pid to one session key, but one kiro-cli process hosts several ACP sessions (a spawn_run sub-agent runs on its parent's runtime; workflows/agent_pool.py workers share one). Every reader of that mapping answers with whichever session published last. That is a wrong answer, not a refusal, so the caller cannot tell.

One reader is an authorization check. dashboard/token_auth.py::_verify_unix_peer denies when the mapped key differs from the declared X-Session-Key, so on a shared pid the co-tenant is denied while declaring its own correct key. Reproduced on unmodified main: founder -> 200, co-tenant -> 403 peer_session_mismatch. Four client-side resolvers (mcp_caller, mcp_core, mcp_shared, peer_resolve) end in the same walk and return a co-tenant's key.

Why it matters

A 403'd session loses every session-keyed internal call: learn_add, cron management, ledger writes, callback delivery. Where the walk succeeds instead, a sub-agent's memory write, audit row or tool-policy lookup is silently charged to its parent.

Not a goal

  • Binding the token to the calling process per request. A same-uid process that can read a sibling's environment can present the sibling's token; that actor already has /proc/<pid>/mem, so the token is not the weakest link. Tracked for Wave 3 (RUNTIME_TENANCY claim binding); the GPT finding on this head was overridden by the project owner on that basis.
  • Retiring the pid mapping's file format. Other gateway builds read it, so a 1:1 pid produces the pre-existing bytes exactly; the file only gains a section above one session.
  • Fixing the client-side refusal on a recycled ancestor pid (recycled-pid ancestor makes lenient MCP identity refuse every call for identity-less callers #14646).

What changed (motivation -> approach -> change)

part before after
session_pid_sig.publish_session_pid one key per pid tenants=<n> + one tenant=<key> line each, under the existing MAC; written only above one session
token_auth._verify_unix_peer denies a co-tenant membership check, plus X-Session-Token verifying to the declared key on a shared pid; 1:1 path unchanged. With no mapping on disk, the live session manager's own key set decides: a declared key the manager does not host needs a token, and the degrade to today's semantics happens only when the manager knows nothing
own-identity readers guess a co-tenant's key refuse with a co-tenancy warning; only an answer stops the walk
four resolver copies four walks, two ps/libproc helpers one ladder mcp_caller.resolve_own_identity over platform_compat.get_ppid
_FROM_ENV_CACHE memoised the whole answer sits below every token rung; only the pid walk is memoised
mcp_tools/browser.py, mcp_computer.py no token header send session_token_header() so they keep working on a shared pid

One pid, N sessions, one key recorded, so readers guess. Recording which sessions share the pid removes the guess. The MAC stops an agent adding itself to a signed pid's membership; every co-tenant can still read the list, so membership alone is not enough to be a named session. On a shared pid the auth path also requires the per-session token, which is MAC'd under the agent-unreadable SEL trust root and already sent by every caller.

Two questions get two answers. Resolving your own identity from a shared pid has nothing to go on, so it refuses and says why. Verifying a declared identity checks membership plus token, so a legitimate co-tenant passes and a key the pid does not host is still denied. Absence of the record stays unknown, never "not shared", and a size-bounded mapping reports the true count so a truncated set is never read as complete.

The four client-side walks collapse into one ladder so a fifth copy cannot land silently; test_identity_topology.py registers the call sites. The process-lifetime memo sits below every session-scoped rung because a rekey rewrites the token's mapping while the token bytes survive, so any memo in front of the token would answer the pre-rekey session for the life of the process.

Backwards compatibility

Compatible: a 1:1 pid produces byte-identical mapping files and the auth path is unchanged for it; a reader that does not understand the tenant section refuses rather than mis-parses.

Tests

test_identity_topology.py adds a shared-runtime topology: all four resolvers refuse a co-tenant's key with the reason logged and name their own session from their own token. test_dashboard_peer_auth.py pins the three auth outcomes (co-tenant verified, foreign key 403, truncated membership degrades). test_session_pid_sig.py, test_resolve_session_key.py, test_mcp_browser_tool.py, test_mcp_computer.py and test_messaging_identity.py are repointed to the new behaviour. Mutations for each guard are recorded in the review thread; every one reddens its named test.

The pid-reader ratchet moves 161 -> 148 in this commit: this PR removes 13 per-session pid readers (the four resolver walks collapsed into one, and the libproc/ps helpers deleted). The count is measured on this tree, not copied from the failure text.

Manual verification

Two sessions on one process on this branch: founder and co-tenant both 200; a third key not hosted by the pid 403. The recycled-pid ancestor case was reproduced and is deferred to #14646.

Screenshots / video

N/A -- no user-visible UI change.

Related Issues

Refs #14355, #14484, #14646

Pattern harvest

Rule candidate: review-prompt -- a signature proves who wrote a list, never which member of it is speaking; a membership check on a shared identity must be paired with a per-member credential.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (docs/system-specs/modules/dashboard-token-auth.md, session.md)
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested review from a team and buluoray September 27, 2026 04:00
@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 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/dashboard/token_auth.py:2042 -- a shared spawn_run child encounters the parent’s complete 1:1 mapping and gets peer_session_mismatch before its valid token is checked -> Fix: recognize the live shared child before this denial and route it through _attest_shared.
[GPT-REVIEWED] a168df5

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

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

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify no other internal unix-socket sender declares X-Session-Key without _session_token_header — the pairing is per-call-site, and this PR exists because two sites lacked it.

Suggestions

  • Pin the key-declaring sender set structurally (a registry test like test_identity_topology's call-site scan, or one shared "declared-identity headers" helper) so a fifth sender cannot omit the token silently and re-create this PR's bug on shared runtimes; suitable as a small follow-up.

[DESIGN-REVIEWED] a168df5

Description read

[DESCRIPTION-READ] 81587141d1b2a93968e4924f8bd9863582d2c9c435a1994bcc0ea6fb8bc065ff

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of a168df5eca35a207aa34834cd14aa27063460fc8 — 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

PidMapping.admits/membership_complete are byte-for-byte second spellings of PeerTenancy's — zero non-test consumers, two copies to keep from diverging.

Not justified as shipped

  • Item 9 — duplicate of src/kiro_crew/peer_resolve.py: PidMapping.admits and PidMapping.membership_complete (session_pid_sig.py) repeat PeerTenancy's methods and docstrings; grepping src for \.admits\(|\.membership_complete finds only token_auth.py:1938-1939 on PeerTenancy — the PidMapping copies have 0 consumers outside tests.
    Subtraction: delete PidMapping.admits and PidMapping.membership_complete; the one verifying consumer already reads them off PeerTenancy.
    Clears when: the two methods are removed, or a src consumer of the PidMapping copies exists.

What this change ships

Inventory (10 items) — 8 justified

Intent: FIX — stop a shared kiro-cli pid misattributing one session's internal calls to another (reproduced 403 on main; refs #14355/#14484).

  1. A co-tenant declaring its own key on a shared pid is now admitted instead of 403'd — justified
  2. The pid mapping records its tenant set under the existing MAC; 1:1 files stay byte-identical — justified
  3. Own-identity resolvers refuse with a co-tenancy warning instead of naming a co-tenant — justified
  4. Shared-pid declarations (incl. unverifiable-mapping and manager-reported arms) now demand X-Session-Token, new 403 peer_session_unattested — justified
  5. Browser-panel and computer-use requests attach the session token beside the key — justified
  6. Four resolver walks collapse into one ladder; the ps/libproc helpers are deleted (verified: platform_compat.get_ppid covers Linux/macOS/Windows) — justified
  7. The from_env memo drops below the token/env rungs; only pid-walk answers are memoised — justified
  8. A walk that passed a malformed/recycled record now refuses the policy lookup; recycled-ancestor refusal deferred to recycled-pid ancestor makes lenient MCP identity refuse every call for identity-less callers #14646 — justified
  9. PidMapping.admits/membership_complete beside identical PeerTenancy methods — duplicate of src/kiro_crew/peer_resolve.py, zero consumers
  10. Baseline removals (black, subprocess-encoding) with reformat-only hunks in untouched tests — rides along

[FIRST-PRINCIPLES-REVIEWED] a168df5

Description read

[DESCRIPTION-READ] 73e32a571dbb8ffc5a4bae8d1df48a803ad0e2756ce07df174399cdbe6c18bc4

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@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 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Not blocking — one advisory issue: the new pid-mapping rung's fail-closed degrade turns a stale recycled mapping in a tokenless caller's ancestry into a permanent tools/call refusal.

FINDING — src/kiro_crew/mcp_caller.py:394 — unusable = unusable or mapping.refusal != REFUSAL_ABSENT counts REFUSAL_RECYCLED, a state _prune_stale_session_pid_files deliberately leaves on disk for every pid recycled into a live thread-group leader, so a tokenless MCP server with such a file in its ancestry and nothing answering above it (cron scripts, pooled MCP backends — the classes peer_resolve names for the degrade arm) now yields OwnIdentity(source=SOURCE_PIDFILE, failed=True) → _policy_session_key() returns None → ToolPolicy(frozenset(), "resolution_failed"), which is in _UNRESOLVED_REFUSES_CALL and hard-refuses every tools/call for as long as the recycling process lives, where the pre-change "" resolved to no_session_key and proceeded → Fix: separating a publisher-attested recycle from a forged start token needs the MAC, which this lenient client read cannot compute, so the remedy is to gate this degrade on verify_session_pid_mapping (or bound and log it) rather than on the refusal code alone — not landable inside the changed line.

[OPUS-REVIEWED] a168df5

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

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

@chenmingwei23 chenmingwei23 changed the title identity: resolve session by token, pid mapping becomes a tenant set fix(identity): one resolver ladder, pid mapping records its tenants Sep 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from fef633b to b3cd10b Compare September 27, 2026 06:11
@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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from b3cd10b to fc5fb5f Compare September 27, 2026 07:16
@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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from fc5fb5f to b86ff49 Compare September 27, 2026 07:53
@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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from 81a85c2 to 8f7b59d Compare September 27, 2026 20:08
@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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from 8f7b59d to fbb8f5e Compare September 27, 2026 21:00
@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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from fbb8f5e to 13284b8 Compare September 27, 2026 22: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 27, 2026
@chenmingwei23
chenmingwei23 force-pushed the identity/token-session-resolver-w6 branch from 13284b8 to 5b6c9a0 Compare September 27, 2026 22:35
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 27, 2026
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision a168df5eca35a207aa34834cd14aa27063460fc8 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 38f59dc: Reading a sibling's /proc//environ requires PTRACE_MODE_READ, which already grants /proc//mem and ptrace on that process and so every secret in it, meaning this token is not the weakest link and the standing stronger-capability test is met; the arm's bytes are unchanged and GPT cleared them on b86ff49, 81a85c2, fbb8f5e and a42640b; and at cap=1 only a subagent companion shares a runtime, which is the same session's own trust context.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 38f59dcd187274eb600979906cdc1b5b37cf8bd8.

Reading a sibling's /proc//environ requires PTRACE_MODE_READ, which already grants /proc//mem and ptrace on that process and so every secret in it, meaning this token is not the weakest link and the standing stronger-capability test is met; the arm's bytes are unchanged and GPT cleared them on b86ff49, 81a85c2, fbb8f5e and a42640b; and at cap=1 only a subagent companion shares a runtime, which is the same session's own trust context.

This decision applies only to this commit. A new push requires a new judgment.

Identity came from the pid, and a pid names a PROCESS. One kiro-cli process
hosts many ACP sessions, so on a shared runtime the mapping held whichever
key was published last: four client-side resolver copies attributed MCP calls
to a co-tenant, and the server side refused a legitimate co-tenant with 403.

The source of identity moves to the per-session token. The pid mapping stays
as a fallback and now records which sessions share the pid, inside the same
MAC, so a reader that resolves its own identity refuses instead of guessing
and a reader that verifies someone else's checks membership plus a token.
The four copies collapse into one ladder.

On a shared pid, membership is necessary but not sufficient: the roster is
agent-readable, so a token naming exactly the declared key is required, and
the requirement is keyed on the pid demonstrably hosting several sessions
rather than on the arm that discovered the need. Every internal sender that
declares a key attaches that token, so the demand admits the callers it was
written for instead of refusing them.

The mapping files sit in an agent-writable directory, so neither their
absence nor a failed signature is evidence of anything. A mapping whose MAC
does not verify, and an absence the live session manager contradicts, both
demand the token. A proven recycle does not -- that one is attested knowledge
that the pid moved on, and routine housekeeping produces it constantly -- and
neither does an absence no authority contradicts, which is what keeps a
warm-pool runtime, a cron script and a pooled backend working.

The tenant set counts SESSIONS only. The manager's snapshot appends a row per
companion runtime carrying display text, and a subagent runtime often repeats
the pid of a session it serves, which would record two tenants for a pid
hosting one and refuse a session that is not shared.

Behaviour on a 1:1 runtime is unchanged -- same bytes on disk, same ladder
order, same answers.

The pid-reader ratchet moves 161 -> 148 in this commit, because the ratchet
asserts EQUALITY and this change deletes 13 per-session pid readers: the four
ancestor-walk copies collapse into one ladder and the libproc/ps helpers go.
Measured on this tree rather than taken from the failure text -- 148 passes and
restoring 161 reddens exactly that one test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants