Watch
0
0
Fork
You've already forked hyperhive
0

move flannel's wireguard port to 51830, advertise the node address as the tunnel endpoint, drop the 51820 assertion

This commit is contained in:
atlas 2026-11-27 23:06:25 +01:00 • committed by maia
commit 8cfd52cd4c

View file

@ -161,6 +161,7 @@ pkgs.testers.runNixOSTest {
environment.variables.KUBECONFIG = "/etc/rancher/k3s/k3s.yaml";
environment.etc = {
"k8s-join/probe-ref".text = probeRef;
"k8s-join/flannel-port".text = toString config.services.hyperhive.deploy.k8s.flannelWgPort;
"k8s-join/pod-on-joiner.json".text = builtins.toJSON (
pod "on-joiner" probeRef { "kubernetes.io/hostname" = "joiner"; }
);
@ -258,6 +259,7 @@ pkgs.testers.runNixOSTest {
JOIN_TOKEN = "/run/k3s-join/token"
JOINER_IP = "${joinIp}"
MAIN_IP = "${mainIp}"
FLANNEL_PORT = main.succeed("cat /etc/k8s-join/flannel-port").strip()
PROBE_REF = main.succeed("cat /etc/k8s-join/probe-ref").strip()
MISSING_REF = "${missingRef}"
HOST = "${images.registryHost}"
@ -281,6 +283,7 @@ pkgs.testers.runNixOSTest {
main.wait_until_succeeds(command, timeout=timeout)
except Exception:
diagnose(units)
print(main.execute("kubectl get pods -o wide; kubectl logs net-main")[1])
raise
@ -421,13 +424,13 @@ pkgs.testers.runNixOSTest {
with subtest("the node-to-node ports are open to the joining machine's address only"):
rules = main.succeed("iptables -S nixos-fw").splitlines()
for port, proto in [("6443", "tcp"), ("10250", "tcp"), ("51820", "udp"), ("5001", "tcp")]:
for port, proto in [("6443", "tcp"), ("10250", "tcp"), (FLANNEL_PORT, "udp"), ("5001", "tcp")]:
matching = [r for r in rules if f"--dport {port} " in r and f"-p {proto} " in r]
assert matching, (port, rules)
assert all(f"-s {JOINER_IP}/32" in r for r in matching), (port, matching)
assert not [r for r in rules if "--dport 8472" in r], rules
joiner_rules = joiner.succeed("iptables -S nixos-fw").splitlines()
assert [r for r in joiner_rules if "--dport 51820 " in r and f"-s {MAIN_IP}/32" in r], joiner_rules
assert [r for r in joiner_rules if f"--dport {FLANNEL_PORT} " in r and f"-s {MAIN_IP}/32" in r], joiner_rules
assert not [r for r in joiner_rules if "--dport 8472" in r], joiner_rules
with subtest("a pod with the poller's state selector runs on the main node"):
@ -445,6 +448,7 @@ pkgs.testers.runNixOSTest {
wait_running("on-joiner", 300)
except AssertionError:
diagnose_pull()
print(main.execute("kubectl get pods -o wide; kubectl logs net-main")[1])
raise
assert pod(main, "on-joiner")["spec"]["nodeName"] == "joiner"
joiner.succeed(f"k3s ctr images ls -q | grep -qxF '{containerd_name}'")
@ -461,7 +465,7 @@ pkgs.testers.runNixOSTest {
keys = {}
for node in [main, joiner]:
assert "wireguard" in node.succeed("ip -d link show flannel-wg")
assert node.succeed("wg show flannel-wg listen-port").strip() == "51820"
assert node.succeed("wg show flannel-wg listen-port").strip() == FLANNEL_PORT
node.fail("ip link show flannel.1")
assert node.succeed("ss -H -lun 'sport = :8472'").strip() == "", "something listens on UDP 8472"
assert "-i flannel-wg " in node.succeed("iptables -S nixos-fw")
@ -469,6 +473,12 @@ pkgs.testers.runNixOSTest {
assert keys["main"] != keys["joiner"], keys
assert main.succeed("wg show flannel-wg peers").split() == [keys["joiner"]]
assert joiner.succeed("wg show flannel-wg peers").split() == [keys["main"]]
# The endpoint is the address the nodes reach each other on, not the
# default route's: the test machines' default route is a private network
# of their own that reaches no peer.
for node, peer_key, peer_ip in [(main, keys["joiner"], JOINER_IP), (joiner, keys["main"], MAIN_IP)]:
endpoints = dict(l.split() for l in node.succeed("wg show flannel-wg endpoints").splitlines())
assert endpoints == {peer_key: f"{peer_ip}:{FLANNEL_PORT}"}, endpoints
with subtest("a pod on the joining machine fetches a page from a pod on the main node, through the tunnel"):
main.succeed("kubectl apply -f /etc/k8s-join/pod-net-main.json -f /etc/k8s-join/pod-net-joiner.json")
@ -477,11 +487,19 @@ pkgs.testers.runNixOSTest {
assert pod(main, "net-main")["spec"]["nodeName"] == "main"
assert pod(main, "net-joiner")["spec"]["nodeName"] == "joiner"
target = pod(main, "net-main")["status"]["podIP"]
url = f"http://{target}:${toString netPort}/"
# The server answers inside its own pod: the control that a failure below
# is the network's.
main.wait_until_succeeds("kubectl exec net-main -- wget -qO- -T 5 http://127.0.0.1:${toString netPort}/ | grep -qx ${netPage}", timeout=60)
before = wg_transfer(joiner, "flannel-wg")
main.wait_until_succeeds(
f"kubectl exec net-joiner -- wget -qO- -T 5 http://{target}:${toString netPort}/ | grep -qx ${netPage}",
timeout=180,
)
try:
main.wait_until_succeeds(f"kubectl exec net-joiner -- wget -qO- -T 5 {url} | grep -qx ${netPage}", timeout=120)
except Exception:
for node in [main, joiner]:
print(f"--- {node.name}")
print(node.execute("wg show flannel-wg; ip -4 route; ip -s link show flannel-wg; iptables -S FORWARD; iptables -S nixos-fw")[1])
print(main.execute("kubectl get pods -o wide; kubectl logs net-main")[1])
raise
after = wg_transfer(joiner, "flannel-wg")
assert after[0] > before[0] and after[1] > before[1], (before, after)
for node in [main, joiner]:
@ -495,7 +513,7 @@ pkgs.testers.runNixOSTest {
main.succeed(
"ip link add rogue type wireguard && "
f"wg set rogue private-key /root/rogue.key listen-port 51999 peer {keys['joiner']} "
f"endpoint {JOINER_IP}:51820 allowed-ips {victim}/32 && "
f"endpoint {JOINER_IP}:{FLANNEL_PORT} allowed-ips {victim}/32 && "
"ip addr add 10.99.0.1/32 dev rogue && ip link set rogue up && "
f"ip route add {victim}/32 dev rogue"
)