1 # Test the firewall module.
3 import ./make-test-python.nix ( { pkgs, nftables, ... } : {
4 name = "firewall" + pkgs.lib.optionalString nftables "-nftables";
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ eelco ];
12 { networking.firewall.enable = true;
13 networking.firewall.logRefusedPackets = true;
14 networking.nftables.enable = nftables;
15 services.httpd.enable = true;
16 services.httpd.adminAddr = "foo@example.org";
19 # Dummy configuration to check whether firewall.service will be honored
20 # during system activation. This only needs to be different to the
21 # original walled configuration so that there is a change in the service
25 { networking.firewall.enable = true;
26 networking.firewall.rejectPackets = true;
27 networking.nftables.enable = nftables;
32 { services.httpd.enable = true;
33 services.httpd.adminAddr = "foo@example.org";
34 networking.firewall.enable = false;
38 testScript = { nodes, ... }: let
39 newSystem = nodes.walled2.config.system.build.toplevel;
40 unit = if nftables then "nftables" else "firewall";
44 walled.wait_for_unit("${unit}")
45 walled.wait_for_unit("httpd")
46 attacker.wait_for_unit("network.target")
48 # Local connections should still work.
49 walled.succeed("curl -v http://localhost/ >&2")
51 # Connections to the firewalled machine should fail, but ping should succeed.
52 attacker.fail("curl --fail --connect-timeout 2 http://walled/ >&2")
53 attacker.succeed("ping -c 1 walled >&2")
55 # Outgoing connections/pings should still work.
56 walled.succeed("curl -v http://attacker/ >&2")
57 walled.succeed("ping -c 1 attacker >&2")
59 # If we stop the firewall, then connections should succeed.
60 walled.stop_job("${unit}")
61 attacker.succeed("curl -v http://walled/ >&2")
63 # Check whether activation of a new configuration reloads the firewall.
65 "${newSystem}/bin/switch-to-configuration test 2>&1 | grep -qF ${unit}.service"