Skip to content

test(bastion): cover ownership-rejection reuse-guard branch (#1065 follow-up) - #1067

Merged
rysweet merged 1 commit into
mainfrom
audit/1065-cover-ownership-rejection
Jul 24, 2026
Merged

test(bastion): cover ownership-rejection reuse-guard branch (#1065 follow-up)#1067
rysweet merged 1 commit into
mainfrom
audit/1065-cover-ownership-rejection

Conversation

@rysweet

@rysweet rysweet commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Quality-audit follow-up to merged PR #1065

Merged PR #1065 hardened existing_live_tunnel_port with a process-tree ownership check so azlin code will not reuse a tunnel port when a stale/recycled registry pid points at a port now listened on by an unrelated process.

Finding (quality audit, MEDIUM — test gap): The security-critical rejection branch (Ok(false) => None) had no test. test_existing_live_tunnel_port_reuses_live_and_ignores_dead covers the reuse path (Ok(true)) and the pid-dead early exit, but the dead case returns before the ownership check ever runs — so the hijack defense that motivated the PR was untested and regression-prone.

Fix

Adds test_existing_live_tunnel_port_rejects_unowned_listener:

  • Our own process owns the loopback listener for port.
  • The registry entry credits a separate, live child pid whose downward process tree cannot contain our (parent) pid → ownership resolves to not owned → reuse must be refused.
  • Guarded to assert only where listener ownership is inspectable (ss/lsof//proc), matching the documented platform fallback.

Validation

  • New test passes deterministically across 5 consecutive runs.
  • Full azlin bastion suite: 106 passed, 0 failed (was 105; +1).
  • cargo build and cargo clippy clean for the changed file (0 warnings).
  • Additive test only — no production behavior changed.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…llow-up)

existing_live_tunnel_port gained a process-tree ownership check (PR #1065)
so a stale/recycled-pid entry whose recorded port is listened on by an
unrelated process is not reused. Only the Ok(true) reuse path and the
early pid-dead exit were tested; the security-critical Ok(false)
rejection branch (port listening + pid alive but listener owned by an
unrelated process tree) had no coverage, leaving the hijack defense
regression-prone.

Add test_existing_live_tunnel_port_rejects_unowned_listener: our own
process owns the loopback listener while the registry credits a separate
live child pid whose downward process tree cannot contain it, so
ownership resolves to not-owned and reuse must be refused. Guarded to
assert only where listener ownership is inspectable (ss/lsof//proc),
matching the documented platform fallback. Deterministic across 5 runs;
no production behavior changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rysweet
rysweet merged commit 409dcbd into main Jul 24, 2026
14 checks passed
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.

1 participant