@@ -15,6 +15,16 @@ import ./make-test.nix ( { pkgs, ... } : {
1515 services.httpd.adminAddr = "foo@example.org";
1616 };
1717
18+ # Dummy configuration to check whether firewall.service will be honored
19+ # during system activation. This only needs to be different to the
20+ # original walled configuration so that there is a change in the service
21+ # file.
22+ walled2 =
23+ { config, pkgs, nodes, ... }:
24+ { networking.firewall.enable = true;
25+ networking.firewall.rejectPackets = true;
26+ };
27+
1828 attacker =
1929 { config, pkgs, ... }:
2030 { services.httpd.enable = true;
@@ -23,28 +33,33 @@ import ./make-test.nix ( { pkgs, ... } : {
2333 };
2434 };
2535
26− testScript =
27− { nodes, ... }:
28− ''
29− startAll;
36+ testScript = { nodes, ... }: let
37+ newSystem = nodes.walled2.config.system.build.toplevel;
38+ in ''
39+ $walled->start;
40+ $attacker->start;
41+
42+ $walled->waitForUnit("firewall");
43+ $walled->waitForUnit("httpd");
44+ $attacker->waitForUnit("network.target");
3045
31− $walled->waitForUnit("firewall");
32− $walled->waitForUnit("httpd");
33− $attacker->waitForUnit("network.target");
46+ # Local connections should still work.
47+ $walled->succeed("curl -v http://localhost/ >&2");
3448
35− # Local connections should still work.
36− $walled->succeed("curl -v http://localhost/ >&2");
49+ # Connections to the firewalled machine should fail, but ping should succeed.
50+ $attacker->fail("curl --fail --connect-timeout 2 http://walled/ >&2");
51+ $attacker->succeed("ping -c 1 walled >&2");
3752
38− # Connections to the firewalled machine should fail, but ping should succeed.
39− $attacker->fail("curl --fail --connect-timeout 2 http://walled/ >&2");
40− $attacker->succeed("ping -c 1 walled >&2");
53+ # Outgoing connections/pings should still work.
54+ $walled->succeed("curl -v http://attacker/ >&2");
55+ $walled->succeed("ping -c 1 attacker >&2");
4156
42− # Outgoing connections/pings should still work.
43− $walled->succeed("curl -v http://attacker/ >&2");
44− $walled->succeed("ping -c 1 attacker >&2");
57+ # If we stop the firewall, then connections should succeed.
58+ $walled->stopJob("firewall");
59+ $attacker->succeed("curl -v http://walled/ >&2");
4560
46− # If we stop the firewall, then connections should succeed.
47− $walled->stopJob("firewall");
48− $attacker->succeed("curl -v http://walled/ >&2");
49− '';
61+ # Check whether activation of a new configuration reloads the firewall.
62+ $walled->succeed("${newSystem}/bin/switch-to-configuration test 2>&1" .
63+ " | grep -qF firewall.service");
64+ '';
5065})