From 24a4e09e4fa18571d7eed17fcf408b92a3f0af8b Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Tue, 17 Nov 2026 09:21:07 -0800 Subject: [PATCH 1/4] test(features): check that a cached policy DNS address takes new connections A client that keeps a policy DNS address past the mapping's lifetime is refused on a host the policy allows (#4674). Add a features suite that resolves host.openshell.internal, connects, waits 45 s, and connects again to the same address, and run it on the Docker and Podman rows. Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 3 + tests/suites/features/Cargo.lock | 9 ++ tests/suites/features/Cargo.toml | 2 +- tests/suites/features/policy-dns/Cargo.toml | 17 +++ .../features/policy-dns/tests/policy_dns.rs | 124 ++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 tests/suites/features/policy-dns/Cargo.toml create mode 100644 tests/suites/features/policy-dns/tests/policy_dns.rs diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 6496d910af..17ac766e10 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -99,6 +99,9 @@ jobs: {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"host-gateway","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, + {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootless-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-userns-default","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"}, diff --git a/tests/suites/features/Cargo.lock b/tests/suites/features/Cargo.lock index 0d91b3a2a9..b84a109b1d 100644 --- a/tests/suites/features/Cargo.lock +++ b/tests/suites/features/Cargo.lock @@ -2505,6 +2505,15 @@ version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" +[[package]] +name = "policy-dns" +version = "0.0.0" +dependencies = [ + "host-server-support", + "openshell-testkit", + "tokio", +] + [[package]] name = "portable-atomic" version = "1.13.1" diff --git a/tests/suites/features/Cargo.toml b/tests/suites/features/Cargo.toml index a592b6f028..13bacff4f8 100644 --- a/tests/suites/features/Cargo.toml +++ b/tests/suites/features/Cargo.toml @@ -3,4 +3,4 @@ [workspace] resolver = "2" -members = ["cdi", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image"] +members = ["cdi", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "policy-dns"] diff --git a/tests/suites/features/policy-dns/Cargo.toml b/tests/suites/features/policy-dns/Cargo.toml new file mode 100644 index 0000000000..e93ef9cf58 --- /dev/null +++ b/tests/suites/features/policy-dns/Cargo.toml @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +[package] +name = "policy-dns" +description = "Features suite: addresses handed out by policy DNS on the Docker and Podman drivers" +version = "0.0.0" +edition = "2024" +rust-version = "1.94" +license = "Apache-2.0" +repository = "https://github.com/NVIDIA/OpenShell" +publish = false + +[dependencies] +host-server-support = { path = "../../../support/host-server" } +openshell-testkit = { path = "../../../testkit/testkit" } +tokio = { version = "1", features = ["time"] } diff --git a/tests/suites/features/policy-dns/tests/policy_dns.rs b/tests/suites/features/policy-dns/tests/policy_dns.rs new file mode 100644 index 0000000000..65aab14ca4 --- /dev/null +++ b/tests/suites/features/policy-dns/tests/policy_dns.rs @@ -0,0 +1,124 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! Policy DNS answers a sandbox's lookup of an allowed name with a synthetic +//! address. Clients keep resolved addresses in their own DNS caches (libcurl +//! for 60 s, the JDK for 30 s), so the address must keep taking new +//! connections for a while after the lookup. +//! +//! Only the Docker and Podman drivers offer policy DNS, so this is a features +//! suite. The upstream server runs on the test host +//! ([`host_server_support`]) and the sandbox reaches it as +//! `host.openshell.internal`. + +use std::time::Duration; + +use host_server_support::HttpRecorder; +use testkit::policy; +use testkit::sdk::raw::proto; +use testkit::{Context, PYTHON_BINARIES, Result, ResultExt as _, Sandbox}; + +const TEST_HOST: &str = "host.openshell.internal"; + +/// How long the client keeps the address before connecting again. It is past +/// the supervisor's current 30 s mapping ceiling and within the 60 s that +/// NVIDIA/OpenShell#4674 asks for. +const CACHED_ADDRESS_AGE: Duration = Duration::from_secs(45); + +/// Resolves `TEST_HOST` the way a client does and prints the synthetic IPv4 +/// address policy DNS handed out. +const RESOLVE: &str = r#" +import socket, sys +answers = socket.getaddrinfo(sys.argv[1], int(sys.argv[2]), socket.AF_INET, socket.SOCK_STREAM) +synthetic = [a[4][0] for a in answers if a[4][0].startswith(("198.18.", "198.19."))] +if not synthetic: + sys.exit(f"no policy DNS address for {sys.argv[1]}: {answers}") +print(synthetic[0]) +"#; + +/// Connects to the address in `argv[1]` on the port in `argv[2]`, as a client +/// with a cached answer does, and prints the response. +const CONNECT: &str = r#" +import socket, sys +address, port = sys.argv[1], int(sys.argv[2]) +with socket.create_connection((address, port), timeout=10) as conn: + conn.sendall(f"GET / HTTP/1.1\r\nHost: host.openshell.internal:{port}\r\nConnection: close\r\n\r\n".encode()) + response = b"" + while chunk := conn.recv(4096): + response += chunk +print(response.decode(errors="replace")) +"#; + +/// A new connection to a policy DNS address, made after the client has kept +/// the address for [`CACHED_ADDRESS_AGE`], reaches the allowed server while +/// the policy still allows the name. An address policy DNS never handed out +/// is refused. Regression test for NVIDIA/OpenShell#4674. +#[testkit::test] +async fn cached_address_takes_new_connections(cx: &mut Context) -> testkit::Result { + let marker = format!("policy-dns-{}", cx.run_id()); + let server = HttpRecorder::start(marker.clone()).await?; + let port = server.port.to_string(); + let sandbox = cx + .sandbox("pdns") + .image(testkit::python_image()) + .policy(policy(server.port)) + .command(["sleep", "infinity"]) + .create_ready() + .await?; + + let address = python(&sandbox, RESOLVE, TEST_HOST, &port) + .await? + .success() + .context("resolve the host through policy DNS")? + .stdout + .trim() + .to_string(); + + expect_response(&sandbox, &address, &port, &marker) + .await + .context(format!("connect to {address} right after the lookup"))?; + + tokio::time::sleep(CACHED_ADDRESS_AGE).await; + expect_response(&sandbox, &address, &port, &marker) + .await + .context(format!( + "connect to {address} {}s after the lookup, without a new lookup", + CACHED_ADDRESS_AGE.as_secs() + ))?; + + // The last address in the synthetic range, which a sandbox with one + // allowed name is never handed. + python(&sandbox, CONNECT, "198.19.255.254", &port) + .await? + .failure() + .context("connect to a synthetic address policy DNS never handed out")?; + Ok(()) +} + +async fn python( + sandbox: &Sandbox, + script: &str, + target: &str, + port: &str, +) -> Result { + sandbox.exec(["python3", "-c", script, target, port]).await +} + +/// Fail unless a new connection to `address` gets the server's response. +async fn expect_response(sandbox: &Sandbox, address: &str, port: &str, marker: &str) -> Result { + let output = python(sandbox, CONNECT, address, port).await?.success()?; + testkit::ensure!( + output.stdout.contains(marker), + "the client did not get the host server's response:\n{}{}", + output.stdout, + output.stderr + ); + Ok(()) +} + +/// Let the image's Python reach `TEST_HOST` on `port`. +fn policy(port: u16) -> proto::SandboxPolicy { + let mut policy = policy::base(); + policy::allow(&mut policy, "host_server", TEST_HOST, port, PYTHON_BINARIES); + policy +} From 7179707aee4e3d0ca4bfbe0c3542f148175ed15b Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Tue, 17 Nov 2026 09:43:41 -0800 Subject: [PATCH 2/4] test(conformance): move the cached policy DNS address test to conformance Policy DNS runs in the sandbox runtime every driver uses, so the test belongs in conformance and runs on every conformance row, including k3s and k3s-ha. Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 10 ++++++---- tests/suites/conformance/README.md | 1 + tests/suites/conformance/src/lib.rs | 1 + .../tests => conformance/src}/policy_dns.rs | 6 ++---- tests/suites/features/Cargo.lock | 13 ++----------- tests/suites/features/Cargo.toml | 2 +- tests/suites/features/policy-dns/Cargo.toml | 17 ----------------- 7 files changed, 13 insertions(+), 37 deletions(-) rename tests/suites/{features/policy-dns/tests => conformance/src}/policy_dns.rs (95%) delete mode 100644 tests/suites/features/policy-dns/Cargo.toml diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 17ac766e10..232d3234a1 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -18,6 +18,11 @@ name: E2E Suites on: workflow_call: inputs: + cancel-in-progress: + description: Cancel active runs in the same concurrency group + required: false + type: boolean + default: true family: description: Run only the rows of this family and the workspaces under it (for example conformance or drivers); empty runs every row required: false @@ -55,7 +60,7 @@ permissions: # workflow to avoid colliding with (and cancelling) the caller's other jobs. concurrency: group: ${{ github.workflow }}-e2e-suites-${{ inputs.family }}-${{ github.ref }} - cancel-in-progress: true + cancel-in-progress: ${{ inputs['cancel-in-progress'] }} jobs: # The rows live here, in one place. Add an environment or a suite by adding a @@ -99,9 +104,6 @@ jobs: {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"host-gateway","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"host-gateway","gateway":"tmachine","runner":"ubuntu-24.04"}, - {"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, - {"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, - {"environment":"fedora-podman-rootless","installer":"rpm","family":"features","package":"policy-dns","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootless-keycloak","installer":"rpm","family":"features","package":"keycloak-provider-refresh","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"fedora-podman-rootful-userns-default","installer":"rpm","family":"drivers/podman","gateway":"openshell","runner":"ubuntu-24.04"}, diff --git a/tests/suites/conformance/README.md b/tests/suites/conformance/README.md index a6edb02a7c..536150b693 100644 --- a/tests/suites/conformance/README.md +++ b/tests/suites/conformance/README.md @@ -13,6 +13,7 @@ nextest run the tests as the library's unit tests. The crate also builds the | `cli` | The same lifecycle through the `openshell` CLI: status, create, get, list, exec, stop, start, delete | | `persistent-workspace` | Files in `/sandbox` survive stop and start | | `policy-advisor` | `policy.local` accepts a proposed rule; a denied address or hostname yields one draft rule | +| `policy-dns` | A client that keeps a policy DNS address can open new connections to it after the lookup | | `file-transfer` | `sandbox upload` and `download`: round trips, file modes and symlinks outside the workspace, `.gitignore` filtering, workspace-escape and option-looking names, a large upload | | `credential-gating` | Provider credentials: admission of credentialed endpoints, REST body placeholders and rewriting, WebSocket binary frames, live policy binding | | `image` | A sandbox runs the default image or the one it is created from | diff --git a/tests/suites/conformance/src/lib.rs b/tests/suites/conformance/src/lib.rs index cabd7f3a3b..6fa7c726e9 100644 --- a/tests/suites/conformance/src/lib.rs +++ b/tests/suites/conformance/src/lib.rs @@ -17,6 +17,7 @@ mod labels; mod lifecycle; mod persistent_workspace; mod policy_advisor; +mod policy_dns; mod process; mod settings; mod smoke; diff --git a/tests/suites/features/policy-dns/tests/policy_dns.rs b/tests/suites/conformance/src/policy_dns.rs similarity index 95% rename from tests/suites/features/policy-dns/tests/policy_dns.rs rename to tests/suites/conformance/src/policy_dns.rs index 65aab14ca4..5f7223d1fd 100644 --- a/tests/suites/features/policy-dns/tests/policy_dns.rs +++ b/tests/suites/conformance/src/policy_dns.rs @@ -6,10 +6,8 @@ //! for 60 s, the JDK for 30 s), so the address must keep taking new //! connections for a while after the lookup. //! -//! Only the Docker and Podman drivers offer policy DNS, so this is a features -//! suite. The upstream server runs on the test host -//! ([`host_server_support`]) and the sandbox reaches it as -//! `host.openshell.internal`. +//! The upstream server runs on the test host ([`host_server_support`]) and +//! the sandbox reaches it as `host.openshell.internal`. use std::time::Duration; diff --git a/tests/suites/features/Cargo.lock b/tests/suites/features/Cargo.lock index b84a109b1d..b8fcdca5bd 100644 --- a/tests/suites/features/Cargo.lock +++ b/tests/suites/features/Cargo.lock @@ -620,9 +620,9 @@ dependencies = [ [[package]] name = "ctutils" -version = "0.4.6" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe3e9d21d39e6f39ff46e03d5b621424f88ee23d8a1672c6bfc9ccc7f2da4f6a" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" dependencies = [ "cmov", ] @@ -2505,15 +2505,6 @@ version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" -[[package]] -name = "policy-dns" -version = "0.0.0" -dependencies = [ - "host-server-support", - "openshell-testkit", - "tokio", -] - [[package]] name = "portable-atomic" version = "1.13.1" diff --git a/tests/suites/features/Cargo.toml b/tests/suites/features/Cargo.toml index 13bacff4f8..a592b6f028 100644 --- a/tests/suites/features/Cargo.toml +++ b/tests/suites/features/Cargo.toml @@ -3,4 +3,4 @@ [workspace] resolver = "2" -members = ["cdi", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "policy-dns"] +members = ["cdi", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image"] diff --git a/tests/suites/features/policy-dns/Cargo.toml b/tests/suites/features/policy-dns/Cargo.toml deleted file mode 100644 index e93ef9cf58..0000000000 --- a/tests/suites/features/policy-dns/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -[package] -name = "policy-dns" -description = "Features suite: addresses handed out by policy DNS on the Docker and Podman drivers" -version = "0.0.0" -edition = "2024" -rust-version = "1.94" -license = "Apache-2.0" -repository = "https://github.com/NVIDIA/OpenShell" -publish = false - -[dependencies] -host-server-support = { path = "../../../support/host-server" } -openshell-testkit = { path = "../../../testkit/testkit" } -tokio = { version = "1", features = ["time"] } From 980b9572cfb504b221479fe565e4a047d9ff6a43 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Tue, 17 Nov 2026 12:56:50 -0800 Subject: [PATCH 3/4] chore: restore files from the branch base The move to conformance restored the workflow and the features lockfile from a newer main. Restore them from the branch base so the PR only adds the conformance test. Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 7 +------ tests/suites/features/Cargo.lock | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 232d3234a1..6496d910af 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -18,11 +18,6 @@ name: E2E Suites on: workflow_call: inputs: - cancel-in-progress: - description: Cancel active runs in the same concurrency group - required: false - type: boolean - default: true family: description: Run only the rows of this family and the workspaces under it (for example conformance or drivers); empty runs every row required: false @@ -60,7 +55,7 @@ permissions: # workflow to avoid colliding with (and cancelling) the caller's other jobs. concurrency: group: ${{ github.workflow }}-e2e-suites-${{ inputs.family }}-${{ github.ref }} - cancel-in-progress: ${{ inputs['cancel-in-progress'] }} + cancel-in-progress: true jobs: # The rows live here, in one place. Add an environment or a suite by adding a diff --git a/tests/suites/features/Cargo.lock b/tests/suites/features/Cargo.lock index b8fcdca5bd..0d91b3a2a9 100644 --- a/tests/suites/features/Cargo.lock +++ b/tests/suites/features/Cargo.lock @@ -620,9 +620,9 @@ dependencies = [ [[package]] name = "ctutils" -version = "0.4.8" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +checksum = "fe3e9d21d39e6f39ff46e03d5b621424f88ee23d8a1672c6bfc9ccc7f2da4f6a" dependencies = [ "cmov", ] From 9c71fa71b097a62a1c18024e5470a18beb2af8a0 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Tue, 17 Nov 2026 13:05:30 -0800 Subject: [PATCH 4/4] test(conformance): wait 33 s before reusing the policy DNS address The host alias mapping expires exactly 30 s after the lookup, so 33 s is enough to show the expiry and keeps the test shorter. The comment explains the choice. Signed-off-by: Matthew Grossman --- tests/suites/conformance/src/policy_dns.rs | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/suites/conformance/src/policy_dns.rs b/tests/suites/conformance/src/policy_dns.rs index 5f7223d1fd..862bac89d1 100644 --- a/tests/suites/conformance/src/policy_dns.rs +++ b/tests/suites/conformance/src/policy_dns.rs @@ -18,10 +18,26 @@ use testkit::{Context, PYTHON_BINARIES, Result, ResultExt as _, Sandbox}; const TEST_HOST: &str = "host.openshell.internal"; -/// How long the client keeps the address before connecting again. It is past -/// the supervisor's current 30 s mapping ceiling and within the 60 s that -/// NVIDIA/OpenShell#4674 asks for. -const CACHED_ADDRESS_AGE: Duration = Duration::from_secs(45); +/// How long the client keeps the address before connecting again. +/// +/// Policy DNS gives a host alias such as `TEST_HOST` a mapping that expires +/// exactly 30 s after the lookup (`MAX_MAPPING_TTL` in +/// `openshell-supervisor-network`), with no grace period. Waiting 33 s +/// outlasts that mapping by a few seconds, so the test fails while #4674 is +/// open whatever the timing of the exec calls. The wait starts after the +/// first connection returns, so the address is older still when the test +/// reuses it. +/// +/// A shorter wait would need a mapping with a shorter lifetime. Other names +/// take their upstream DNS TTL, but a conformance test can't control the +/// sandbox's upstream resolver, and the host server is reachable only through +/// the host alias. +/// +/// This wait checks that the address outlasts the current 30 s limit. It +/// doesn't check a particular longer lifetime, such as the 60 s libcurl +/// caches for. A unit test with an injected clock should cover the exact +/// lifetime the fix guarantees. +const CACHED_ADDRESS_AGE: Duration = Duration::from_secs(33); /// Resolves `TEST_HOST` the way a client does and prints the synthetic IPv4 /// address policy DNS handed out.