Skip to content

test(cron): pin the ssh-self floor's host state for backup@host - #20885

Closed
iamwhatever wants to merge 1 commit into
mainfrom
fix/20595-ssh-self-test-pin
Closed

iamwhatever wants to merge 1 commit into
mainfrom
fix/20595-ssh-self-test-pin

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The two ssh -o ConnectTimeout=10 backup@host uptime cases in test/test_mcp_cron_security.py pass or fail on the cron vet's own logic, never on the CI runner's host-name state.

test_an_assignment_nothing_reads_is_ordinary[ssh -o ConnectTimeout=10 backup@host uptime] went red on four unrelated branches on 2026-10-15 (Linux 3.12, shard 3) with AssertionError: should allow: 'ssh -o ConnectTimeout=10 backup@host uptime', refused by sandbox-escape-ssh-self component=argv-floor. Main passed the same shard on the same base.

Why it matters

Any PR whose shard happens to run this case first in a worker can go red with nothing to fix in its own diff. Its author pays for the triage and the rerun.

Not a goal

  • Changing the ssh-self floor, its pending answer, or the own-address worker in src/. This is a test-only change.
  • Pinning ssh commands in other test modules.
  • The two descriptor-close tests in this file that red on clean main on this host in some orders (see Tests).

What changed (motivation → approach → change)

The two backup@host tests pin the floor's view of this machine, so host is a remote machine on every runner.

Symptom. On the failing CI worker, the network floor shows this test ran the process's first ssh check: the own-host seed's UDP probes and the enrichment worker's lookups of the runner's own name. It never asked DNS about host. So the refusal came from the hosts-file layer, before the DNS verdict layer.

Cause. For a dotless target, argv_floor._host_is_self asks _hosts_file_verdict first. The gate reads the hosts-file key (it holds the netlink-published flag and the own-name set), parses /etc/hosts in the call, then reads the key again. The first ssh check also starts the kirocrew-own-host-resolve thread, and its netlink publish changes that key. When the publish lands inside the parse, the gate answers pending and the command is refused.

Change. A _ssh_target_host_is_remote fixture in test/test_mcp_cron_security.py pins the floor's view of this machine on argv_floor, in the same slots the ssh-self tests in test/test_denied_commands_security.py pin:

Slot Pinned to Effect
_OWN_HOST_NAMES_CACHE frozenset({"127.0.0.1"}) no runner name, no seed probe
_NETLINK_ADDRS_PUBLISHED, _OWN_HOST_RESOLVE_DONE True put back with the own names as one state
_OWN_HOST_RESOLVE_NEXT_TRY inf the enrichment thread never starts
_hosts_file_paths () no in-call /etc/hosts parse
_resolved_host_verdict not self no DNS lookup, no cached verdict

test_vet_shell_command_allows_smuggling_lookalikes and test_an_assignment_nothing_reads_is_ordinary use it. These are the only two tests in the file that reach the floor's hosts-file or DNS layer (traced over the whole file). The floor still runs: localhost and loopback addresses are judged before these inputs.

Backwards compatibility

Compatible: test-only; no product code, config or public surface changes.

Removes nothing: every assertion stays, and the fixture only pins state for the two tests that use it.

Tests

No assertion changes. The two tests above take the fixture.

Determinism proof on Linux, Python 3.12. The parent column is clean main at a7903730df. The PR column is this commit's patch (git patch-id unchanged across rebases onto later main; none of those main commits touch src/kiro_crew/security/argv_floor.py, security/__init__.py, security/denied_rules.py, mcp_cron.py, conftest.py or this file). The forced conditions are throwaway -p plugins, not committed; source below.

On the current base e33caf76f3 the file collects 674 tests: main's new engines sensitive leaf adds two test_every_sensitive_entry_refuses_with_one_neutral_wording cases. All 674 pass, also under the forced publish, and the forced-delay node passes.

Run main (parent) this PR
Forced delay: 0.5 s inside _parse_hosts_file, real worker and real /etc/hosts, failing node alone 5/5 red, same test_mcp_cron_security.py:819 refusal text as CI 5/5 green
Forced publish: _publish_netlink_addresses inside every in-call parse, whole file 2 failed (exactly the two backup@host cases), 670 passed 672 passed
Whole file, -n0, 20 runs 20/20, 672 passed each
-n 4 --dist loadgroup --max-worker-restart=2 beside test_deny_guidance.py and test_argv_floor_inline_and_brace_scope.py, 10 runs 10/10, 1063 passed each (two tests deselected, see below)
Shuffled orders, seeds 20595, 4242, 31337, 777, 90210 both changed tests green in all five
Forced publish plus shuffled order, seeds 20595 and 4242 672 passed each

Two unchanged tests in this file, test_script_leaf_swap_never_reads_the_target and test_fifo_substituted_during_open_is_nonblocking_and_refused, fail with DID NOT RAISE <class 'OSError'> on this host under xdist and in seeds 31337 and 777. Clean main fails them the same way (8 of 10 -n 4 runs, seed 31337 3/3, seed 777 2/2): at the failing assert, the closed descriptor number is held by a pipe. The -n 4 runs deselect them.

Probe plugins and commands
# f12_force_delay.py: hold the in-call parse so the real worker's publish lands inside it
import time

def pytest_configure(config):
    from kiro_crew.security import argv_floor
    real_parse = argv_floor._parse_hosts_file
    def slow_parse(*args, **kwargs):
        table = real_parse(*args, **kwargs)
        time.sleep(0.5)
        return table
    argv_floor._parse_hosts_file = slow_parse
# f12_force_publish.py: an own-address publication lands inside every in-call parse
import itertools
_SEQ = itertools.count(1)

def pytest_configure(config):
    from kiro_crew.security import argv_floor
    real_parse = argv_floor._parse_hosts_file
    def racing_parse(*args, **kwargs):
        table = real_parse(*args, **kwargs)
        argv_floor._publish_netlink_addresses({f"192.0.2.{next(_SEQ) % 250 + 1}"})
        return table
    argv_floor._parse_hosts_file = racing_parse
python -m pytest -n0 -p no:cacheprovider -p f12_force_delay -qq "test/test_mcp_cron_security.py::test_an_assignment_nothing_reads_is_ordinary[ssh -o ConnectTimeout=10 backup@host uptime]"
python -m pytest -n0 -p no:cacheprovider -p f12_force_publish -qq test/test_mcp_cron_security.py

Manual verification

A throwaway test with the fixture applied: ssh -o ConnectTimeout=10 backup@<target> uptime is refused with sandbox-escape-ssh-self for localhost, 127.0.0.1 and [::1], and allowed for host (4 passed).

Related Issues

Fixes #20595

Related: #17035, #19969

Pattern harvest

Rule candidate: review-prompt
Pattern: a test that sends an ssh, scp, sftp or rsync command through is_denied or _vet_shell_command without pinning argv_floor's host state (own names, hosts file, DNS verdict) gets a verdict that depends on the runner.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 15, 2026 15:53
@iamwhatever
iamwhatever requested a review from buluoray October 15, 2026 15:53
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision b881a15983ced61982ee13a2d3884bb745d69417 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] b881a15

Description read

[DESCRIPTION-READ] a3645ef56c72b9b1d49f83d3f04bb6dfe2377a6f12f8de77c84625da3db079cf

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 Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] b881a15

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

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

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b881a15

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

@iamwhatever

Copy link
Copy Markdown
Contributor Author

The five Backend Tests reds on 281814e (Linux shards 1-4, Windows shard 5) are main's, not this PR's. Each fails only test/test_acp_bindings.py::test_the_member_set_is_the_frozen_inventory and ::test_each_member_keeps_its_kind_shape_and_owner[approve_tool], the same two node ids main's own CI run fails on 59389d3 (https://github.com/kirodotdev/KiroCrew/actions/runs/38763437454). Tracked in #20893, fixed by #20894. This PR touches only test/test_mcp_cron_security.py; it will be rebased onto main once #20894 lands.

The two cron vet tests that allow `ssh -o ConnectTimeout=10 backup@host
uptime` read the runner's own host state through the ssh-self argv
floor: its host name, hosts file, resolver, and the address table a
background thread publishes after the first ssh check of the process.
When that publication lands while the gate parses the hosts file, the
dotless target gets the pending answer and the command is refused, so
the verdict depended on which test of a worker ran the first ssh check.

A fixture pins that state on argv_floor for both tests: own names
without `host` together with their published and resolved flags, no
enrichment retry, no hosts file, and a not-self DNS verdict. The floor
still runs, and loopback targets stay refused.

Fixes #20595
@iamwhatever
iamwhatever force-pushed the fix/20595-ssh-self-test-pin branch from 281814e to b881a15 Compare October 15, 2026 22:59
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Rebased onto main e33caf7, which carries the census fix #20902 (#20894 was closed as its duplicate). Same patch (git patch-id unchanged), new head b881a15; CI re-running.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

The four Linux Backend Tests reds on b881a15 come from CI's leaf lane ("leaf changed files, pass 1/3"). That lane repeats this PR's changed test file with -n auto. The failing test is test_script_leaf_swap_never_reads_the_target, an unchanged test in the same file: DID NOT RAISE <class 'OSError'> in _assert_descriptors_closed. Clean main 93617e9 fails it 3 of 3 times under the same command. It is a closed-descriptor check that races fd-number reuse; recorded in #21001. The full corpus in those shards passed.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Closing in favour of #20964, which fixes the root cause in argv_floor.py; this PR only pinned the test seam and would hide that race.

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 15, 2026
@bolichen97
bolichen97 deleted the fix/20595-ssh-self-test-pin branch November 6, 2026 07:33
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.

Flaky: test_mcp_cron_security::test_an_assignment_nothing_reads_is_ordinary ssh-self refuses backup@host (Linux)

1 participant