From 5da6a7bbb80346af0b49c82b57526f6291f174c8 Mon Sep 17 00:00:00 2001 From: atlas Date: Fri, 20 Nov 2026 03:27:22 +0100 Subject: [PATCH] egress vm test: an agent_allow element passes one MAC to one address and port under reject --- nix/vm-tests/hive-squid.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nix/vm-tests/hive-squid.nix b/nix/vm-tests/hive-squid.nix index e3bf35d73..864f0e1d7 100644 --- a/nix/vm-tests/hive-squid.nix +++ b/nix/vm-tests/hive-squid.nix @@ -1289,5 +1289,23 @@ pkgs.testers.runNixOSTest { assert udp_status("203.0.113.77") == 0, "control: an exempt MAC's datagram is not refused" proxy.succeed(f"nft delete element inet hive_egress direct_mac '{{ {AGENT_MAC} }}'") assert dial_status("203.0.113.2", 8443) == 1, "refused again" + + # `hive-priv egress-pin` fills `agent_allow` on a hive host; here the + # elements are added by hand, as for `direct_mac`. + with checked("reject mode: an agent_allow element passes that MAC to that address and port only, and is refused again once it leaves"): + proxy.succeed(f"nft add element inet hive_egress agent_allow '{{ {AGENT_MAC} . 203.0.113.2 . 8443 }}'") + assert dial_status("203.0.113.2", 8443) == 0, "the allowed address and port" + # Another address of the same host, on the same port, is not in the set. + assert dial_status("203.0.113.9", 8443) == 1, "another address, same port" + wait_reject_line(r"SRC=192\.168\.1\.3 DST=203\.0\.113\.9 .*PROTO=TCP .*DPT=8443 ") + # Only TCP to the port is let through. + status, out = agent.execute("ping -c1 -W3 203.0.113.2") + assert status != 0, f"ICMP to the allowed address is still refused: {out}" + assert udp_status("203.0.113.2") != 0, "a datagram to the allowed address and port number is refused" + # An element of another MAC allows nothing for this one. + proxy.succeed("nft add element inet hive_egress agent_allow '{ 02:00:00:00:00:99 . 203.0.113.9 . 8443 }'") + assert dial_status("203.0.113.9", 8443) == 1, "another MAC's element" + proxy.succeed(f"nft delete element inet hive_egress agent_allow '{{ {AGENT_MAC} . 203.0.113.2 . 8443 }}'") + assert dial_status("203.0.113.2", 8443) == 1, "refused again" ''; }