Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f4bbf67
fix(tmachine): give guests a unique local IPv6 prefix
matthewgrossman Nov 18, 2026
04fd3d5
refactor(tmachine): share the K3s cluster reset tasks
matthewgrossman Nov 18, 2026
9fc829d
feat(tmachine): support IPv6 gateway Services and environment Helm va…
matthewgrossman Nov 18, 2026
aa13fdf
test(tmachine): add an IPv6-first dual-stack k3s environment
matthewgrossman Nov 18, 2026
9073847
ci(e2e): run k3s-ha conformance on the IPv6 k3s environment
matthewgrossman Nov 18, 2026
4ca02e1
refactor(tmachine): simplify the k3s installer's Helm command and gat…
matthewgrossman Nov 18, 2026
74e2f47
fix(tmachine): wait for the guest's IPv6 address in the IPv6 k3s setup
matthewgrossman Nov 18, 2026
e30f2e2
docs(testing): describe environment Helm values for k3s installers
matthewgrossman Nov 18, 2026
5278361
refactor(tmachine): slim the IPv6 k3s environment
matthewgrossman Nov 18, 2026
af09e54
Merge remote-tracking branch 'origin/main' into test/5698-k3s-ipv6-en…
matthewgrossman Nov 20, 2026
58b3615
Merge remote-tracking branch 'origin/main' into test/5698-k3s-ipv6-en…
matthewgrossman Nov 24, 2026
f833d39
test(conformance): skip the k3s-ha log-read tests on the IPv6 k3s env…
matthewgrossman Nov 24, 2026
b12d8ad
test(host-server): listen on IPv6 as well as IPv4
matthewgrossman Nov 24, 2026
efc556e
test(tmachine): reach the K3s node over IPv6 on an IPv6-first cluster
matthewgrossman Nov 24, 2026
f0139d3
test(features): check policy DNS AAAA answers on the IPv6 K3s environ…
matthewgrossman Nov 24, 2026
a3ed227
Merge remote-tracking branch 'origin/main' into test/5698-k3s-ipv6-en…
matthewgrossman Nov 25, 2026
79606e8
test(host-server): make the IPv6 listener dual-stack and fall back on…
matthewgrossman Nov 25, 2026
47931d4
test(features): check the synthetic address survives a policy reload
matthewgrossman Nov 25, 2026
c818d89
test(features): trim the policy-dns-ipv6 suite and installer comments
matthewgrossman Nov 25, 2026
d43fd75
test(tmachine): make the IPv6 K3s environment an IPv6-only cluster
matthewgrossman Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/e2e-suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
{"environment":"fedora-podman-rootless","installer":"rpm","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04","test_threads":4},
{"environment":"ubuntu-k3s","installer":"k3s","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04","test_threads":4},
{"environment":"ubuntu-k3s","installer":"k3s-ha","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04","test_threads":4},
{"environment":"ubuntu-k3s-ipv6","installer":"k3s-ha","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04","test_threads":4},
{"environment":"ubuntu-docker-rootful-cdi","installer":"deb","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"},
{"environment":"fedora-podman-rootful-cdi","installer":"rpm","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"},
{"environment":"fedora-podman-rootless-cdi","installer":"rpm","family":"features","package":"cdi","gateway":"openshell","runner":"ubuntu-24.04"},
Expand All @@ -115,6 +116,7 @@ jobs:
{"environment":"fedora-podman-rootful","installer":"rpm","family":"features","package":"routable-host-ip","gateway":"openshell","runner":"ubuntu-24.04"},
{"environment":"ubuntu-k3s","installer":"k3s","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
{"environment":"ubuntu-k3s","installer":"k3s-ha","family":"features","package":"routable-host-ip","gateway":"tmachine","runner":"ubuntu-24.04"},
{"environment":"ubuntu-k3s-ipv6","installer":"k3s-ha","family":"features","package":"policy-dns-ipv6","gateway":"tmachine","runner":"ubuntu-24.04"},
{"environment":"ubuntu-docker-rootful","installer":"deb","family":"features","package":"connect-ssh-supervision","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"},
Expand Down
7 changes: 7 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ supervisor. The address must be one the supervisor lets an IP literal reach.
Rootless Podman's is link-local and always blocked, so CI runs the suite on
Docker rootful, Podman rootful, and the `k3s` and `k3s-ha` installers.

The `policy-dns-ipv6` feature suite (`tests/suites/features/policy-dns-ipv6`)
checks that policy DNS answers AAAA queries with a synthetic address that
reaches only the policy endpoint's server. CI runs it on `ubuntu-k3s-ipv6`, an
IPv6-only cluster where sandboxes have no IPv4 route, so the default
`policy_dns_ipv6_egress = "auto"` turns on. The K3s installers set
`server.hostGatewayIP` to the node's IPv6 address there.

The `connect-ssh-supervision` feature suite
(`tests/suites/features/connect-ssh-supervision`) checks how `sandbox connect`
supervises its `ssh` process: it reconnects after losing the SSH transport and
Expand Down
1 change: 1 addition & 0 deletions tests/suites/conformance/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/suites/features/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/suites/features/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

[workspace]
resolver = "2"
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "routable-host-ip"]
members = ["cdi", "connect-ssh-supervision", "docker-updates", "host-gateway", "keycloak-provider-refresh", "kubernetes-updates", "oci-image", "policy-dns-ipv6", "routable-host-ip"]
22 changes: 22 additions & 0 deletions tests/suites/features/policy-dns-ipv6/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

[package]
name = "policy-dns-ipv6"
description = "Features suite: policy DNS answers AAAA queries with a synthetic address pinned to the policy endpoint"
version = "0.0.0"
edition = "2024"
rust-version = "1.94"
license = "Apache-2.0"
repository = "https://github.com/ai-openshell/openshell"
publish = false

[[test]]
name = "policy-dns-ipv6"
path = "tests/policy_dns_ipv6.rs"
harness = false

[dependencies]
host-server-support = { path = "../../../support/host-server" }
sandbox-clients-support = { path = "../../../support/sandbox-clients" }
openshell-testkit = { path = "../../../testkit/testkit" }
147 changes: 147 additions & 0 deletions tests/suites/features/policy-dns-ipv6/tests/policy_dns_ipv6.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! On an IPv6-only network, policy DNS answers AAAA queries for a policy
//! endpoint's host with a synthetic IPv6 address, and a connection to that
//! address reaches only the endpoint's upstream.
//!
//! The environment must give sandboxes no IPv4 default route, so the default
//! `policy_dns_ipv6_egress = "auto"` turns on, and set
//! `host.openshell.internal` to the test host's IPv6 address, as the `k3s`
//! installers do on `ubuntu-k3s-ipv6`.

use std::net::IpAddr;

use host_server_support::{HttpRecorder, TEST_HOST, allow_host, free_port};
use sandbox_clients_support::{Request, connect, http};
use testkit::Context;
use testkit::policy;

fn main() -> std::process::ExitCode {
testkit::main()
}

/// Sends an AAAA query for `argv[1]` to the sandbox's nameserver over UDP and
/// over TCP, without proxy variables, and prints the addresses of each answer
/// as one JSON line.
const DNS_CLIENT: &str = r#"
import json, os, random, socket, struct, sys

for name in [n for n in os.environ if n.lower().endswith("_proxy")]:
del os.environ[name]
server = next(l.split()[1] for l in open("/etc/resolv.conf") if l.startswith("nameserver"))
family = socket.AF_INET6 if ":" in server else socket.AF_INET
qid = random.randrange(65536)
query = struct.pack("!HHHHHH", qid, 0x0100, 1, 0, 0, 0)
query += b"".join(bytes([len(p)]) + p.encode() for p in sys.argv[1].split(".")) + b"\0"
query += struct.pack("!HH", 28, 1)

def skip_name(msg, i):
while msg[i]:
if msg[i] >= 0xC0:
return i + 2
i += msg[i] + 1
return i + 1

def addresses(msg):
_, flags, qd, an = struct.unpack("!HHHH", msg[:8])
i = 12
for _ in range(qd):
i = skip_name(msg, i) + 4
found = []
for _ in range(an):
i = skip_name(msg, i)
rtype, _, _, length = struct.unpack("!HHIH", msg[i:i + 10])
i += 10
if rtype == 28:
found.append(socket.inet_ntop(socket.AF_INET6, msg[i:i + length]))
i += length
return {"rcode": flags & 0xF, "addresses": found}

with socket.socket(family, socket.SOCK_DGRAM) as udp:
udp.settimeout(5)
udp.sendto(query, (server, 53))
udp_answer = addresses(udp.recv(4096))
with socket.create_connection((server, 53), timeout=5) as tcp:
tcp.sendall(struct.pack("!H", len(query)) + query)
data = b""
while len(data) < 2 or len(data) < 2 + struct.unpack("!H", data[:2])[0]:
chunk = tcp.recv(4096)
if not chunk:
break
data += chunk
tcp_answer = addresses(data[2:])
print(json.dumps({"udp": udp_answer, "tcp": tcp_answer}))
"#;

/// A native client gets the same synthetic AAAA answer over UDP and TCP, and
/// reaches the policy endpoint's server through it. The sandbox denies the
/// server's real address and the synthetic address on another port.
#[testkit::test]
async fn aaaa_answer_reaches_only_the_pinned_upstream(cx: &mut Context) -> testkit::Result {
let server = HttpRecorder::start("pinned").await?;
let mut allowed = policy::base();
allow_host(&mut allowed, "host_server", server.port);
let sandbox = cx.python_sandbox("dns6", allowed).create_ready().await?;

let reply = http(&sandbox, TEST_HOST, server.port, &Request::get("/by-name")).await?;
testkit::ensure!(
reply.status() == Some(200),
"request by name failed: {reply:?}"
);
let real_ip = server
.requests()
.first()
.and_then(|request| request.local_addr)
.ok_or_else(|| testkit::Error::msg("the host server didn't record its address"))?
.ip();
testkit::ensure!(
real_ip.is_ipv6(),
"{TEST_HOST} reached the host server at {real_ip}, not an IPv6 address"
);

let answers = sandbox
.exec(["python3", "-c", DNS_CLIENT, TEST_HOST])
.await?
.success()?
.last_json()?;
let udp = &answers["udp"]["addresses"];
testkit::ensure!(
udp == &answers["tcp"]["addresses"] && udp.as_array().is_some_and(|a| a.len() == 1),
"expected one AAAA address, the same over UDP and TCP: {answers}"
);
let synthetic: IpAddr = udp[0]
.as_str()
.and_then(|address| address.parse().ok())
.ok_or_else(|| testkit::Error::msg(format!("unparsable AAAA answer: {answers}")))?;
testkit::ensure!(
synthetic != real_ip,
"the AAAA answer is the host server's real address {real_ip}"
);

let host_header = format!("{TEST_HOST}:{}", server.port);
let by_address = Request::get("/by-synthetic-address").header("Host", host_header.as_str());
let synthetic = synthetic.to_string();
let reply = http(&sandbox, &synthetic, server.port, &by_address).await?;
testkit::ensure!(
reply.status() == Some(200),
"request to the synthetic address {synthetic} failed: {reply:?}"
);

let other_port = free_port().await?;
for (what, host, port) in [
("the real address", real_ip.to_string(), server.port),
(
"the synthetic address on another port",
synthetic,
other_port,
),
] {
let attempt = connect(&sandbox, &host, port).await?;
testkit::ensure!(
attempt.outcome.is_permission_denied(),
"expected a denial for {what} [{host}]:{port}; got {attempt:?}"
);
}
Ok(())
}
2 changes: 2 additions & 0 deletions tests/suites/unsupported.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
issue: https://github.com/ai-openshell/openshell/issues/5752
environments:
- ubuntu-k3s/k3s-ha
- ubuntu-k3s-ipv6/k3s-ha
- test: conformance::network_egress::fail_closed_middleware_blocks_uninspectable_traffic
issue: https://github.com/ai-openshell/openshell/issues/5752
environments:
- ubuntu-k3s/k3s-ha
- ubuntu-k3s-ipv6/k3s-ha
1 change: 1 addition & 0 deletions tests/support/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/support/host-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ openshell-testkit = { path = "../../testkit/testkit" }
rcgen = { version = "0.14.10", default-features = false, features = ["pem"] }
rustls = { version = "0.23", default-features = false, features = ["std", "tls12"] }
serde_json = "1"
socket2 = "0.6"
tokio = { version = "1.43", features = ["io-util", "net", "rt", "time"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["tls12"] }
tungstenite = "0.26"
Expand Down
4 changes: 3 additions & 1 deletion tests/support/host-server/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ pub(crate) async fn read_request(
loop {
if let Some((mut request, length)) = parse_request(buffer) {
buffer.drain(..length);
request.local_addr = local_addr;
// An IPv4 client on the IPv6 socket arrives on a mapped address.
request.local_addr =
local_addr.map(|addr| SocketAddr::new(addr.ip().to_canonical(), addr.port()));
return Some(request);
}
match tokio::time::timeout(READ_TIMEOUT, stream.read(&mut chunk)).await {
Expand Down
51 changes: 38 additions & 13 deletions tests/support/host-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
//! `host.openshell.internal`, and that record what arrived, so a test can
//! check what the supervisor forwarded upstream.
//!
//! The servers listen on every IPv4 host address, since drivers map
//! The servers listen on every host address, IPv6 and IPv4, since drivers map
//! `host.openshell.internal` to different ones, and stop when dropped. They
//! don't listen on IPv6, so `host.openshell.internal` must resolve to an IPv4
//! address of the test host. They run where the tests run, so a gateway whose
//! sandboxes can't reach the test host, such as one on a remote cluster, can't
//! run tests that use them.
//! listen on IPv4 only where the host has no IPv6. They run where the tests
//! run, so a gateway whose sandboxes can't reach the test host, such as one
//! on a remote cluster, can't run tests that use them.
//!
//! - [`HttpRecorder`] answers HTTP requests with a fixed body or a handler's
//! [`Response`], and records each parsed [`Request`]. It serves HTTPS with
Expand All @@ -28,10 +27,13 @@ mod tcp;
mod tls;
mod websocket;

use std::io::ErrorKind;
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr};
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;

use socket2::{Domain, Protocol, Socket, Type};
use testkit::sdk::raw::proto;
use testkit::{PYTHON_BINARIES, Result, ResultExt as _, policy};
use tokio::net::{TcpListener, TcpStream};
Expand Down Expand Up @@ -60,22 +62,45 @@ const WAIT_INTERVAL: Duration = Duration::from_millis(100);
const READ_TIMEOUT: Duration = Duration::from_secs(10);
const MAX_REQUEST: usize = 1024 * 1024;

/// Listen on every IPv4 host address at `port`, or at a random free port for 0.
/// Listen on every IPv6 and IPv4 host address at `port`, or on IPv4 only
/// where the host has no IPv6. Port 0 picks a random free port.
async fn bind(port: u16) -> Result<(TcpListener, u16)> {
let listener = TcpListener::bind(("0.0.0.0", port))
.await
.context(if port == 0 {
"bind a host server".to_string()
} else {
format!("bind a host server on port {port}")
})?;
let listener = match bind_dual_stack(port) {
Err(error)
if matches!(
error.kind(),
ErrorKind::AddrNotAvailable | ErrorKind::Unsupported
) =>
{
TcpListener::bind((Ipv4Addr::UNSPECIFIED, port)).await
}
result => result,
}
.context(if port == 0 {
"bind a host server".to_string()
} else {
format!("bind a host server on port {port}")
})?;
let port = listener
.local_addr()
.context("read the host server's address")?
.port();
Ok((listener, port))
}

/// An IPv6 listener that also accepts IPv4, whatever the host's default.
fn bind_dual_stack(port: u16) -> std::io::Result<TcpListener> {
let socket = Socket::new(Domain::IPV6, Type::STREAM, Some(Protocol::TCP))?;
socket.set_only_v6(false)?;
// As tokio's own bind does.
#[cfg(unix)]
socket.set_reuse_address(true)?;
socket.set_nonblocking(true)?;
socket.bind(&SocketAddr::from((Ipv6Addr::UNSPECIFIED, port)).into())?;
socket.listen(1024)?;
TcpListener::from_std(socket.into())
}

/// An accept loop on a new port that hands each connection to its own task,
/// counts the connections, and stops when dropped.
struct Server {
Expand Down
36 changes: 36 additions & 0 deletions tests/tmachine/ansible/playbooks/k3s-ipv6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Make the K3s base an IPv6-only cluster. The node keeps IPv4 for image pulls,
# but pods and Services get only IPv6 addresses. k3s.yaml left K3s
# stopped with no cluster state, so the next start creates it from this file.
---
- name: Configure IPv6-only K3s
hosts: all
become: true
gather_facts: false
tasks:
- name: Wait for SSH
ansible.builtin.wait_for_connection:

# K3s takes the node's addresses from the default routes. tmachine gives
# the guest a global IPv6 address through QEMU's ipv6-net option.
- name: Wait for a global IPv6 address
ansible.builtin.setup:
gather_subset: [network]
register: k3s_ipv6_facts
until: (k3s_ipv6_facts.ansible_facts.ansible_default_ipv6.scope | default('')) == "global"
retries: 10
delay: 2

- name: Write the IPv6-only K3s configuration
ansible.builtin.copy:
dest: /etc/rancher/k3s/config.yaml
owner: root
group: root
mode: "0644"
content: |
node-ip: {{ k3s_ipv6_facts.ansible_facts.ansible_default_ipv6.address }}
cluster-cidr: fd00:42::/56
service-cidr: fd00:43::/112
flannel-ipv6-masq: true
Loading
Loading