From f4bbf67ac0d38125e2a4e57b22e17cc9488cf268 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 12:11:14 -0800 Subject: [PATCH 01/13] fix(tmachine): give guests a unique local IPv6 prefix QEMU user networking defaults to the site-local fec0::/64, which Linux ranks below any global address. On a dual-stack K3s guest the node then sends to IPv6 Services from flannel's address and never gets the reply. Signed-off-by: Matthew Grossman --- tests/tmachine/src/qemu/vm.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/tmachine/src/qemu/vm.rs b/tests/tmachine/src/qemu/vm.rs index 354d04c53a..000d9d1779 100644 --- a/tests/tmachine/src/qemu/vm.rs +++ b/tests/tmachine/src/qemu/vm.rs @@ -225,8 +225,14 @@ fn command( .arg("virtio-blk-pci,drive=rootfs,bootindex=1") .arg("-device") .arg("virtio-rng-pci") + // A unique local IPv6 prefix instead of user networking's default + // site-local fec0::/64. Linux ranks a site-local source below any + // global address, so on a dual-stack K3s guest it picks flannel's + // address to reach an IPv6 Service and never gets the reply. .arg("-netdev") - .arg(format!("user,id=net0,hostfwd=tcp:127.0.0.1:{ssh_port}-:22")) + .arg(format!( + "user,id=net0,ipv6-net=fd00:10::/64,hostfwd=tcp:127.0.0.1:{ssh_port}-:22" + )) .arg("-device") .arg("virtio-net-pci,netdev=net0"); From 04fd3d5cc36f3654ba9844aeab5cdab2f33586c3 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 12:11:15 -0800 Subject: [PATCH 02/13] refactor(tmachine): share the K3s cluster reset tasks Signed-off-by: Matthew Grossman --- .../tmachine/ansible/playbooks/k3s-reset.yaml | 32 +++++++++++++++++++ tests/tmachine/ansible/playbooks/k3s.yaml | 29 ++--------------- 2 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 tests/tmachine/ansible/playbooks/k3s-reset.yaml diff --git a/tests/tmachine/ansible/playbooks/k3s-reset.yaml b/tests/tmachine/ansible/playbooks/k3s-reset.yaml new file mode 100644 index 0000000000..51bebcab8f --- /dev/null +++ b/tests/tmachine/ansible/playbooks/k3s-reset.yaml @@ -0,0 +1,32 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# A setup layer is cached across runs, so it must not carry cluster +# credentials: every disk built on it would share one CA, token and admin +# kubeconfig. Stop K3s and delete the state it created, keeping the containerd +# image store (agent/containerd) and the K3s data directory. The next start +# generates fresh credentials and creates the cluster again from the K3s +# configuration. +--- +- name: Stop K3s and its containers + ansible.builtin.command: + argv: [/usr/local/bin/k3s-killall.sh] + changed_when: true + +- name: Remove the K3s credentials and cluster state + ansible.builtin.shell: | + set -eu + cd /var/lib/rancher/k3s + rm -rf server/tls server/cred server/db server/token server/agent-token server/node-token + find agent -maxdepth 1 -type f \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' \) -delete + rm -rf /etc/rancher/node/password /etc/rancher/k3s/k3s.yaml /var/lib/kubelet/pods /var/lib/cni + changed_when: true + +- name: Check no K3s credentials remain + ansible.builtin.shell: | + find /var/lib/rancher/k3s/server /var/lib/rancher/k3s/agent /etc/rancher/k3s /etc/rancher/node \ + -maxdepth 1 \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' -o -name token -o -name password \ + -o -name 'k3s.yaml' -o -name '*.db' -o -name tls -o -name cred \) -print + register: k3s_leftover_credentials + changed_when: false + failed_when: k3s_leftover_credentials.stdout | length > 0 diff --git a/tests/tmachine/ansible/playbooks/k3s.yaml b/tests/tmachine/ansible/playbooks/k3s.yaml index 07b0de85d8..03484cc4b4 100644 --- a/tests/tmachine/ansible/playbooks/k3s.yaml +++ b/tests/tmachine/ansible/playbooks/k3s.yaml @@ -72,30 +72,5 @@ environment: DESIRED_VERSION: "v{{ helm_version }}" - # This layer is cached across runs, so it must not carry cluster - # credentials: every disk built on it would share one CA, token and admin - # kubeconfig. Stop K3s and delete the state it created on first start, - # keeping the containerd image store (agent/containerd) and the K3s data - # directory. The next start generates fresh credentials. - - name: Stop K3s and its containers - ansible.builtin.command: - argv: [/usr/local/bin/k3s-killall.sh] - changed_when: true - - - name: Remove the K3s credentials and cluster state - ansible.builtin.shell: | - set -eu - cd /var/lib/rancher/k3s - rm -rf server/tls server/cred server/db server/token server/agent-token server/node-token - find agent -maxdepth 1 -type f \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' \) -delete - rm -rf /etc/rancher/node/password /etc/rancher/k3s/k3s.yaml /var/lib/kubelet/pods /var/lib/cni - changed_when: true - - - name: Check no K3s credentials remain - ansible.builtin.shell: | - find /var/lib/rancher/k3s/server /var/lib/rancher/k3s/agent /etc/rancher/k3s /etc/rancher/node \ - -maxdepth 1 \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' -o -name token -o -name password \ - -o -name 'k3s.yaml' -o -name '*.db' -o -name tls -o -name cred \) -print - register: k3s_leftover_credentials - changed_when: false - failed_when: k3s_leftover_credentials.stdout | length > 0 + - name: Reset the K3s cluster state + ansible.builtin.include_tasks: k3s-reset.yaml From 9fc829d325a04947ad018f2028e8adde024742a1 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 12:11:24 -0800 Subject: [PATCH 03/13] feat(tmachine): support IPv6 gateway Services and environment Helm values in the k3s installers Signed-off-by: Matthew Grossman --- .../ansible/playbooks/openshell-k3s-ha.yaml | 4 +- .../ansible/playbooks/openshell-k3s.yaml | 55 +++++++++++++------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s-ha.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s-ha.yaml index efcc736d49..3518cc1a7f 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s-ha.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s-ha.yaml @@ -64,7 +64,7 @@ ansible.builtin.lineinfile: path: /etc/hosts regexp: '\sopenshell\.openshell\.svc\.cluster\.local$' - line: "{{ k3s_gateway_address.stdout.split(':')[0] }} openshell.openshell.svc.cluster.local" + line: "{{ k3s_gateway_ip }} openshell.openshell.svc.cluster.local" - name: Read chart client TLS Secret ansible.builtin.command: @@ -103,4 +103,4 @@ apply: become: false vars: - openshell_client_gateway_endpoint: "https://openshell.openshell.svc.cluster.local:{{ k3s_gateway_address.stdout.split(':')[1] }}" + openshell_client_gateway_endpoint: "https://openshell.openshell.svc.cluster.local:{{ k3s_gateway_port }}" diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml index 5b68bc0067..f31c2e3cc8 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml @@ -66,7 +66,9 @@ # address must be the one of the node the tests run on. QEMU user # networking gives every boot the same guest address (10.0.2.15), so the # value stays valid when the disk is reused. - # The node can also list an IPv6 address after it, so take the IPv4 one. + # A dual-stack node also lists an IPv6 address, first on an IPv6-first + # cluster. Take the IPv4 one: the servers tests start for sandboxes to + # reach (tests/support/host-server) listen on IPv4 only. - name: Discover the K3s node address ansible.builtin.command: argv: @@ -133,6 +135,14 @@ mode: "0600" content: "{{ openshell_k3s_helm_values_overlay | default('{}') }}" + # An environment adapts the chart to its cluster by writing values to + # /etc/openshell-test/helm-values.yaml before the installer runs (for + # example playbooks/k3s-ipv6.yaml). They apply last. + - name: Check for environment Helm values + ansible.builtin.stat: + path: /etc/openshell-test/helm-values.yaml + register: openshell_k3s_environment_values + - name: Install Agent Sandbox ansible.builtin.command: argv: @@ -168,20 +178,19 @@ - name: Install OpenShell Helm chart ansible.builtin.command: - argv: - - /usr/local/bin/helm - - install - - openshell - - /var/lib/openshell/artifacts/helm-chart.tgz - - --namespace - - openshell - - --create-namespace - - --values - - /var/lib/openshell/artifacts/values.yaml - - --values - - /var/lib/openshell/artifacts/values-overlay.yaml - - --wait - - --timeout=5m + argv: >- + {{ + [ + '/usr/local/bin/helm', 'install', 'openshell', + '/var/lib/openshell/artifacts/helm-chart.tgz', + '--namespace', 'openshell', '--create-namespace', + '--values', '/var/lib/openshell/artifacts/values.yaml', + '--values', '/var/lib/openshell/artifacts/values-overlay.yaml', + ] + + (['--values', '/etc/openshell-test/helm-values.yaml'] + if openshell_k3s_environment_values.stat.exists else []) + + ['--wait', '--timeout=5m'] + }} environment: KUBECONFIG: /etc/rancher/k3s/k3s.yaml @@ -196,17 +205,27 @@ - get - service - openshell - - --output=jsonpath={.spec.clusterIP}:{.spec.ports[?(@.name=="grpc")].port} + - --output=jsonpath={.spec.clusterIP} {.spec.ports[?(@.name=="grpc")].port} register: k3s_gateway_address changed_when: false # Rejects headless Services (ClusterIP "None") and a missing grpc port. + # The ClusterIP is IPv6 on a cluster whose primary family is IPv6. - name: Require a gateway Service address ansible.builtin.assert: that: - - k3s_gateway_address.stdout is match('^[0-9.]+:[0-9]+$') + - k3s_gateway_address.stdout is match('^([0-9.]+|[0-9a-f:]+) [0-9]+$') fail_msg: "Unexpected gateway Service address: {{ k3s_gateway_address.stdout }}" + - name: Record the gateway Service address + ansible.builtin.set_fact: + k3s_gateway_ip: "{{ k3s_gateway_address.stdout.split()[0] }}" + k3s_gateway_port: "{{ k3s_gateway_address.stdout.split()[1] }}" + k3s_gateway_authority: >- + {{ ('[' ~ k3s_gateway_address.stdout.split()[0] ~ ']') + if ':' in k3s_gateway_address.stdout.split()[0] + else k3s_gateway_address.stdout.split()[0] }}:{{ k3s_gateway_address.stdout.split()[1] }} + # Deployment readiness doesn't establish that the controller reconciles # Sandboxes. This checks the installed cluster; a booted guest restarts the # controller, so the test runner checks again after it boots @@ -218,6 +237,6 @@ hosts: all gather_facts: false vars: - openshell_client_gateway_endpoint: "http://{{ k3s_gateway_address.stdout }}" + openshell_client_gateway_endpoint: "http://{{ k3s_gateway_authority }}" roles: - openshell_client From aa13fdfc320b0d0e9adc8383e32fdd54d162bd00 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 12:11:24 -0800 Subject: [PATCH 04/13] test(tmachine): add an IPv6-first dual-stack k3s environment Signed-off-by: Matthew Grossman --- .../tmachine/ansible/playbooks/k3s-ipv6.yaml | 151 ++++++++++++++++++ tests/tmachine/config.nix | 6 + 2 files changed, 157 insertions(+) create mode 100644 tests/tmachine/ansible/playbooks/k3s-ipv6.yaml diff --git a/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml new file mode 100644 index 0000000000..aa8e622c7d --- /dev/null +++ b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml @@ -0,0 +1,151 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Turn the K3s base into a dual-stack cluster with IPv6 first, so Pods and +# Services get an IPv6 address first and OpenShell runs over IPv6. +# +# k3s.yaml ran first and reset the cluster, so the next start creates it again +# from this configuration. This playbook starts it once to check it, then +# resets it the same way. It also writes the Helm values the chart needs on an +# IPv6 cluster to /etc/openshell-test/helm-values.yaml, which the k3s +# installers (openshell-k3s.yaml) apply. +--- +- name: Configure IPv6-first dual-stack K3s + hosts: all + become: true + gather_facts: false + vars: + k3s_ipv6_cluster_cidr: fd00:42::/56,10.42.0.0/16 + k3s_ipv6_service_cidr: fd00:43::/112,10.43.0.0/16 + tasks: + - name: Wait for SSH + ansible.builtin.wait_for_connection: + + - name: Gather the guest addresses + ansible.builtin.setup: + gather_subset: [network] + + # K3s takes the node's addresses from the default routes, IPv6 first for + # an IPv6-first cluster. + - name: Require a global IPv6 address + ansible.builtin.assert: + that: + - ansible_facts.default_ipv6.address is defined + - ansible_facts.default_ipv6.scope == "global" + fail_msg: >- + The guest needs a global IPv6 address with a default route, not + {{ ansible_facts.default_ipv6 | default('none') }}; tmachine sets + ipv6-net on QEMU user networking for this. + + - name: Create the K3s configuration directory + ansible.builtin.file: + path: /etc/rancher/k3s/config.yaml.d + state: directory + owner: root + group: root + mode: "0755" + + # The order of each list makes IPv6 the primary family. Flannel + # masquerades IPv6 Pod traffic leaving the cluster, as it does for IPv4. + - name: Write the dual-stack K3s configuration + ansible.builtin.copy: + dest: /etc/rancher/k3s/config.yaml.d/50-ipv6-dual-stack.yaml + owner: root + group: root + mode: "0644" + content: | + cluster-cidr: {{ k3s_ipv6_cluster_cidr }} + service-cidr: {{ k3s_ipv6_service_cidr }} + flannel-ipv6-masq: true + + - name: Create the test configuration directory + ansible.builtin.file: + path: /etc/openshell-test + state: directory + owner: root + group: root + mode: "0755" + + - name: Write the Helm values for an IPv6 cluster + ansible.builtin.copy: + dest: /etc/openshell-test/helm-values.yaml + owner: root + group: root + mode: "0644" + content: | + gateway: + listenAddress: "::" + supervisor: + listenAddress: "::" + + - name: Start K3s + ansible.builtin.systemd: + name: k3s + state: started + + - name: Wait for K3s + ansible.builtin.command: + argv: + - /usr/local/bin/k3s + - kubectl + - wait + - --for=condition=Ready + - node + - --all + - --timeout=120s + register: k3s_ready + changed_when: false + until: k3s_ready.rc == 0 + retries: 12 + delay: 5 + + - name: Wait for CoreDNS + ansible.builtin.command: + argv: + - /usr/local/bin/k3s + - kubectl + - --namespace=kube-system + - rollout + - status + - deployment/coredns + - --timeout=180s + register: k3s_coredns + changed_when: false + until: k3s_coredns.rc == 0 + retries: 30 + delay: 5 + + - name: Read the cluster's address families + ansible.builtin.command: + argv: + - /usr/local/bin/k3s + - kubectl + - --namespace=kube-system + - get + - service + - kube-dns + - --output=jsonpath={.spec.clusterIPs} + register: k3s_dns_addresses + changed_when: false + + - name: Require an IPv6-first dual-stack Service + ansible.builtin.assert: + that: + - k3s_dns_addresses.stdout | from_json | length == 2 + - (k3s_dns_addresses.stdout | from_json)[0] is search(':') + - (k3s_dns_addresses.stdout | from_json)[1] is match('^[0-9.]+$') + fail_msg: "kube-dns has addresses {{ k3s_dns_addresses.stdout }}" + + # Tests reach the gateway's Service from the node, which fails when the + # node picks a source address that replies can't reach. + - name: Check the node reaches a Pod through an IPv6 Service + ansible.builtin.uri: + url: "http://[{{ (k3s_dns_addresses.stdout | from_json)[0] }}]:9153/metrics" + timeout: 10 + register: k3s_ipv6_service + until: k3s_ipv6_service.status == 200 + retries: 6 + delay: 5 + + - name: Reset the K3s cluster state + ansible.builtin.include_tasks: k3s-reset.yaml diff --git a/tests/tmachine/config.nix b/tests/tmachine/config.nix index 5a41618bf4..115d717eaa 100644 --- a/tests/tmachine/config.nix +++ b/tests/tmachine/config.nix @@ -107,6 +107,12 @@ let inputs.keycloak_realm_file = "../../scripts/keycloak-realm.json"; }; }; + # A dual-stack cluster with IPv6 first, and the chart's IPv6 listen + # addresses, for running the k3s suites over IPv6. + ipv6 = { + bases = [ "ubuntu-k3s" ]; + setup.playbooks = [ "ansible/playbooks/k3s-ipv6.yaml" ]; + }; # Hardware-free CDI fixtures, for the cdi suite. cdi = { bases = dockerBases ++ podmanBases; From 9073847065edd3ddcfd383a062b41d3110927cc8 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 12:57:34 -0800 Subject: [PATCH 05/13] ci(e2e): run k3s-ha conformance on the IPv6 k3s environment Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index 86073d5b56..4e862fb77e 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -92,6 +92,7 @@ jobs: {"environment":"fedora-podman-rootless","installer":"rpm","family":"conformance","package":"conformance","gateway":"openshell","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04"}, {"environment":"ubuntu-k3s","installer":"k3s-ha","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04"}, + {"environment":"ubuntu-k3s-ipv6","installer":"k3s-ha","family":"conformance","package":"conformance","gateway":"tmachine","runner":"ubuntu-24.04"}, {"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"}, From 4ca02e161c83a017bae87a77d04648dfd7172338 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 14:29:41 -0800 Subject: [PATCH 06/13] refactor(tmachine): simplify the k3s installer's Helm command and gateway address Create an empty environment Helm values file when the environment has none, so the Helm command is a plain list. Name the gateway IP and port before bracketing an IPv6 address. Signed-off-by: Matthew Grossman --- .../ansible/playbooks/openshell-k3s.yaml | 66 ++++++++++++------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml index f31c2e3cc8..a1a43c3f8a 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml @@ -137,11 +137,24 @@ # An environment adapts the chart to its cluster by writing values to # /etc/openshell-test/helm-values.yaml before the installer runs (for - # example playbooks/k3s-ipv6.yaml). They apply last. - - name: Check for environment Helm values - ansible.builtin.stat: - path: /etc/openshell-test/helm-values.yaml - register: openshell_k3s_environment_values + # example playbooks/k3s-ipv6.yaml). They apply last. Other environments + # get an empty file. + - name: Create the test configuration directory + ansible.builtin.file: + path: /etc/openshell-test + state: directory + owner: root + group: root + mode: "0755" + + - name: Ensure environment Helm values exist + ansible.builtin.copy: + dest: /etc/openshell-test/helm-values.yaml + content: "{}\n" + force: false + owner: root + group: root + mode: "0644" - name: Install Agent Sandbox ansible.builtin.command: @@ -178,19 +191,22 @@ - name: Install OpenShell Helm chart ansible.builtin.command: - argv: >- - {{ - [ - '/usr/local/bin/helm', 'install', 'openshell', - '/var/lib/openshell/artifacts/helm-chart.tgz', - '--namespace', 'openshell', '--create-namespace', - '--values', '/var/lib/openshell/artifacts/values.yaml', - '--values', '/var/lib/openshell/artifacts/values-overlay.yaml', - ] - + (['--values', '/etc/openshell-test/helm-values.yaml'] - if openshell_k3s_environment_values.stat.exists else []) - + ['--wait', '--timeout=5m'] - }} + argv: + - /usr/local/bin/helm + - install + - openshell + - /var/lib/openshell/artifacts/helm-chart.tgz + - --namespace + - openshell + - --create-namespace + - --values + - /var/lib/openshell/artifacts/values.yaml + - --values + - /var/lib/openshell/artifacts/values-overlay.yaml + - --values + - /etc/openshell-test/helm-values.yaml + - --wait + - --timeout=5m environment: KUBECONFIG: /etc/rancher/k3s/k3s.yaml @@ -217,14 +233,16 @@ - k3s_gateway_address.stdout is match('^([0-9.]+|[0-9a-f:]+) [0-9]+$') fail_msg: "Unexpected gateway Service address: {{ k3s_gateway_address.stdout }}" + # A URL needs brackets around an IPv6 address, for example + # http://[fd00:43::a]:8080; without them the port can't be told apart. - name: Record the gateway Service address + vars: + gateway_ip: "{{ k3s_gateway_address.stdout.split()[0] }}" + gateway_port: "{{ k3s_gateway_address.stdout.split()[1] }}" ansible.builtin.set_fact: - k3s_gateway_ip: "{{ k3s_gateway_address.stdout.split()[0] }}" - k3s_gateway_port: "{{ k3s_gateway_address.stdout.split()[1] }}" - k3s_gateway_authority: >- - {{ ('[' ~ k3s_gateway_address.stdout.split()[0] ~ ']') - if ':' in k3s_gateway_address.stdout.split()[0] - else k3s_gateway_address.stdout.split()[0] }}:{{ k3s_gateway_address.stdout.split()[1] }} + k3s_gateway_ip: "{{ gateway_ip }}" + k3s_gateway_port: "{{ gateway_port }}" + k3s_gateway_authority: "{{ ('[' ~ gateway_ip ~ ']') if ':' in gateway_ip else gateway_ip }}:{{ gateway_port }}" # Deployment readiness doesn't establish that the controller reconciles # Sandboxes. This checks the installed cluster; a booted guest restarts the From 74e2f47169cdba563f7b8f866be97b15cadf60c8 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 14:29:42 -0800 Subject: [PATCH 07/13] fix(tmachine): wait for the guest's IPv6 address in the IPv6 k3s setup Signed-off-by: Matthew Grossman --- tests/tmachine/ansible/playbooks/k3s-ipv6.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml index aa8e622c7d..6a709430f6 100644 --- a/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml +++ b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml @@ -21,9 +21,15 @@ - name: Wait for SSH ansible.builtin.wait_for_connection: + # SSH can be up before the guest has its IPv6 address, so wait for it. - name: Gather the guest addresses 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 + failed_when: false # K3s takes the node's addresses from the default routes, IPv6 first for # an IPv6-first cluster. From e30f2e2a9d6af22458e0236c479c3f59f734da89 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 14:29:42 -0800 Subject: [PATCH 08/13] docs(testing): describe environment Helm values for k3s installers Signed-off-by: Matthew Grossman --- TESTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/TESTING.md b/TESTING.md index 5a8a3942aa..7736feae39 100644 --- a/TESTING.md +++ b/TESTING.md @@ -607,6 +607,12 @@ installer applies it to the gateway's own file: with no overrides leaves it untouched. - `k3s` installers ignore the file. +K3s environments adapt the Helm chart instead: a playbook that runs before the +installer writes values to `/etc/openshell-test/helm-values.yaml`, and the +`k3s` and `k3s-ha` installers apply them after their own values. +`ubuntu-k3s-ipv6` uses this to set the gateway and supervisor `listenAddress` +to `::`. + `tests/tmachine/ansible/roles/openshell_gateway/files/merge-gateway-toml.py` does the work. Each key in the overrides replaces the same key in the table, or is added to it, and a table the file lacks is appended. The rest of the file, From 527836130ba4c069368e77fc95e4dfa03e3006e9 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Wed, 18 Nov 2026 14:45:03 -0800 Subject: [PATCH 09/13] refactor(tmachine): slim the IPv6 k3s environment The IPv6 setup now only writes the K3s configuration, so the cluster is created on its first start and needs no reset, and k3s.yaml is unchanged. The k3s installer sets the gateway and supervisor listen addresses to :: when the node's first address is IPv6, instead of reading Helm values the environment wrote. Signed-off-by: Matthew Grossman --- TESTING.md | 6 - .../tmachine/ansible/playbooks/k3s-ipv6.yaml | 139 +----------------- .../tmachine/ansible/playbooks/k3s-reset.yaml | 32 ---- tests/tmachine/ansible/playbooks/k3s.yaml | 29 +++- .../ansible/playbooks/openshell-k3s.yaml | 30 +--- tests/tmachine/config.nix | 4 +- 6 files changed, 43 insertions(+), 197 deletions(-) delete mode 100644 tests/tmachine/ansible/playbooks/k3s-reset.yaml diff --git a/TESTING.md b/TESTING.md index 7736feae39..5a8a3942aa 100644 --- a/TESTING.md +++ b/TESTING.md @@ -607,12 +607,6 @@ installer applies it to the gateway's own file: with no overrides leaves it untouched. - `k3s` installers ignore the file. -K3s environments adapt the Helm chart instead: a playbook that runs before the -installer writes values to `/etc/openshell-test/helm-values.yaml`, and the -`k3s` and `k3s-ha` installers apply them after their own values. -`ubuntu-k3s-ipv6` uses this to set the gateway and supervisor `listenAddress` -to `::`. - `tests/tmachine/ansible/roles/openshell_gateway/files/merge-gateway-toml.py` does the work. Each key in the overrides replaces the same key in the table, or is added to it, and a table the file lacks is appended. The rest of the file, diff --git a/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml index 6a709430f6..ce5a3995c6 100644 --- a/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml +++ b/tests/tmachine/ansible/playbooks/k3s-ipv6.yaml @@ -1,157 +1,34 @@ # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -# Turn the K3s base into a dual-stack cluster with IPv6 first, so Pods and -# Services get an IPv6 address first and OpenShell runs over IPv6. -# -# k3s.yaml ran first and reset the cluster, so the next start creates it again -# from this configuration. This playbook starts it once to check it, then -# resets it the same way. It also writes the Helm values the chart needs on an -# IPv6 cluster to /etc/openshell-test/helm-values.yaml, which the k3s -# installers (openshell-k3s.yaml) apply. +# Make the K3s base a dual-stack cluster with IPv6 first. k3s.yaml left K3s +# stopped with no cluster state, so the next start creates it from this file. --- - name: Configure IPv6-first dual-stack K3s hosts: all become: true gather_facts: false - vars: - k3s_ipv6_cluster_cidr: fd00:42::/56,10.42.0.0/16 - k3s_ipv6_service_cidr: fd00:43::/112,10.43.0.0/16 tasks: - name: Wait for SSH ansible.builtin.wait_for_connection: - # SSH can be up before the guest has its IPv6 address, so wait for it. - - name: Gather the guest addresses + # 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 - failed_when: false - # K3s takes the node's addresses from the default routes, IPv6 first for - # an IPv6-first cluster. - - name: Require a global IPv6 address - ansible.builtin.assert: - that: - - ansible_facts.default_ipv6.address is defined - - ansible_facts.default_ipv6.scope == "global" - fail_msg: >- - The guest needs a global IPv6 address with a default route, not - {{ ansible_facts.default_ipv6 | default('none') }}; tmachine sets - ipv6-net on QEMU user networking for this. - - - name: Create the K3s configuration directory - ansible.builtin.file: - path: /etc/rancher/k3s/config.yaml.d - state: directory - owner: root - group: root - mode: "0755" - - # The order of each list makes IPv6 the primary family. Flannel - # masquerades IPv6 Pod traffic leaving the cluster, as it does for IPv4. - name: Write the dual-stack K3s configuration ansible.builtin.copy: - dest: /etc/rancher/k3s/config.yaml.d/50-ipv6-dual-stack.yaml + dest: /etc/rancher/k3s/config.yaml owner: root group: root mode: "0644" content: | - cluster-cidr: {{ k3s_ipv6_cluster_cidr }} - service-cidr: {{ k3s_ipv6_service_cidr }} + cluster-cidr: fd00:42::/56,10.42.0.0/16 + service-cidr: fd00:43::/112,10.43.0.0/16 flannel-ipv6-masq: true - - - name: Create the test configuration directory - ansible.builtin.file: - path: /etc/openshell-test - state: directory - owner: root - group: root - mode: "0755" - - - name: Write the Helm values for an IPv6 cluster - ansible.builtin.copy: - dest: /etc/openshell-test/helm-values.yaml - owner: root - group: root - mode: "0644" - content: | - gateway: - listenAddress: "::" - supervisor: - listenAddress: "::" - - - name: Start K3s - ansible.builtin.systemd: - name: k3s - state: started - - - name: Wait for K3s - ansible.builtin.command: - argv: - - /usr/local/bin/k3s - - kubectl - - wait - - --for=condition=Ready - - node - - --all - - --timeout=120s - register: k3s_ready - changed_when: false - until: k3s_ready.rc == 0 - retries: 12 - delay: 5 - - - name: Wait for CoreDNS - ansible.builtin.command: - argv: - - /usr/local/bin/k3s - - kubectl - - --namespace=kube-system - - rollout - - status - - deployment/coredns - - --timeout=180s - register: k3s_coredns - changed_when: false - until: k3s_coredns.rc == 0 - retries: 30 - delay: 5 - - - name: Read the cluster's address families - ansible.builtin.command: - argv: - - /usr/local/bin/k3s - - kubectl - - --namespace=kube-system - - get - - service - - kube-dns - - --output=jsonpath={.spec.clusterIPs} - register: k3s_dns_addresses - changed_when: false - - - name: Require an IPv6-first dual-stack Service - ansible.builtin.assert: - that: - - k3s_dns_addresses.stdout | from_json | length == 2 - - (k3s_dns_addresses.stdout | from_json)[0] is search(':') - - (k3s_dns_addresses.stdout | from_json)[1] is match('^[0-9.]+$') - fail_msg: "kube-dns has addresses {{ k3s_dns_addresses.stdout }}" - - # Tests reach the gateway's Service from the node, which fails when the - # node picks a source address that replies can't reach. - - name: Check the node reaches a Pod through an IPv6 Service - ansible.builtin.uri: - url: "http://[{{ (k3s_dns_addresses.stdout | from_json)[0] }}]:9153/metrics" - timeout: 10 - register: k3s_ipv6_service - until: k3s_ipv6_service.status == 200 - retries: 6 - delay: 5 - - - name: Reset the K3s cluster state - ansible.builtin.include_tasks: k3s-reset.yaml diff --git a/tests/tmachine/ansible/playbooks/k3s-reset.yaml b/tests/tmachine/ansible/playbooks/k3s-reset.yaml deleted file mode 100644 index 51bebcab8f..0000000000 --- a/tests/tmachine/ansible/playbooks/k3s-reset.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -# A setup layer is cached across runs, so it must not carry cluster -# credentials: every disk built on it would share one CA, token and admin -# kubeconfig. Stop K3s and delete the state it created, keeping the containerd -# image store (agent/containerd) and the K3s data directory. The next start -# generates fresh credentials and creates the cluster again from the K3s -# configuration. ---- -- name: Stop K3s and its containers - ansible.builtin.command: - argv: [/usr/local/bin/k3s-killall.sh] - changed_when: true - -- name: Remove the K3s credentials and cluster state - ansible.builtin.shell: | - set -eu - cd /var/lib/rancher/k3s - rm -rf server/tls server/cred server/db server/token server/agent-token server/node-token - find agent -maxdepth 1 -type f \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' \) -delete - rm -rf /etc/rancher/node/password /etc/rancher/k3s/k3s.yaml /var/lib/kubelet/pods /var/lib/cni - changed_when: true - -- name: Check no K3s credentials remain - ansible.builtin.shell: | - find /var/lib/rancher/k3s/server /var/lib/rancher/k3s/agent /etc/rancher/k3s /etc/rancher/node \ - -maxdepth 1 \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' -o -name token -o -name password \ - -o -name 'k3s.yaml' -o -name '*.db' -o -name tls -o -name cred \) -print - register: k3s_leftover_credentials - changed_when: false - failed_when: k3s_leftover_credentials.stdout | length > 0 diff --git a/tests/tmachine/ansible/playbooks/k3s.yaml b/tests/tmachine/ansible/playbooks/k3s.yaml index 03484cc4b4..07b0de85d8 100644 --- a/tests/tmachine/ansible/playbooks/k3s.yaml +++ b/tests/tmachine/ansible/playbooks/k3s.yaml @@ -72,5 +72,30 @@ environment: DESIRED_VERSION: "v{{ helm_version }}" - - name: Reset the K3s cluster state - ansible.builtin.include_tasks: k3s-reset.yaml + # This layer is cached across runs, so it must not carry cluster + # credentials: every disk built on it would share one CA, token and admin + # kubeconfig. Stop K3s and delete the state it created on first start, + # keeping the containerd image store (agent/containerd) and the K3s data + # directory. The next start generates fresh credentials. + - name: Stop K3s and its containers + ansible.builtin.command: + argv: [/usr/local/bin/k3s-killall.sh] + changed_when: true + + - name: Remove the K3s credentials and cluster state + ansible.builtin.shell: | + set -eu + cd /var/lib/rancher/k3s + rm -rf server/tls server/cred server/db server/token server/agent-token server/node-token + find agent -maxdepth 1 -type f \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' \) -delete + rm -rf /etc/rancher/node/password /etc/rancher/k3s/k3s.yaml /var/lib/kubelet/pods /var/lib/cni + changed_when: true + + - name: Check no K3s credentials remain + ansible.builtin.shell: | + find /var/lib/rancher/k3s/server /var/lib/rancher/k3s/agent /etc/rancher/k3s /etc/rancher/node \ + -maxdepth 1 \( -name '*.crt' -o -name '*.key' -o -name '*.kubeconfig' -o -name token -o -name password \ + -o -name 'k3s.yaml' -o -name '*.db' -o -name tls -o -name cred \) -print + register: k3s_leftover_credentials + changed_when: false + failed_when: k3s_leftover_credentials.stdout | length > 0 diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml index a1a43c3f8a..ff7a0cb0e7 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml @@ -93,9 +93,12 @@ changed_when: false failed_when: k3s_nodes.rc != 0 or k3s_nodes.stdout_lines | length != 1 - - name: Select the K3s node IPv4 address + # On an IPv6-first cluster (playbooks/k3s-ipv6.yaml) the node lists its + # IPv6 address first, and the gateway and supervisor must listen on IPv6. + - name: Select the K3s node IPv4 address and listen address ansible.builtin.set_fact: k3s_node_ipv4: "{{ k3s_node_address.stdout.split() | select('match', '^[0-9.]+$') | first }}" + k3s_listen_address: "{{ '::' if ':' in k3s_node_address.stdout.split()[0] else '0.0.0.0' }}" - name: Write OpenShell Helm values ansible.builtin.copy: @@ -106,6 +109,7 @@ image: registry: "" gateway: + listenAddress: "{{ k3s_listen_address }}" image: repository: openshell/gateway tag: tmachine @@ -116,6 +120,7 @@ tag: tmachine pullPolicy: never supervisor: + listenAddress: "{{ k3s_listen_address }}" image: repository: openshell/supervisor tag: tmachine @@ -135,27 +140,6 @@ mode: "0600" content: "{{ openshell_k3s_helm_values_overlay | default('{}') }}" - # An environment adapts the chart to its cluster by writing values to - # /etc/openshell-test/helm-values.yaml before the installer runs (for - # example playbooks/k3s-ipv6.yaml). They apply last. Other environments - # get an empty file. - - name: Create the test configuration directory - ansible.builtin.file: - path: /etc/openshell-test - state: directory - owner: root - group: root - mode: "0755" - - - name: Ensure environment Helm values exist - ansible.builtin.copy: - dest: /etc/openshell-test/helm-values.yaml - content: "{}\n" - force: false - owner: root - group: root - mode: "0644" - - name: Install Agent Sandbox ansible.builtin.command: argv: @@ -203,8 +187,6 @@ - /var/lib/openshell/artifacts/values.yaml - --values - /var/lib/openshell/artifacts/values-overlay.yaml - - --values - - /etc/openshell-test/helm-values.yaml - --wait - --timeout=5m environment: diff --git a/tests/tmachine/config.nix b/tests/tmachine/config.nix index 115d717eaa..0e6d973694 100644 --- a/tests/tmachine/config.nix +++ b/tests/tmachine/config.nix @@ -107,8 +107,8 @@ let inputs.keycloak_realm_file = "../../scripts/keycloak-realm.json"; }; }; - # A dual-stack cluster with IPv6 first, and the chart's IPv6 listen - # addresses, for running the k3s suites over IPv6. + # A dual-stack K3s cluster with IPv6 first, for running the k3s suites + # over IPv6. ipv6 = { bases = [ "ubuntu-k3s" ]; setup.playbooks = [ "ansible/playbooks/k3s-ipv6.yaml" ]; From f833d39b009bdccb2f45c7e0707c97e0b0d2196a Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Mon, 23 Nov 2026 20:18:43 -0800 Subject: [PATCH 10/13] test(conformance): skip the k3s-ha log-read tests on the IPv6 k3s environment The IPv6 k3s-ha row has the same multi-replica log gap (#5752) as ubuntu-k3s/k3s-ha. Signed-off-by: Matthew Grossman --- tests/suites/unsupported.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/suites/unsupported.yaml b/tests/suites/unsupported.yaml index 84c914f04c..4c30ae70b3 100644 --- a/tests/suites/unsupported.yaml +++ b/tests/suites/unsupported.yaml @@ -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 From b12d8ad01a16c5273d40804884550f323fd7b4f8 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Mon, 23 Nov 2026 21:05:58 -0800 Subject: [PATCH 11/13] test(host-server): listen on IPv6 as well as IPv4 Signed-off-by: Matthew Grossman --- tests/support/host-server/src/http.rs | 6 +++++- tests/support/host-server/src/lib.rs | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/support/host-server/src/http.rs b/tests/support/host-server/src/http.rs index 0845b0af5e..b93dc7fbd1 100644 --- a/tests/support/host-server/src/http.rs +++ b/tests/support/host-server/src/http.rs @@ -247,7 +247,11 @@ pub(crate) async fn read_request(stream: &mut TcpStream, buffer: &mut Vec) - loop { if let Some((mut request, length)) = parse_request(buffer) { buffer.drain(..length); - request.local_addr = stream.local_addr().ok(); + // An IPv4 client on the IPv6 socket arrives on a mapped address. + request.local_addr = stream + .local_addr() + .ok() + .map(|addr| SocketAddr::new(addr.ip().to_canonical(), addr.port())); return Some(request); } match tokio::time::timeout(READ_TIMEOUT, stream.read(&mut chunk)).await { diff --git a/tests/support/host-server/src/lib.rs b/tests/support/host-server/src/lib.rs index a481c1d5f3..7bd44ce6d8 100644 --- a/tests/support/host-server/src/lib.rs +++ b/tests/support/host-server/src/lib.rs @@ -54,10 +54,15 @@ const WAIT_INTERVAL: Duration = Duration::from_millis(100); const READ_TIMEOUT: Duration = Duration::from_secs(10); const MAX_REQUEST: usize = 1024 * 1024; +/// Listens on every IPv6 and IPv4 address, or on IPv4 only where the host +/// has no IPv6. async fn bind() -> Result<(TcpListener, u16)> { - let listener = TcpListener::bind(("0.0.0.0", 0)) - .await - .context("bind a host server")?; + let listener = match TcpListener::bind(("::", 0)).await { + Ok(listener) => listener, + Err(_) => TcpListener::bind(("0.0.0.0", 0)) + .await + .context("bind a host server")?, + }; let port = listener .local_addr() .context("read the host server's address")? From efc556e98c287bc3204c7761e3fa1657462e5d1b Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Mon, 23 Nov 2026 21:05:58 -0800 Subject: [PATCH 12/13] test(tmachine): reach the K3s node over IPv6 on an IPv6-first cluster Set host.openshell.internal to the node's first address and enable policy DNS IPv6 egress when it is IPv6. Signed-off-by: Matthew Grossman --- .../ansible/playbooks/openshell-k3s.yaml | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml index ff7a0cb0e7..2af473db13 100644 --- a/tests/tmachine/ansible/playbooks/openshell-k3s.yaml +++ b/tests/tmachine/ansible/playbooks/openshell-k3s.yaml @@ -66,9 +66,8 @@ # address must be the one of the node the tests run on. QEMU user # networking gives every boot the same guest address (10.0.2.15), so the # value stays valid when the disk is reused. - # A dual-stack node also lists an IPv6 address, first on an IPv6-first - # cluster. Take the IPv4 one: the servers tests start for sandboxes to - # reach (tests/support/host-server) listen on IPv4 only. + # A dual-stack node lists both addresses, the IPv6 one first on an + # IPv6-first cluster (playbooks/k3s-ipv6.yaml). Take the first. - name: Discover the K3s node address ansible.builtin.command: argv: @@ -93,13 +92,13 @@ changed_when: false failed_when: k3s_nodes.rc != 0 or k3s_nodes.stdout_lines | length != 1 - # On an IPv6-first cluster (playbooks/k3s-ipv6.yaml) the node lists its - # IPv6 address first, and the gateway and supervisor must listen on IPv6. - - name: Select the K3s node IPv4 address and listen address + - name: Select the K3s node address ansible.builtin.set_fact: - k3s_node_ipv4: "{{ k3s_node_address.stdout.split() | select('match', '^[0-9.]+$') | first }}" - k3s_listen_address: "{{ '::' if ':' in k3s_node_address.stdout.split()[0] else '0.0.0.0' }}" + k3s_node_ip: "{{ k3s_node_address.stdout.split()[0] }}" + k3s_ipv6: "{{ ':' in k3s_node_address.stdout.split()[0] }}" + # On an IPv6-first cluster the gateway and supervisor listen on IPv6, and + # policy DNS answers AAAA queries, so sandboxes reach the node over IPv6. - name: Write OpenShell Helm values ansible.builtin.copy: dest: /var/lib/openshell/artifacts/values.yaml @@ -109,7 +108,7 @@ image: registry: "" gateway: - listenAddress: "{{ k3s_listen_address }}" + listenAddress: "{{ '::' if k3s_ipv6 else '0.0.0.0' }}" image: repository: openshell/gateway tag: tmachine @@ -120,7 +119,7 @@ tag: tmachine pullPolicy: never supervisor: - listenAddress: "{{ k3s_listen_address }}" + listenAddress: "{{ '::' if k3s_ipv6 else '0.0.0.0' }}" image: repository: openshell/supervisor tag: tmachine @@ -131,8 +130,13 @@ auth: allowUnauthenticatedUsers: true disableTls: true - hostGatewayIP: "{{ k3s_node_ipv4 }}" + hostGatewayIP: "{{ k3s_node_ip }}" telemetryEnabled: false + {% if k3s_ipv6 %} + gatewayConfig: + openshell.drivers.kubernetes: + policy_dns_ipv6_egress: enabled + {% endif %} - name: Write OpenShell Helm values overlay ansible.builtin.copy: From f0139d336e0a7be3d5aea622f492031caa58e434 Mon Sep 17 00:00:00 2001 From: Matthew Grossman Date: Mon, 23 Nov 2026 21:05:58 -0800 Subject: [PATCH 13/13] test(features): check policy DNS AAAA answers on the IPv6 K3s environment Refs #3716 Signed-off-by: Matthew Grossman --- .github/workflows/e2e-suites.yml | 1 + TESTING.md | 6 + tests/suites/features/Cargo.lock | 10 ++ tests/suites/features/Cargo.toml | 2 +- .../features/policy-dns-ipv6/Cargo.toml | 23 +++ .../policy-dns-ipv6/tests/policy_dns_ipv6.rs | 159 ++++++++++++++++++ 6 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 tests/suites/features/policy-dns-ipv6/Cargo.toml create mode 100644 tests/suites/features/policy-dns-ipv6/tests/policy_dns_ipv6.rs diff --git a/.github/workflows/e2e-suites.yml b/.github/workflows/e2e-suites.yml index c33a436d13..2bd410bc96 100644 --- a/.github/workflows/e2e-suites.yml +++ b/.github/workflows/e2e-suites.yml @@ -116,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"}, diff --git a/TESTING.md b/TESTING.md index c959a505e3..0c6e21f1a3 100644 --- a/TESTING.md +++ b/TESTING.md @@ -707,6 +707,12 @@ 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`, +where the K3s installers enable `policy_dns_ipv6_egress` and set +`server.hostGatewayIP` to the node's IPv6 address. + 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 diff --git a/tests/suites/features/Cargo.lock b/tests/suites/features/Cargo.lock index ba47285c9a..adabff4abb 100644 --- a/tests/suites/features/Cargo.lock +++ b/tests/suites/features/Cargo.lock @@ -2674,6 +2674,16 @@ version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" +[[package]] +name = "policy-dns-ipv6" +version = "0.0.0" +dependencies = [ + "host-server-support", + "openshell-testkit", + "sandbox-clients-support", + "serde_json", +] + [[package]] name = "portable-atomic" version = "1.13.1" diff --git a/tests/suites/features/Cargo.toml b/tests/suites/features/Cargo.toml index 7c7fe40ae7..b7ea154446 100644 --- a/tests/suites/features/Cargo.toml +++ b/tests/suites/features/Cargo.toml @@ -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"] diff --git a/tests/suites/features/policy-dns-ipv6/Cargo.toml b/tests/suites/features/policy-dns-ipv6/Cargo.toml new file mode 100644 index 0000000000..c7f37181c8 --- /dev/null +++ b/tests/suites/features/policy-dns-ipv6/Cargo.toml @@ -0,0 +1,23 @@ +# 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" } +serde_json = "1" diff --git a/tests/suites/features/policy-dns-ipv6/tests/policy_dns_ipv6.rs b/tests/suites/features/policy-dns-ipv6/tests/policy_dns_ipv6.rs new file mode 100644 index 0000000000..2a9c7cde76 --- /dev/null +++ b/tests/suites/features/policy-dns-ipv6/tests/policy_dns_ipv6.rs @@ -0,0 +1,159 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +//! With `policy_dns_ipv6_egress` enabled, 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 enable it 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::policy; +use testkit::{Context, ResultExt as _}; + +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, the synthetic address on another port, and the +/// synthetic address once a policy change made its mapping stale. +#[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.clone(), + 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:?}" + ); + } + + let moved = HttpRecorder::start("moved").await?; + let mut changed = policy::base(); + allow_host(&mut changed, "host_server", moved.port); + policy::set(&sandbox, &changed) + .await + .context("move the endpoint to another port")?; + let attempt = connect(&sandbox, &synthetic, server.port).await?; + testkit::ensure!( + attempt.outcome.is_permission_denied(), + "expected a denial for the stale synthetic address [{synthetic}]:{}; got {attempt:?}", + server.port + ); + Ok(()) +}