Skip to content

Commit c67e467

Browse files
test(features): use the host's outbound address when routable-host-ip arrives on loopback
Signed-off-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent 86a2569 commit c67e467

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎TESTING.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,11 @@ the node's address.
658658
The `routable-host-ip` feature suite (`tests/suites/features/routable-host-ip`)
659659
checks that a policy endpoint whose host is an IP literal reaches that address,
660660
with or without `allowed_ips`. The test reaches a host server by
661-
`host.openshell.internal`, then uses the address that request arrived at, which
662-
must be one the supervisor lets an IP literal reach. Rootless Podman's is
663-
link-local and always blocked, and Docker Desktop's is loopback, so CI runs the
664-
suite on Docker rootful, Podman rootful, and the `k3s` and `k3s-ha`
665-
installers.
661+
`host.openshell.internal`, then uses the address that request arrived at, or
662+
the host's outbound address when it arrived on loopback from a host-network
663+
supervisor. The address must be one the supervisor lets an IP literal reach.
664+
Rootless Podman's is link-local and always blocked, so CI runs the suite on
665+
Docker rootful, Podman rootful, and the `k3s` and `k3s-ha` installers.
666666

667667
The `connect-ssh-supervision` feature suite
668668
(`tests/suites/features/connect-ssh-supervision`) checks how `sandbox connect`

‎tests/suites/features/routable-host-ip/tests/routable_host_ip.rs‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
//! The servers run on the test host. The sandbox can't learn the host's
88
//! address, since policy DNS answers it with a synthetic one, so the test
99
//! reaches a server by `host.openshell.internal` first and takes the address
10-
//! the server saw the request arrive at. Not conformance, because
10+
//! the server saw the request arrive at. A supervisor on the host network
11+
//! (Docker's and Podman's default) arrives on loopback, which an IP literal
12+
//! can't reach, so the test uses the host's outbound address instead; that
13+
//! supervisor shares it. Not conformance, because
1114
//! that address must be one the supervisor lets an IP literal reach: rootless
1215
//! Podman's is link-local, which is always blocked.
1316
//!
1417
//! Ported from the `proxy_egress_pipeline` e2e test of IP literals, which
1518
//! used two support containers on the e2e network instead.
1619
20+
use std::net::{IpAddr, Ipv4Addr, UdpSocket};
21+
1722
use host_server_support::{HttpRecorder, TEST_HOST};
1823
use sandbox_clients_support::{Request, http};
1924
use testkit::policy;
@@ -52,17 +57,17 @@ async fn ip_literal_endpoints_reach_the_host(cx: &mut Context) -> testkit::Resul
5257
"request to {TEST_HOST}:{} failed: {reply:?}",
5358
explicit.port
5459
);
55-
let host_ip = explicit
60+
let arrived_on = explicit
5661
.requests()
5762
.first()
5863
.and_then(|request| request.local_addr)
5964
.ok_or_else(|| testkit::Error::msg("the host server didn't record its address"))?
6065
.ip();
61-
// Docker Desktop relays the host gateway through a host-side proxy.
62-
testkit::ensure!(
63-
!host_ip.is_loopback(),
64-
"requests to {TEST_HOST} arrive at the host on {host_ip}, which a sandbox can't reach"
65-
);
66+
let host_ip = if arrived_on.is_loopback() {
67+
outbound_address()?
68+
} else {
69+
arrived_on
70+
};
6671
let ip = host_ip.to_string();
6772
let prefix = if host_ip.is_ipv4() { 32 } else { 128 };
6873

@@ -96,3 +101,16 @@ async fn ip_literal_endpoints_reach_the_host(cx: &mut Context) -> testkit::Resul
96101
}
97102
Ok(())
98103
}
104+
105+
/// The test host's address on its default route. Connecting a UDP socket
106+
/// sends nothing; it only picks the route.
107+
fn outbound_address() -> testkit::Result<IpAddr> {
108+
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0))?;
109+
socket.connect((Ipv4Addr::new(192, 0, 2, 1), 9))?;
110+
let address = socket.local_addr()?.ip();
111+
testkit::ensure!(
112+
!address.is_loopback() && !address.is_unspecified(),
113+
"the test host has no outbound address, only {address}"
114+
);
115+
Ok(address)
116+
}

0 commit comments

Comments
 (0)