Skip to content

fix(security): wait briefly for a new host's DNS lookup in the ssh floor - #38656

Open
buluoray wants to merge 1 commit into
mainfrom
crew/slack/ssh-self-dns-wait
Open

buluoray wants to merge 1 commit into
mainfrom
crew/slack/ssh-self-dns-wait

Conversation

@buluoray

@buluoray buluoray commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The ssh-to-self floor allows a remote host, and an ordinary file name after a glob, on the first try instead of refusing it while a DNS lookup is still running.

In a fresh process the floor refused ssh -T git@github.com on the first call and allowed it a few seconds later. git add s* README.md failed the same way: refused once, then allowed. Both came from the same place. The first check of a new dotted name started a DNS lookup and refused at once, before the answer came back.

Why it matters

An agent doing git over ssh (an auth check before a push, a fetch) gets a refusal on its first try for a host that is not this machine. An agent staging files with a glob gets a security refusal for a plain git add. Both look like random failures, and the refusal text quotes the loopback rule, which is misleading.

Not a goal

  • Changing what counts as this machine. A loopback answer, a failed lookup, and this host's own names stay refused.
  • Waiting on the gateway's event loop. A check there answers at once, as before.
  • Rewording the refusal note.

What changed (motivation → approach → change)

Case Before After
First check of a remote dotted name, off the event loop refused waits for the lookup, then allowed
git add s* README.md, first call, off the event loop, when the lookup answers remote refused allowed
Lookup answers loopback, fails, or is still running after the wait refused refused
First check on the event loop refused refused (no wait)

_resolved_host_verdict in argv_floor_hosts.py waits for the resolver worker it started, off the event loop only, at most _HOST_VERDICT_WAIT_SECS (0.5 s) in total per check. The worker signals a condition when it finishes. One check shares one deadline through its _CALL_VIEWS memo, so a line naming several new hosts still waits half a second at most. This follows the maintainer decision on #37311.

git add s* README.md is covered by the same wait. The glob s* can name ssh, so the floor checks README.md as a host and looks it up; the remote answer now lands before the verdict. The floor still reads that word as a possible host, because it cannot always tell whether bash runs the glob. When the name has no DNS record, the resolver worker runs the ssh config route check before it publishes, so the same wait covers it: if both finish inside the budget, the first call gets the answer later calls get (a clean ssh config proves nothing, so such a name stays refused on every call, as on main).

The security spec sentence on pending dotted names (docs/system-specs/modules/security.md) is updated, and test/security_line_budget/ssh-self-dns-wait.txt records the +56 lines.

Backwards compatibility

Compatible: commands that were allowed stay allowed; the only change is that some first-call refusals become allows after a successful remote lookup.

Removes nothing: no rule, key, or function is removed; every refusal for a loopback answer, a failed lookup, or this host's own names stays.

Tests

test/test_denied_commands_security_dns_wait.py, all with a stub resolver (no network):

  • a remote name is allowed on the first check; a loopback alias is refused on the first check; a failed lookup stays refused;
  • a lookup still running when the wait ends is refused, and the answer that lands later is used by the next check;
  • on the event loop the first check refuses without waiting;
  • one check shares one wait budget (manual clock);
  • git add s* README.md, git add ss* README.md and a glued redirect are allowed on the first check;
  • a name with no DNS record gets on its first check the answer later checks give: allowed when ssh's config proves a remote route, refused with a clean config (the route check runs inside the same wait);
  • a self target after a glob stays refused: git add ss* localhost, ss* self.alias.example id, a find -exec s?h row, and s?h self.alias.example id.

Proof: PROVEN test/test_denied_commands_security_dns_wait.py::test_a_remote_name_is_allowed_on_the_first_check, test/test_denied_commands_security_dns_wait.py::test_a_file_name_after_a_glob_is_allowed_on_the_first_check[git add s* README.md], test/test_denied_commands_security_dns_wait.py::test_a_file_name_after_a_glob_is_allowed_on_the_first_check[git add ss* README.md], test/test_denied_commands_security_dns_wait.py::test_a_file_name_after_a_glob_is_allowed_on_the_first_check[git add ss* README.md>out.log], test/test_denied_commands_security_dns_wait.py::test_a_name_with_no_dns_record_gets_its_later_answer_on_the_first_check[True-None] (head cde99a9)

Determinism: the new file passed 20 of 20 runs at -n0, 10 of 10 at -n 4 beside test_denied_commands_security_own_host.py, 3 shuffled orders, and 6 PYTHONHASHSEED values. The related security files (ssh-self, own-host, hosts-file, facade, call sharing, ssh config route, gate liveness, rows, guidance, argv rules, and the other deny-gate files) pass. The flake-pattern ratchet and the repo semgrep rules pass on the diff.

Manual verification

Three calls of deny_gate.is_denied in one fresh process, with a stub resolver that answers after 0.1 s: git add s* README.md and ssh -T git@github.com are allowed on all three calls (main: refused on the first), and a loopback alias, a failed lookup and ssh localhost are refused on all three. With a 1 s stub answer, the first ssh -T git@github.com is refused (the wait ended) and the next is allowed.

Related Issues

Closes #37311

Sibling sweep

Swept: git grep -n "_resolved_host_verdict(" -- src/
Siblings: none -- _host_is_self is the only caller that answers a miss fail-closed, and it is the path changed here

Pattern harvest

Not generalizable: the fail-closed answer for a lookup that has not finished yet belongs to this one verdict cache.

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 (if applicable)
  • No secrets, credentials, or internal references in the diff

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 17, 2026 17:04
@buluoray
buluoray enabled auto-merge (squash) November 17, 2026 17:05
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor.py

  • src/kiro_crew/security/argv_floor_hosts.py

  • @buluoray posted a complete reasoning template for cde99a9.

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of cde99a9b5290a1bc9928d0eb6f537289b53e76cc — 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 does not.

First-Principles-Verdict: PASS

The DNS wait works at the mechanism level and reuses the existing condition, memo and event-loop check. The git add half fixes the symptom, not the cause. That is a note, not a block.

Notes

  • Item 2 — symptom-level: the cause is that the floor treats README.md after s* as an ssh host ("The floor still reads that word as a possible host"). The wait only helps when that file name resolves remote. A name with no DNS record and a clean ssh config is still "refused on every call, as on main", so git add s* README.md usually stays refused. Subtraction: remove the git add s* README.md claims from the Goal coverage and the tests, or say this fix sits at symptom level for that case.

What this change ships

Inventory (6 items) — 5 justified

Intent: let an agent's first ssh to a remote host succeed instead of hitting a false self-target refusal. FIX.

  1. First ssh to a new remote dotted name, off the event loop, is allowed on the first try — justified
  2. git add s* README.md allowed on the first try when the name resolves remote — symptom-level
  3. Off-loop gate checks can now block up to 0.5 s per call — justified
  4. Event-loop checks keep refusing at once with no wait — justified
  5. Security spec sentence on pending dotted names updated — justified
  6. New wait symbols re-exported through the argv_floor facade, plus the line-budget record — justified

[FIRST-PRINCIPLES-REVIEWED] cde99a9

Description read

[DESCRIPTION-READ] 495df514d61ea734d884efa9981090d5c4b74bc7cce4b0eb801207ac5363cf91

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 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of cde99a9b5290a1bc9928d0eb6f537289b53e76cc — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the wait is capped at 0.5 s for each check and never runs on the event loop. Every refusal that matters is unchanged: a loopback answer, a failed lookup and a lookup still running when the wait ends.

Notes

  • Checks that run on the gateway's event loop still refuse a new dotted host on the first call. If those checks are a common path, the first-try failure this PR targets will still happen for gateway-side checks.

[DESIGN-REVIEWED] cde99a9

Description read

[DESCRIPTION-READ] d4ae111534288f051c80ecaaef4a642465ee6d9297920533c6803e66dfd6e848

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 Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] cde99a9

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable cde99a9b5290a1bc9928d0eb6f537289b53e76cc false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of cde99a9b5290a1bc9928d0eb6f537289b53e76cc and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] cde99a9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt cde99a9b5290a1bc9928d0eb6f537289b53e76cc false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ human override accepted

@buluoray overrode this lane for cde99a9b5290a1bc9928d0eb6f537289b53e76cc via /ai-review override (this commit only).

[SCOPE-REVIEWED] cde99a9

@buluoray
buluoray force-pushed the crew/slack/ssh-self-dns-wait branch 2 times, most recently from 20adef9 to f1b9013 Compare November 17, 2026 17:34
@buluoray

Copy link
Copy Markdown
Contributor Author

span=003081c85db9

  • Allow-path tests depended on the 0.5 s wall-clock wait

fixed in f1b9013: the dns fixture sets _HOST_VERDICT_WAIT_SECS to FALLBACK_TIMEOUT_SECS, so every allow test ends its wait on the worker's signal, not on the clock.
The held-lookup test sets the budget to 0, so its refusal no longer depends on timing either.
Determinism: 20/20 at -n0, 10/10 at -n 4 beside the own-host file, 3 shuffled orders, flake ratchet green.

@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 Nov 17, 2026
The ssh-to-self floor refused the first ssh to a new dotted name while
the DNS lookup it had just started was still running, and allowed the
same command a moment later. `ssh -T git@github.com` failed on the first
try in a fresh process, and so did `git add s* README.md`, where the
glob can name an ssh program and the floor checks README.md as a host.

Off the event loop, the first check of a new dotted name now waits for
that lookup, at most half a second per check, and answers from it. A
loopback answer, a failed lookup, or a lookup still running when the
wait ends stays refused. The event loop itself never waits.

Closes #37311
@buluoray
buluoray force-pushed the crew/slack/ssh-self-dns-wait branch from f1b9013 to cde99a9 Compare November 17, 2026 17:41
@buluoray

Copy link
Copy Markdown
Contributor Author

Security Scope Review on cde99a9b5290: the two "newly refused" rows are the hash-order bug in #25848, not a change from this PR.

s* reads as ssh or scp depending on PYTHONHASHSEED, and the base and head runs each get their own seed. Pinned to one seed, base (ce21fa1f01d) and head give the same verdict for both rows, with DNS stubbed to "no such name" and to "temporary failure":

Seed s* reads as git add s* README.md base / head tar -czf out.tgz s* notes.txt base / head
2 ssh refused / refused refused / refused
3 scp allowed / allowed allowed / allowed

The lane's own reasoning reaches the same place: "ADJUDICATED: 15 candidates, 0 confirmed newly-refused", and every new exit path still returns fail_closed unless a not-self verdict landed. The fix for the seed dependence is #25993, which is next after this PR.

@buluoray

Copy link
Copy Markdown
Contributor Author

/ai-review override scope cde99a9 pre-existing #25848: agent: both newly-refused rows (git add s* README.md, tar s* notes.txt) flip with PYTHONHASHSEED on main too, because s* reads as ssh or scp by set order. Pinned to one seed, base and head give the same verdict: #38656 (comment)

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a pre-existing release (class pre-existing) for the scope AI finding on cde99a9b5290a1bc9928d0eb6f537289b53e76cc.

agent: both newly-refused rows (git add s* README.md, tar s* notes.txt) flip with PYTHONHASHSEED on main too, because s* reads as ssh or scp by set order. Pinned to one seed, base and head give the same verdict: #38656 (comment)

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

@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 Nov 17, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: cde99a9
  • What rule changed: the ssh-to-self floor's answer for the first check of a new dotted host name, in _resolved_host_verdict (argv_floor_hosts.py).
  • Before -> after (what was allowed/blocked, now): before, the first check refused while its DNS lookup was still running, and the same command was allowed a moment later. Now, off the event loop, the check waits for that lookup, at most 0.5 s per check, and answers from it. A loopback answer, a failed lookup, or a lookup still running after the wait is refused, as before. The event loop never waits.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a check off the event loop takes up to 0.5 s longer. No new allow: a host is allowed only after a lookup proves it is not this machine.
  • Evidence checked (which sandbox result proves it): test/test_denied_commands_security_dns_wait.py with a stub resolver: remote answer allowed on the first check; loopback alias, failed lookup, and a lookup still running after the wait all refused; event loop refuses without waiting; no-DNS-record name gets the same answer on the first and later checks. prove.py PROVEN on this head. Security Scope Review: 0 confirmed newly refused; its two rows are the hash-seed variance in security: ssh-self floor verdict depends on hash seed when a glob names several ssh verbs #25848 (comment 6956315617).
  • No regression:
    • Tools still work (which tools/commands were run, result): deny_gate.is_denied in a fresh process: ssh -T git@github.com and git add s* README.md allowed on the first call; ssh localhost id, a loopback alias and a failed lookup refused on every call.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data, or signature change; _resolved_host_verdict keeps its arguments and return type. The ssh-self, own-host, hosts-file, facade, call-sharing and ssh-config-route suites pass.
    • Existing tests (which suites passed on this head): Backend Tests (3.12, shards 1-8), Backend Tests (Windows, shards 1-8), Backend Tests (IPv6 on Linux and Windows, crew container, namespace sandbox), Denial Differential (Linux, macOS, Windows), Integration (in-process gateway), E2E Gateway Boot (Linux, Windows), Coverage Gate, Backend Ratchets & Boundaries, Flake Pattern Ratchet, Source Gates, SAST (Semgrep).
  • How to undo: revert this PR's one commit; nothing is migrated or stored.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh-to-self floor refuses the first ssh to a remote host while its DNS lookup is pending

1 participant