Watch
0
0
Fork
You've already forked hyperhive
0

egress: the forward chain accepts the flows the host publishes for the agents

On a host with the egress intercept on, the forward chain rejected an agent's traffic to the queue once the queue ran as a pod: the pod's hostPort rewrites the destination to the pod, and the packet then leaves the bridge for the cluster. The chain now accepts TCP that the host's NAT redirected whose original destination is the bridge's address at a published port, which the queue adds when it runs in the cluster. Everything else from the bridge to the cluster stays refused. The nats switch test runs with the intercept on.
This commit is contained in:
atlas 2026-11-23 18:40:04 +01:00 • committed by mara
commit c2d57df7f5

View file

@ -12,8 +12,9 @@
# - the pod is Ready by its exec probe on the server's monitor, holds the leaf
# and the callout config as init containers, and publishes the client port
# on every address, with no `hostPort` on the exporter;
# - a client on the hive's bridge reaches the queue by name through the
# published port, and the responder in the pod admits the router's token;
# - with the egress intercept on, a client on the hive's bridge reaches the
# queue by name through the published port and not by the pod's address or
# the node's, and the responder in the pod admits the router's token;
# - the port is as closed to a host outside the node as the container's is, and
# open with `openFirewall`, where a second node dials it by name and verifies
# the name. The exporter answers the host only, by its Service's name;
@ -163,6 +164,12 @@ pkgs.testers.runNixOSTest {
deploy.k8s.enable = true;
network.enable = true;
network.bridgeIp = bridgeIp;
# The egress intercept is on, which makes the forward chain refuse an
# agent's traffic to anything but the bridge, as on a hive controller host.
deploy.hive-controller.egress.intercept = {
enable = true;
refuseEch = false;
};
deploy.bao.enable = true;
deploy.bao.seal = "shamir";
deploy.bao.bootstrapTokenFile = "/var/lib/swarm-bao-bootstrap/grant.token";
@ -475,6 +482,13 @@ pkgs.testers.runNixOSTest {
return status == 0, out.strip()
def probe_from_agent() -> tuple[bool, str]:
"""`probe` from the netns of the client on the bridge, at the bridge's
address, by the name an agent dials."""
status, out = machine.execute(f"ip netns exec agent python3 /etc/natstls.py {BRIDGE} {NAME} {SERVICES_ROOT} 2>&1")
return status == 0, out.strip()
def reachable(node: QemuMachine, address: str, port: int) -> bool:
return node.execute(f"nc -z -w 4 {address} {port}")[0] == 0
@ -674,8 +688,15 @@ pkgs.testers.runNixOSTest {
# back when the container starts.
assert int(machine.succeed(f"find {HOST_STORE} ! -uid {HOST_UID} | wc -l")) > 0
with subtest("a client on the hive's bridge reaches the pod through the published port, and a host outside the node does not"):
with subtest("a client on the hive's bridge reaches the pod through the published port, behind the egress chain that refuses it everything else of the cluster, and a host outside the node does not"):
assert machine.execute(f"ip netns exec agent nc -z -w 4 {BRIDGE} {PORT}")[0] == 0
assert probe_from_agent()[0], probe_from_agent()
# The same pod by its own address, and the queue by the node's address,
# are no flow the host published for the agent: both are refused.
pod_ip = kube(machine, f"get pod {pod_name} -o jsonpath='{{.status.podIP}}'").strip()
assert pod_ip.startswith("10.200."), pod_ip
assert machine.execute(f"ip netns exec agent nc -z -w 4 {pod_ip} {PORT}")[0] != 0
assert machine.execute(f"ip netns exec agent nc -z -w 4 {NODE} {PORT}")[0] != 0
assert machine.execute(f"ip netns exec agent nc -z -w 4 {BRIDGE} {METRICS}")[0] != 0
assert reachable(outside, NODE, CONTROL)
assert not reachable(outside, NODE, PORT), "the pod's port is open to a host outside the node"