1 import ./make-test-python.nix ({ pkgs, ... }: {
3 meta = with pkgs.lib.maintainers; {
4 maintainers = [ jfroche ];
14 "${modulesPath}/../tests/common/auto-format-root-device.nix"
17 emptyDiskImages = [ 512 ];
20 # This requires to have access
21 # to a host Nix store as
22 # the new root device is /dev/vdb
23 # an empty 512MiB drive, containing no Nix store.
24 mountHostNixStore = true;
27 boot.loader.systemd-boot.enable = true;
29 networking.interfaces.eth1.ipv4.addresses = [
30 { address = "192.168.0.1"; prefixLength = 24; }
33 environment.systemPackages = with pkgs; [ clevis tang cryptsetup ];
36 ipAddressAllow = [ "127.0.0.1/32" ];
41 machine.wait_for_unit("sockets.target")
43 with subtest("Check keys are generated"):
44 machine.wait_until_succeeds("curl -v http://127.0.0.1:7654/adv")
45 key = machine.wait_until_succeeds("tang-show-keys 7654")
47 with subtest("Check systemd access list"):
48 machine.succeed("ping -c 3 192.168.0.1")
49 machine.fail("curl -v --connect-timeout 3 http://192.168.0.1:7654/adv")
51 with subtest("Check basic encrypt and decrypt message"):
52 machine.wait_until_succeeds(f"""echo 'Hello World' | clevis encrypt tang '{{ "url": "http://127.0.0.1:7654", "thp":"{key}"}}' > /tmp/encrypted""")
53 decrypted = machine.wait_until_succeeds("clevis decrypt < /tmp/encrypted")
54 assert decrypted.strip() == "Hello World"
55 machine.wait_until_succeeds("tang-show-keys 7654")
57 with subtest("Check encrypt and decrypt disk"):
58 machine.succeed("cryptsetup luksFormat --force-password --batch-mode /dev/vdb <<<'password'")
59 machine.succeed(f"""clevis luks bind -s1 -y -f -d /dev/vdb tang '{{ "url": "http://127.0.0.1:7654", "thp":"{key}" }}' <<< 'password' """)
60 clevis_luks = machine.succeed("clevis luks list -d /dev/vdb")
61 assert clevis_luks.strip() == """1: tang '{"url":"http://127.0.0.1:7654"}'"""
62 machine.succeed("clevis luks unlock -d /dev/vdb")
63 machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
64 machine.succeed("clevis luks unlock -d /dev/vdb")
65 machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
66 # without tang available, unlock should fail
67 machine.succeed("systemctl stop tangd.socket")
68 machine.fail("clevis luks unlock -d /dev/vdb")
69 machine.succeed("systemctl start tangd.socket")
71 with subtest("Rotate server keys"):
72 machine.succeed("${pkgs.tang}/libexec/tangd-rotate-keys -d /var/lib/tang")
73 machine.succeed("clevis luks unlock -d /dev/vdb")
74 machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
76 with subtest("Test systemd service security"):
77 output = machine.succeed("systemd-analyze security tangd@.service")
79 assert output[-9:-1] == "SAFE :-}"