Watch
0
0
Fork
You've already forked hyperhive
0

run flannel's wireguard-native backend on every k8s node

This commit is contained in:
atlas 2026-11-27 22:48:56 +01:00 • committed by maia
commit 44ae81470e

View file

@ -26,6 +26,7 @@ let
})
runGroup
hive
hiveWith
hiveWithController
baoSettings
bridgePorts
@ -116,14 +117,25 @@ let
nodeOffRefusals = lib.filter (a: !a.assertion) nodeOffRefused.assertions;
# A node every assertion refuses: no rendering, a pod range containing the
# hive bridge's subnet, and a service range inside the pod range.
nodeRefused = hive {
deploy.k8s.enable = true;
k8s.enable = false;
network.enable = true;
deploy.k8s.podCidr = "10.42.0.0/16";
deploy.k8s.serviceCidr = "10.42.128.0/17";
};
# hive bridge's subnet, a service range inside the pod range, and a WireGuard
# interface on the port flannel's tunnel binds.
nodeRefused =
hiveWith
[
{
networking.wireguard.interfaces.wg0 = {
listenPort = 51820;
privateKeyFile = "/etc/wireguard/wg0.key";
};
}
]
{
deploy.k8s.enable = true;
k8s.enable = false;
network.enable = true;
deploy.k8s.podCidr = "10.42.0.0/16";
deploy.k8s.serviceCidr = "10.42.128.0/17";
};
# The node on a host with no hive bridge, so no address to resolve names to.
nodeNoBridge = hive { deploy.k8s.enable = true; };
coreDnsKey = "hyperhive-host-services.override";
@ -358,7 +370,8 @@ let
&& withNode.services.k3s.role == "server"
&& withNode.systemd.services ? k3s
&& lib.elem "cni0" withNode.networking.firewall.trustedInterfaces
&& lib.elem "flannel.1" withNode.networking.firewall.trustedInterfaces;
&& lib.elem "flannel-wg" withNode.networking.firewall.trustedInterfaces
&& !(lib.elem "flannel.1" withNode.networking.firewall.trustedInterfaces);
}
{
name = "the node runs k3s with traefik and metrics-server off and its secrets encrypted";
@ -407,6 +420,26 @@ let
&& refuses "overlap the hive bridge"
&& refuses "overlap each other";
}
{
# An agent takes the backend from its server, and `--flannel-backend` is
# a server flag that an agent refuses, so the agent's flags carry none.
# The agent is the control that the lookup reads the flag list.
name = "the server runs flannel's WireGuard backend, and the joined agent sets no backend flag";
ok =
lib.elem "--flannel-backend=wireguard-native" withNode.services.k3s.extraFlags
&& lib.elem "--flannel-backend=wireguard-native" nodeNoBridge.services.k3s.extraFlags
&& !(lib.any (lib.hasPrefix "--flannel-backend") joined.services.k3s.extraFlags)
&& lib.elem "--embedded-registry" withNode.services.k3s.extraFlags
&& joined.services.k3s.role == "agent"
&& lib.elem "flannel-wg" joined.networking.firewall.trustedInterfaces
&& !(lib.elem "flannel.1" joined.networking.firewall.trustedInterfaces);
}
{
# The all-local host, with no WireGuard interface, is the control: every
# assertion holds there.
name = "the node refuses a WireGuard interface of the host's own on the port flannel's tunnel binds";
ok = lib.all (a: a.assertion) withNode.assertions && refuses "flannel's WireGuard tunnel on UDP";
}
{
# The names are the control that the search finds something: the swarm's
# own bao name and the hive domain are among them, and every one is in the
@ -740,7 +773,7 @@ let
&& !(hasInfix "swarm-bao-k8s-jwt-policy" off.serviceConfig.ExecStartPost)
&& hasInfix "swarm-bao-operator-viewer-policy" off.serviceConfig.ExecStartPost
&& !(noNode.networking.firewall.interfaces ? cni0)
&& !(noNode.networking.firewall.interfaces ? "flannel.1");
&& !(noNode.networking.firewall.interfaces ? "flannel-wg");
}
{
# Pods log in on a listener that asks for no client certificate, and no
@ -778,7 +811,7 @@ let
in
cni == [
"cni0"
"flannel.1"
"flannel-wg"
]
&& lib.all (i: lib.elem 8208 (portsOn i)) cni
&& lib.all (i: lib.elem i cni || !(lib.elem 8208 (portsOn i))) (lib.attrNames fw.interfaces)
@ -2807,7 +2840,7 @@ let
forNodes = address: [
(rule address "tcp" "6443")
(rule address "tcp" "10250")
(rule address "udp" "8472")
(rule address "udp" "51820")
(rule address "tcp" "5001")
];
nodeLines = lib.filter (l: hasInfix "--dport" l && hasInfix "nixos-fw -s" l) (
@ -2818,7 +2851,10 @@ let
&& lib.length nodeLines == 8
&& !(hasInfix "--dport 6443" nodeNoBridge.networking.firewall.extraCommands)
&& !(lib.elem 6443 onCluster.networking.firewall.allowedTCPPorts)
&& !(lib.elem 8472 onCluster.networking.firewall.allowedUDPPorts);
&& !(lib.elem 51820 onCluster.networking.firewall.allowedUDPPorts)
&& !(hasInfix "8472" rules)
&& !(hasInfix "8472" joined.networking.firewall.extraCommands)
&& hasInfix (rule "192.168.1.10" "udp" "51820") joined.networking.firewall.extraCommands;
}
{
# The main node is the control for each absence.