ssh: add integration test for configurable listen_addresses - #27679
pkawatkar14 wants to merge 6 commits into
Conversation
Add tests/ssh/test_ssh_listen_addresses.py to validate the new SSH_SERVER|POLICIES listen_addresses feature end-to-end on a live DUT: - Configure listen_addresses restricted to currently-assigned management/loopback addresses, omitting an assigned VLAN gateway address. - Confirm sshd binds (via ss) exactly to the configured addresses. - Confirm SSH succeeds through every configured address. - Confirm SSH fails through the intentionally omitted VLAN address, and that this is because sshd isn't listening there (not a routing/ACL issue). - Remove listen_addresses and confirm both IPv4/IPv6 wildcard listeners are restored, including on the previously omitted address. - Restore original SSH_SERVER policies in a fixture teardown, even on failure, so the DUT is never left inaccessible. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks! ---Powered by SONiC BuildBot
|
|
/azpw run Azure.sonic-buildimage |
|
Retrying failed(or canceled) jobs... |
|
Retrying failed(or canceled) stages in build 1209962: ✅Stage Test:
|
|
/azpw run Azure.sonic-buildimage |
|
Retrying failed(or canceled) jobs... |
|
No failed(or canceled) jobs found in completed stages. Only failed(or canceled) jobs in completed stages can be retried. Stages in progress: Test. Please wait for the stages to complete and then retry again. |
Address PR review feedback: minimal VS topologies without VLAN interfaces should skip this test rather than fail it, since there is no address available to use as the intentionally-omitted target. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azpw run Azure.sonic-mgmt |
|
Retrying failed(or canceled) jobs... |
|
Retrying failed(or canceled) stages in build 1217821: ✅Stage Test:
|
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
- Narrow topology marker to t0/t0-* since the test requires a VLAN gateway address; broader topologies just reach a skip. - Rename _wait_for_sshd_bindings to _sshd_bindings_match and drop its internal wait_until so callers control polling instead of doubling the wait at every call site. - Fix teardown short-circuit: wait for the actual expected binding set (restored addresses or wildcard) and log a warning instead of silently succeeding whenever original_listen_addresses was set; this also resolves the CodeQL 'return/break in finally' style concern since the finally block's result is no longer discarded silently. - Narrow pytest.raises(Exception) to the specific connection-refused failure modes (NoValidConnectionsError, socket.timeout, OSError) so an AuthenticationException regression is not silently swallowed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com>
23c1c64 to
48e63d5
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
The kvmtest-t0 CI job was failing: sonic-mgmt's test runner only has network reachability to the DUT's management network, not to VLAN/ data-plane addresses. The test was opening a live SSH connection to the omitted VLAN gateway address both to confirm it's rejected (masked by catching connection errors for the wrong reason) and, after restoring wildcard listeners, to confirm it's reachable again - that second connection attempt always failed regardless of sshd's actual bind state, since the address was never routable from the test runner in the first place. Replaced both live connection attempts with ss-based bind-state checks on the DUT (already used elsewhere in the test), which verify sshd's listen state without requiring the test runner to route to the VLAN network. Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
b5f82f6 to
013f96b
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Loopback address(es) included in keep_addresses are not routable from the sonic-mgmt test runner in kvmtest topologies (same reachability constraint already documented for the omitted VLAN address), so attempting a live SSH connection to them fails for reasons unrelated to sshd's actual bind state, causing spurious test failures. Only the management address is now SSH-verified live; Loopback bind state is validated via ss, consistent with how the VLAN address is checked. Signed-off-by: Pooja Kawatkar <pkawatkar@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
013f96b to
8411502
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Why I did it
Adds an integration test for Feature 29390131 (configurable OpenSSH
ListenAddresssupport), validating theSSH_SERVER|POLICIES > listen_addressesruntime behavior implemented in sonic-net/sonic-host-services (see linked PR) end-to-end on a live DUT.How I did it
tests/ssh/test_ssh_listen_addresses.py:t0/t0-*topologies since the test requires a VLAN with an assigned IPv4 gateway address; other topologies would only reach a skip.listen_addressesrestricted to the kept addresses.ss -lntp) exactly to the configured addresses, via_sshd_bindings_matchpolled bywait_untilat each call site.NoValidConnectionsError/socket.timeout/OSError), scoped narrowly so anAuthenticationExceptionregression is not silently swallowed.listen_addressesand confirms both IPv4/IPv6 wildcard listeners are restored, including reachability of the previously omitted address.SSH_SERVERpolicies in a fixture teardown (even on failure), so the DUT is never left inaccessible. Teardown waits for the actual expected binding set (restored addresses or wildcard) to converge and logs a warning rather than raising if it times out, so teardown never masks a failure from the test body.Review feedback addressed
pytest.mark.topology('any')totopology('t0', 't0-*').pytest.skip(...)(instead ofpytest_assert) when no VLAN gateway address is available._wait_for_sshd_bindingsto_sshd_bindings_match, removed its internalwait_until(it now returns a bool directly) so callers control polling instead of nesting two 30s waits.Trueimmediately whenever the original config hadlisten_addressesset, without ever confirming the restored bindings converged. This also resolved the CodeQL "return/break in finally" alert on the same block.with pytest.raises(Exception)to(paramiko.ssh_exception.NoValidConnectionsError, socket.timeout, OSError).How to verify it
Run
tests/ssh/test_ssh_listen_addresses.pyagainst at0-topology testbed.Related PRs: