diff options
Diffstat (limited to '')
l--------- | debian/tests/cryptroot-md | 1 | ||||
-rw-r--r-- | debian/tests/cryptroot-md.d/bottom | 15 | ||||
-rw-r--r-- | debian/tests/cryptroot-md.d/config | 7 | ||||
-rwxr-xr-x | debian/tests/cryptroot-md.d/mock | 41 | ||||
-rw-r--r-- | debian/tests/cryptroot-md.d/preinst | 20 | ||||
-rw-r--r-- | debian/tests/cryptroot-md.d/setup | 84 |
6 files changed, 168 insertions, 0 deletions
diff --git a/debian/tests/cryptroot-md b/debian/tests/cryptroot-md new file mode 120000 index 0000000..2e34c2d --- /dev/null +++ b/debian/tests/cryptroot-md @@ -0,0 +1 @@ +utils/cryptroot-common
\ No newline at end of file diff --git a/debian/tests/cryptroot-md.d/bottom b/debian/tests/cryptroot-md.d/bottom new file mode 100644 index 0000000..a771c91 --- /dev/null +++ b/debian/tests/cryptroot-md.d/bottom @@ -0,0 +1,15 @@ +umount "$ROOT/boot" +umount "$ROOT" + +swapoff /dev/md1 +mdadm --stop /dev/md1 +cryptsetup close "vda3_crypt" +cryptsetup close "vdb3_crypt" + +swapoff /dev/cryptvg/swap +lvm vgchange -an "cryptvg" +mdadm --stop /dev/md2 +cryptsetup close "vda4_crypt" +cryptsetup close "vdb4_crypt" + +# vim: set filetype=sh : diff --git a/debian/tests/cryptroot-md.d/config b/debian/tests/cryptroot-md.d/config new file mode 100644 index 0000000..0c9e5ff --- /dev/null +++ b/debian/tests/cryptroot-md.d/config @@ -0,0 +1,7 @@ +PKGS_EXTRA+=( e2fsprogs ) # for fsck.ext4 +PKGS_EXTRA+=( lvm2 mdadm ) +PKGS_EXTRA+=( cryptsetup-initramfs ) + +DRIVE_SIZES=( "1536M" "1536M" ) + +# vim: set filetype=bash : diff --git a/debian/tests/cryptroot-md.d/mock b/debian/tests/cryptroot-md.d/mock new file mode 100755 index 0000000..51f8c9c --- /dev/null +++ b/debian/tests/cryptroot-md.d/mock @@ -0,0 +1,41 @@ +#!/usr/bin/perl -T + +BEGIN { + require "./debian/tests/utils/mock.pm"; + CryptrootTest::Mock::->import(); +} + +my %passphrases; +$passphrases{$_} = $_ foreach qw/vda3_crypt vda4_crypt vdb3_crypt vdb4_crypt/; +unlock_disk(\%passphrases) for 1 .. scalar(%passphrases); + +# check that the above was done at initramfs stage +expect($SERIAL => qr#\bRunning /scripts/init-bottom\s*\.\.\. #); + +login("root"); + +# make sure the root FS and swap are help by dm-crypt devices +shell(q{cryptsetup luksOpen --test-passphrase /dev/vda3 <<<vda3_crypt}, rv => 0); +shell(q{cryptsetup luksOpen --test-passphrase /dev/vda4 <<<vda4_crypt}, rv => 0); +shell(q{cryptsetup luksOpen --test-passphrase /dev/vdb3 <<<vdb3_crypt}, rv => 0); +shell(q{cryptsetup luksOpen --test-passphrase /dev/vdb4 <<<vdb4_crypt}, rv => 0); + +my $out = shell(q{lsblk -in -oNAME,TYPE,MOUNTPOINT /dev/vda3}); +die unless $out =~ m#^`-vda3_crypt\s+crypt\s*$#m; +die unless $out =~ m#^ `-md1\s+raid0\s+\[SWAP\]\s*$#m; + +$out = shell(q{lsblk -in -oNAME,TYPE,MOUNTPOINT /dev/vdb3}); +die unless $out =~ m#^`-vdb3_crypt\s+crypt\s*$#m; +die unless $out =~ m#^ `-md1\s+raid0\s+\[SWAP\]\s*$#m; + +$out = shell(q{lsblk -in -oNAME,TYPE,MOUNTPOINT /dev/vda4}); +die unless $out =~ m#^`-vda4_crypt\s+crypt\s*$#m; +die unless $out =~ m#^ [`|]-cryptvg-swap\s+lvm\s+\[SWAP\]\s*$#m; +die unless $out =~ m#^ [`|]-cryptvg-root\s+lvm\s+/\s*$#m; + +$out = shell(q{lsblk -in -oNAME,TYPE,MOUNTPOINT /dev/vdb4}); +die unless $out =~ m#^`-vdb4_crypt\s+crypt\s*$#m; +die unless $out =~ m#^ [`|]-cryptvg-swap\s+lvm\s+\[SWAP\]\s*$#m; +die unless $out =~ m#^ [`|]-cryptvg-root\s+lvm\s+/\s*$#m; + +QMP::quit(); diff --git a/debian/tests/cryptroot-md.d/preinst b/debian/tests/cryptroot-md.d/preinst new file mode 100644 index 0000000..84bfa7a --- /dev/null +++ b/debian/tests/cryptroot-md.d/preinst @@ -0,0 +1,20 @@ +# intentionally mix UUID= and /dev +cat >/etc/crypttab <<-EOF + vda3_crypt UUID=$(blkid -s UUID -o value /dev/vda3) none discard + vda4_crypt UUID=$(blkid -s UUID -o value /dev/vda4) none discard + vdb3_crypt /dev/vdb3 none discard + vdb4_crypt /dev/vdb4 none discard +EOF + +cat >/etc/fstab <<-EOF + /dev/cryptvg/root / auto errors=remount-ro 0 1 + /dev/cryptvg/swap none swap sw 0 0 + /dev/md1 none swap sw 0 0 + UUID=$(blkid -s UUID -o value /dev/md0) /boot auto defaults 0 2 +EOF + +# force unlocking /dev/md1 holders (/dev/vd[ab]3) at initramfs stage +mkdir -p /etc/initramfs-tools/conf.d +echo "RESUME=/dev/md1" >/etc/initramfs-tools/conf.d/resume + +# vim: set filetype=sh : diff --git a/debian/tests/cryptroot-md.d/setup b/debian/tests/cryptroot-md.d/setup new file mode 100644 index 0000000..a8f49ed --- /dev/null +++ b/debian/tests/cryptroot-md.d/setup @@ -0,0 +1,84 @@ +# Rather convoluted LVM-on-MD-on-LUKS2 layout with 2 swap areas, /boot +# on RAID1, SWAP0 on RAID0, LVM on RAID1 and 4 independently encrypted +# partitions decrypt at early boot stage: + +# NAME TYPE MOUNTPOINTS +# vda disk +# ├─vda1 part +# ├─vda2 part +# │ └─md0 raid1 /boot +# ├─vda3 part +# │ └─vda3_crypt crypt +# │ └─md1 raid0 [SWAP] +# └─vda4 part +# └─vda4_crypt crypt +# └─md2 raid1 +# ├─cryptvg-swap lvm [SWAP] +# └─cryptvg-root lvm / +# vdb disk +# ├─vdb1 part +# ├─vdb2 part +# │ └─md0 raid1 /boot +# ├─vdb3 part +# │ └─vdb3_crypt crypt +# │ └─md1 raid0 [SWAP] +# └─vdb4 part +# └─vdb4_crypt crypt +# └─md2 raid1 +# ├─cryptvg-swap lvm [SWAP] +# └─cryptvg-root lvm / + +sfdisk --append /dev/vda <<-EOF + unit: sectors + + start=$((64*1024*2)), size=$((128*1024*2)), type=${GUID_TYPE_Linux_FS} + start=$(((64+128)*1024*2)), size=$((64*1024*2)), type=${GUID_TYPE_LUKS} + start=$(((64+128+64)*1024*2)), type=${GUID_TYPE_LUKS} +EOF +udevadm settle + +# copy vda's partition table onto vdb +sfdisk -d /dev/vda | sfdisk /dev/vdb +udevadm settle + +for d in vda3 vda4 vdb3 vdb4; do + echo -n "${d}_crypt" >/keyfile + cryptsetup luksFormat --batch-mode \ + --key-file=/keyfile \ + --type=luks2 \ + --pbkdf=argon2id \ + --pbkdf-force-iterations=4 \ + --pbkdf-memory=32 \ + -- "/dev/$d" + cryptsetup luksOpen --key-file=/keyfile --allow-discards \ + -- "/dev/$d" "${d}_crypt" + udevadm settle +done + +mdadm --create /dev/md0 --metadata=default --level=1 --raid-devices=2 /dev/vda2 /dev/vdb2 +mdadm --create /dev/md1 --metadata=default --level=0 --raid-devices=2 /dev/mapper/vda3_crypt /dev/mapper/vdb3_crypt +mdadm --create /dev/md2 --metadata=default --level=1 --raid-devices=2 /dev/mapper/vda4_crypt /dev/mapper/vdb4_crypt +udevadm settle + +lvm pvcreate /dev/md2 +lvm vgcreate "cryptvg" /dev/md2 +lvm lvcreate -Zn --size 64m --name "swap" "cryptvg" +lvm lvcreate -Zn -l100%FREE --name "root" "cryptvg" +lvm vgchange -ay "cryptvg" +lvm vgmknodes +udevadm settle + + +mke2fs -Ft ext4 /dev/cryptvg/root +mount -t ext4 /dev/cryptvg/root "$ROOT" + +mkdir "$ROOT/boot" +mke2fs -Ft ext2 -m0 /dev/md0 +mount -t ext2 /dev/md0 "$ROOT/boot" + +mkswap /dev/cryptvg/swap +swapon /dev/cryptvg/swap +mkswap /dev/md1 +swapon /dev/md1 + +# vim: set filetype=sh : |