depot/nixos/tests/systemd-cryptenroll.nix
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

41 lines
1.4 KiB
Nix

import ./make-test-python.nix ({ pkgs, ... }: {
name = "systemd-cryptenroll";
meta = with pkgs.lib.maintainers; {
maintainers = [ ymatsiuk ];
};
nodes.machine = { pkgs, lib, ... }: {
environment.systemPackages = [ pkgs.cryptsetup ];
virtualisation = {
emptyDiskImages = [ 512 ];
tpm.enable = true;
};
};
testScript = ''
machine.start()
# Verify the TPM device is available and accessible by systemd-cryptenroll
machine.succeed("test -e /dev/tpm0")
machine.succeed("test -e /dev/tpmrm0")
machine.succeed("systemd-cryptenroll --tpm2-device=list")
# Create LUKS partition
machine.succeed("echo -n lukspass | cryptsetup luksFormat -q /dev/vdb -")
# Enroll new LUKS key and bind it to Secure Boot state
# For more details on PASSWORD variable, check the following issue:
# https://github.com/systemd/systemd/issues/20955
machine.succeed("PASSWORD=lukspass systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/vdb")
# Add LUKS partition to /etc/crypttab to test auto unlock
machine.succeed("echo 'luks /dev/vdb - tpm2-device=auto' >> /etc/crypttab")
machine.shutdown()
machine.start()
# Test LUKS partition automatic unlock on boot
machine.wait_for_unit("systemd-cryptsetup@luks.service")
# Wipe TPM2 slot
machine.succeed("systemd-cryptenroll --wipe-slot=tpm2 /dev/vdb")
'';
})