Repository navigation
fix(cli): prove the gateway peer before CLI internal-secret sends - #23283
Conversation
|
Local pre-push review dispositions (hand-written charters; the brief extractor reported a parity failure, so this is approximate to CI).
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. CI's Notes
[DESIGN-REVIEWED] 78ba007 Description read[DESCRIPTION-READ] 95ec0a8fc4b579e9b367c9880c05c61f03252ab75cd9d238d67bf4c706ba0c74 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 (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The one item that goes beyond the Goal is a declared side effect of reusing the shared proof. Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: CLI commands that send the gateway's internal secret refuse to send it unless the peer on the connection is this install's gateway (#21297). FIX.
[FIRST-PRINCIPLES-REVIEWED] 78ba007 Description read[DESCRIPTION-READ] 03308d3e99fd6496f4eb3969014ceaef7d9eadeb2344a6c80224cf6923757d1b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.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: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
9de64f5 to
93029f8
Compare
|
|
CI note for head 93029f8: |
93029f8 to
78ba007
Compare
|
Rebased once onto main for the #23264 Windows fix. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed current head 78ba0075b7f2c3dbb24e996f086941f2749712e6 as Tier 2. Deep review found no blocking issue.
Security check: secret-bearing CLI sends now prove the connected peer before sending bytes. Peer mismatch and missing identity records fail closed. Auto-merge remains subject to branch protection.
Problem / Motivation
Goal: The CLI commands named in #21297, plus
kirocrew doctor, check that the process on the other end of the connection is this install's gateway before they send the gateway's local/internal secret.kirocrew token,logout,stop,restartandupdatealready send the secret through a connection-bound peer check (_owner_verified_secret_urlopen, #20993). That value is also the gateway'sX-Internal-Secret.kirocrew spawn(list, run and its poll),kirocrew artifact,kirocrew file-delivery approve, thekirocrew doctoradaptive-controller read, the app-lifecycle client and the pod's Windows token mint sent it without that check. The memory-forget client carried its own copy of the socket check.Why it matters
The internal secret admits a caller to the gateway's internal API. A sender that writes it without checking its peer can deliver it to a different local process holding the port or socket path, for example after the gateway exits. The CLI's other secret sends already refuse in that case. Until now these did not.
Not a goal
cron_trigger(shared bykirocrew cron triggerand the agent's cron tool) and the code-review app. Their processes may not be able to run this check. That needs a decision first, tracked in security: decide the peer proof for agent-side and app senders of the internal secret #23270.What changed (motivation → approach → change)
Several CLI senders of the secret wrote it to whatever answered the port or socket. The connection-bound check was used by only six of them.
Every CLI sender now uses one shared check, from
cli_server_peer:kirocrew spawn,kirocrew artifact,kirocrew file-delivery approve, thekirocrew doctoradaptive read_owner_verified_secret_urlopen(unix socket when present, loopback TCP otherwise; peer proven on the connection)verify_peerhook calling_connected_unix_peer_is_recorded_gatewaytcp_verified_urlopenwhose hook compares_connected_tcp_peer_pidwith the pod's attested gateway pid_connected_tcp_peer_pidis the 4-tuple resolver from_connected_peer_verdict, now in its own function insrc/kiro_crew/cli_server_peer.pyso the pod check can use it too. The three hook-based checks emit the same SEL allowed/denied events as the shared proof.src/kiro_crew/cli_commands.pylists the two newcli_commands_gateway_apihelpers in its facade manifest. When the peer is not proven, each command reports "gateway ownership not verified" (or its own refusal type) and sends nothing. It never says the gateway is "not running", and it never falls back to another path. The CLI spec's "Owner-verified secret sends" section now lists these senders in place of the old out-of-scope note.Backwards compatibility
Compatible: a gateway this install started passes the same peer check
kirocrew tokenalready relies on. Only a peer that cannot be proven to be the recorded gateway is refused. One case changes:file-delivery approveon POSIX now sends over TCP when there is no socket file, with the same proof. Before, it reported the gateway as not running.Removes nothing: no command, flag, route or record is removed. The patch seam the spawn and artifact tests used moves from
loopback_urlopento_gateway_send, which is test-only surface.Tests
test/test_gateway_secret_senders_prove_peer.py(new): spawn list, run and poll, artifact and file-delivery approve each send through the peer proof with the secret attached. A refusal is reported, exits 1 and sends nothing. The app-lifecycle client checks its socket peer, sends neither request to a peer other than the recorded gateway, and audits both outcomes. All go red with the source reverted.test/test_cli_doctor_adaptive_live.py::test_an_unproven_peer_receives_nothing_and_is_named(new): a real loopback listener that fails the peer proof receives no request, and doctor prints one line naming why. Red on main. The existing live-server cases stand the test server in as the proven gateway.test/test_pod_ownership.py::test_mint_token_uses_attested_loopback_on_windows: the Windows mint goes over the verified TCP opener and audits allowed. A different or unresolvable peer getsPodError, is audited denied, and nothing is sent. Red on main.test/test_memory_forget_cli.py: the existing rebound-socket, recycled-pid and missing-record cases now go through the shared check.Determinism: the new and changed nodes passed 20× at
-n0, 10× at-n 4 --dist loadgroup --max-worker-restart=2alongsidetest_cli_gateway_client.pyandtest_apps_uninstall_backend_stop.py, and once in a seeded shuffle (seed 15163, 24 ids).Manual verification
N/A — unit coverage sufficient: each sender's transport and refusal are exercised through its real code path with the socket/TCP opener stubbed. The proof itself is already covered by the #20993 suite.
Related Issues
Closes #21297
Sibling sweep
Swept: git grep -nE ""X-(Local|Internal)-Secret"\s*:" -- src/
Sibling: src/kiro_crew/cli_commands_gateway_api.py -- changed here
Sibling: src/kiro_crew/cli_server.py -- changed here
Sibling: src/kiro_crew/app_lifecycle_client.py -- changed here
Sibling: src/kiro_crew/memory_forget_client.py -- changed here
Sibling: src/kiro_crew/pod/runtime_client.py -- changed here
Sibling: src/kiro_crew/cli_server_requests.py -- not affected -- already uses _owner_verified_secret_urlopen
Sibling: src/kiro_crew/cli_server_restart.py -- not affected -- already uses _owner_verified_secret_urlopen
Sibling: src/kiro_crew/cli_server_stop.py -- not affected -- already uses _owner_verified_secret_urlopen
Sibling: src/kiro_crew/cli_server_update.py -- not affected -- already uses _owner_verified_secret_urlopen
Sibling: src/kiro_crew/mcp_core.py -- tracked in #23270
Sibling: src/kiro_crew/mcp_computer.py -- tracked in #23270
Sibling: src/kiro_crew/mcp_cron_list_render.py -- tracked in #23270
Sibling: src/kiro_crew/mcp_shared_policy.py -- tracked in #23270
Sibling: src/kiro_crew/mcp_tools/browser.py -- tracked in #23270
Sibling: src/kiro_crew/cron_script.py -- tracked in #23270
Sibling: src/kiro_crew/cron_trigger.py -- tracked in #23270
Sibling: src/kiro_crew/doctor_checks/workload.py -- changed here
Sibling: src/kiro_crew/apps/builtins/code_review_sage/sage_lib/review_driver.py -- tracked in #23270
Pattern harvest
Rule candidate: semgrep
Pattern: a request carrying an
X-Local-Secret/X-Internal-Secretheader passed toloopback_urlopen, or tounix_socket_urlopenwithoutverify_peer, in a CLI moduleChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)