test(bastion): cover ownership-rejection reuse-guard branch (#1065 follow-up) - #1067
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quality-audit follow-up to merged PR #1065
Merged PR #1065 hardened
existing_live_tunnel_portwith a process-tree ownership check soazlin codewill 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_deadcovers 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:port.ss/lsof//proc), matching the documented platform fallback.Validation
azlinbastion suite: 106 passed, 0 failed (was 105; +1).cargo buildandcargo clippyclean for the changed file (0 warnings).Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com