diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/qemu/firecracker.sh | 4 | ||||
| -rw-r--r-- | tests/vm-host.nix | 66 |
2 files changed, 35 insertions, 35 deletions
diff --git a/tests/qemu/firecracker.sh b/tests/qemu/firecracker.sh index 08f766d..fcc217c 100644 --- a/tests/qemu/firecracker.sh +++ b/tests/qemu/firecracker.sh @@ -2,7 +2,7 @@ # run script where there's no Firecracker: boots the same kernel, initrd, # drives, vsock (vhost-device-vsock does the same uds_path_PORT # convention) and network interface (qemu's user networking; guest port 22 -# forwarded to 127.0.0.1:${FC_TEST_SSH_PORT:-2222}) in qemu, with +# forwarded to 127.0.0.1:${RIG_TEST_SSH_PORT:-2222}) in qemu, with # virtio-pci instead of virtio-mmio (see debug.nix). set -efu config=$3 @@ -23,5 +23,5 @@ qemu-system-x86_64 -machine accel=kvm:tcg -nographic -no-reboot \ -initrd "$(get '."boot-source".initrd_path')" -append "$args" \ -chardev socket,id=vs,path="$vhost" -device vhost-user-vsock-pci,chardev=vs \ $(jq -r '.drives[] | "-drive file=\(.path_on_host),if=virtio,format=raw" + (if .is_read_only then ",readonly=on" else "" end)' "$config") \ - -netdev user,id=n,hostfwd=tcp:127.0.0.1:"${FC_TEST_SSH_PORT:-2222}"-:22 \ + -netdev user,id=n,hostfwd=tcp:127.0.0.1:"${RIG_TEST_SSH_PORT:-2222}"-:22 \ -device virtio-net-pci,netdev=n,mac="$(get '."network-interfaces"[0].guest_mac')" diff --git a/tests/vm-host.nix b/tests/vm-host.nix index 569d874..a0e5cda 100644 --- a/tests/vm-host.nix +++ b/tests/vm-host.nix @@ -1,8 +1,8 @@ # NixOS VM test of modules/host: the module for real (systemd units, path # units, timer, nftables, dnsmasq, nginx), with network namespaces on -# veths in place of tv's taps fctap1 and fctap2 as guests: +# veths in place of tv's taps rigtap1 and rigtap2 as guests: # g1 as the VM box, with box's address (172.16.0.10, MAC 06:00:ac:10:00:0a), -# g2 without a name, with fctap2's own (172.16.0.202, ...:ca); SLAAC gives +# g2 without a name, with rigtap2's own (172.16.0.202, ...:ca); SLAAC gives # them the IPv6 addresses the host expects from those MACs. Another netns # is an upstream with 42::1 and 198.51.100.1, there for the names *.test # (a dnsmasq on the host's lo, as nginx's resolver), with an HTTPS server @@ -20,10 +20,10 @@ let # Test certificates (keys in the store, for the test only): a CA, the # upstream's certificate for the names below from it, and a self-signed # one for untrusted.test. - certs = pkgs.runCommand "fc-test-certs" { nativeBuildInputs = [ pkgs.openssl ]; } '' + certs = pkgs.runCommand "rig-test-certs" { nativeBuildInputs = [ pkgs.openssl ]; } '' mkdir $out && cd $out openssl req -x509 -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ - -days 3650 -subj /CN=fc-test-ca -keyout ca.key -out ca.pem \ + -days 3650 -subj /CN=rig-test-ca -keyout ca.key -out ca.pem \ -addext basicConstraints=critical,CA:TRUE -addext keyUsage=critical,keyCertSign openssl req -x509 -CA ca.pem -CAkey ca.key -new -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \ -days 3650 -subj /CN=allowed.test -keyout server.key -out server.pem \ @@ -35,9 +35,9 @@ let ''; in pkgs.testers.runNixOSTest { - name = "fc-host"; + name = "rig-host"; nodes.host = { pkgs, ... }: { - # alice: fctap0, tv: fctap1 and fctap2 + # alice: rigtap0, tv: rigtap1 and rigtap2 imports = [ (import ../modules/host { users = { tv = 2; alice = 1; }; vms.box = { user = "tv"; ip = "172.16.0.10"; }; @@ -60,7 +60,7 @@ pkgs.testers.runNixOSTest { }; security.pki.certificateFiles = [ "${certs}/ca.pem" ]; # As the host's firewall has to (see README.md). - networking.firewall.trustedInterfaces = [ "fcbr0" ]; + networking.firewall.trustedInterfaces = [ "rigbr0" ]; environment.systemPackages = [ pkgs.socat pkgs.dig pkgs.curl pkgs.openssl ]; virtualisation.memorySize = 1024; }; @@ -69,18 +69,18 @@ pkgs.testers.runNixOSTest { g2_ip6 = "fdfc:fc::400:acff:fe10:ca" host.wait_for_unit("multi-user.target") - host.wait_for_unit("fcbr0-dnsmasq.service") - host.wait_for_unit("fcbr0-firewall.service") - # box on fctap1, as the run script does it - host.succeed("su tv -c 'echo box > /run/fc-egress/fctap1.name'") - host.wait_until_succeeds("test \"$(head -n 1 /run/fcbr0-addr/fctap1)\" = 172.16.0.10", timeout=60) + host.wait_for_unit("rig-dnsmasq.service") + host.wait_for_unit("rig-firewall.service") + # box on rigtap1, as the run script does it + host.succeed("su tv -c 'echo box > /run/rig-egress/rigtap1.name'") + host.wait_until_succeeds("test \"$(head -n 1 /run/rig-addr/rigtap1)\" = 172.16.0.10", timeout=60) host.succeed(""" set -e guest() { # N TAP IP MAC ip link del $2 ip netns add g$1 ip link add $2 type veth peer name eth0 netns g$1 - ip link set $2 master fcbr0 up + ip link set $2 master rigbr0 up ip netns exec g$1 sysctl -qw net.ipv6.conf.all.use_tempaddr=0 net.ipv6.conf.default.use_tempaddr=0 ip netns exec g$1 ip link set eth0 address $4 ip netns exec g$1 ip link set lo up @@ -88,8 +88,8 @@ pkgs.testers.runNixOSTest { ip netns exec g$1 ip link set eth0 up ip netns exec g$1 ip route add default via 172.16.0.1 } - guest 1 fctap1 172.16.0.10 06:00:ac:10:00:0a - guest 2 fctap2 172.16.0.202 06:00:ac:10:00:ca + guest 1 rigtap1 172.16.0.10 06:00:ac:10:00:0a + guest 2 rigtap2 172.16.0.202 06:00:ac:10:00:ca ip netns add U ip link add up0 type veth peer name eth0 netns U ip link set up0 up @@ -122,11 +122,11 @@ pkgs.testers.runNixOSTest { print(f"{what}: {got}") assert got == want, f"{what}: got {got!r}, want {want!r}" - # rules via fc-egress and the path units - host.succeed("su tv -c 'fc-egress -l box allow tcp://[42::1]:22 tcp://[42::1]:443 tcp://sshhost6.test:22 tcp://198.51.100.1:22'") - host.fail("su tv -c 'fc-egress -l box allow tcp://[42::1/129]:22'") - host.succeed("su tv -c 'echo box > /run/fc-egress/fctap1'") - host.wait_until_succeeds("nft list set inet firecracker allow6_fctap1 | grep -q '42::1'", timeout=60) + # rules via rig-egress and the path units + host.succeed("su tv -c 'rig-egress -l box allow tcp://[42::1]:22 tcp://[42::1]:443 tcp://sshhost6.test:22 tcp://198.51.100.1:22'") + host.fail("su tv -c 'rig-egress -l box allow tcp://[42::1/129]:22'") + host.succeed("su tv -c 'echo box > /run/rig-egress/rigtap1'") + host.wait_until_succeeds("nft list set inet rigs allow6_rigtap1 | grep -q '42::1'", timeout=60) check("host reaches the upstream", host.succeed("timeout 5 socat -T3 - TCP6:[42::1]:22 </dev/null").strip(), "ssh-ok") check("g1 [42::1]:22, allowed", tcp("g1", "[42::1]", 22), "ssh-ok") @@ -142,18 +142,18 @@ pkgs.testers.runNixOSTest { host.succeed(f"ip netns exec g2 ip addr add {g1_ip6}/64 dev eth0 nodad") check("g2 sending as g1", tcp("g2", "[42::1]", 22, f",bind=[{g1_ip6}]"), "blocked") check("g1 to the host's IPv6 address", tcp("g1", "[fdfc:fc::1]", 22), "blocked") - host.succeed("su tv -c 'fc-egress -l box deny tcp://[42::1]:22 tcp://sshhost6.test:22'") - host.wait_until_fails("nft list set inet firecracker allow6_fctap1 | grep -q '42::1 . tcp . 22'", timeout=60) + host.succeed("su tv -c 'rig-egress -l box deny tcp://[42::1]:22 tcp://sshhost6.test:22'") + host.wait_until_fails("nft list set inet rigs allow6_rigtap1 | grep -q '42::1 . tcp . 22'", timeout=60) check("g1 [42::1]:22 after deny", tcp("g1", "[42::1]", 22), "blocked") check("g1 checks after deny", check_uris("g1", "tcp://[42::1]:22"), ["false"]) - host.succeed("systemctl list-timers fcbr0-firewall-refresh.timer --no-pager | grep -q fcbr0-firewall-refresh") + host.succeed("systemctl list-timers rig-firewall-refresh.timer --no-pager | grep -q rig-firewall-refresh") # The HTTPS proxy. The upstream serves files (s_server -WWW), as # allowed.test & co. with a certificate from the test CA, which the # host trusts, and as untrusted.test with a self-signed one. The # guests dial any address: their port 443 goes to the proxy. test_ca = "${certs}/ca.pem" - fc_ca = "/var/lib/fcbr0-egress/ca.pem" + proxy_ca = "/var/lib/rig-proxy/ca.pem" host.succeed("mkdir -p /tmp/www/ok /tmp/www/no && echo hello > /tmp/www/hello && echo ok > /tmp/www/ok/file && echo no > /tmp/www/no/file") host.succeed( "cd /tmp/www && ip netns exec U openssl s_server -quiet -WWW -accept 198.51.100.1:443" @@ -161,7 +161,7 @@ pkgs.testers.runNixOSTest { " -servername untrusted.test -cert2 ${certs}/untrusted.pem -key2 ${certs}/untrusted.key >&2 &" ) host.wait_until_succeeds("ip netns exec U ss -ltn | grep -q '198.51.100.1:443'", timeout=30) - host.wait_for_unit("fcbr0-egress.service") + host.wait_for_unit("rig-proxy.service") def https(g, url, ca, extra=""): name = url.split("/")[2] @@ -172,13 +172,13 @@ pkgs.testers.runNixOSTest { return "blocked" if out[-1] == "blocked" else f"{' '.join(out[:-1])} {out[-1]}" def status(g, url, extra=""): - return https(g, url, fc_ca, extra).split()[-1] + return https(g, url, proxy_ca, extra).split()[-1] - host.succeed("su tv -c 'fc-egress -l box allow https://allowed.test https://paths.test/ok/ https://untrusted.test/ok/'") + host.succeed("su tv -c 'rig-egress -l box allow https://allowed.test https://paths.test/ok/ https://untrusted.test/ok/'") check("g1 allowed.test, passed through", https("g1", "https://allowed.test/hello", test_ca), "hello 200") - check("g1 allowed.test, not with our CA", https("g1", "https://allowed.test/hello", fc_ca), "blocked") + check("g1 allowed.test, not with our CA", https("g1", "https://allowed.test/hello", proxy_ca), "blocked") check("g1 sub.allowed.test, subdomain", https("g1", "https://sub.allowed.test/hello", test_ca), "hello 200") - check("g1 paths.test/ok/, decrypted", https("g1", "https://paths.test/ok/file", fc_ca), "ok 200") + check("g1 paths.test/ok/, decrypted", https("g1", "https://paths.test/ok/file", proxy_ca), "ok 200") check("g1 paths.test/ok/, not the upstream's certificate", https("g1", "https://paths.test/ok/file", test_ca), "blocked") check("g1 paths.test/no/", status("g1", "https://paths.test/no/file"), "403") check("g1 paths.test/ok/../no/", status("g1", "https://paths.test/ok/../no/file", "--path-as-is"), "403") @@ -189,11 +189,11 @@ pkgs.testers.runNixOSTest { check("g1 untrusted.test, upstream not verified", status("g1", "https://untrusted.test/ok/file"), "502") check("g1 https checks", check_uris("g1", "https://allowed.test", "https://sub.allowed.test/x", "https://paths.test/ok/file", "https://paths.test/no/file", "https://denied.test"), ["true", "true", "true", "false", "false"]) - host.wait_until_succeeds("journalctl -t fc_egress --no-pager | grep -q 'ALLOW tv fctap1 box https://allowed.test'", timeout=30) - host.wait_until_succeeds("journalctl -t fc_egress --no-pager | grep -q 'DENY tv fctap1 box https://denied.test'", timeout=30) - host.wait_until_succeeds("journalctl -t fc_egress --no-pager | grep -qE 'DENY .*GET https://paths.test/no/file'", timeout=30) + host.wait_until_succeeds("journalctl -t rig_egress --no-pager | grep -q 'ALLOW tv rigtap1 box https://allowed.test'", timeout=30) + host.wait_until_succeeds("journalctl -t rig_egress --no-pager | grep -q 'DENY tv rigtap1 box https://denied.test'", timeout=30) + host.wait_until_succeeds("journalctl -t rig_egress --no-pager | grep -qE 'DENY .*GET https://paths.test/no/file'", timeout=30) # rules apply to the next connection, without reloading anything - host.succeed("su tv -c 'fc-egress -l box deny https://allowed.test && fc-egress -l box allow https://denied.test'") + host.succeed("su tv -c 'rig-egress -l box deny https://allowed.test && rig-egress -l box allow https://denied.test'") check("g1 allowed.test after deny", https("g1", "https://allowed.test/hello", test_ca), "blocked") check("g1 denied.test after allow", https("g1", "https://denied.test/hello", test_ca), "hello 200") ''; |
