From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH installer 1/5] install: encrypt the system disks with LUKS2 or native ZFS encryption
Date: Wed, 18 Nov 2026 00:42:25 +0100 [thread overview]
Message-ID: <20261117234330.801935-3-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261117234330.801935-1-t.lamprecht@proxmox.com>
Full-disk encryption keeps the data of a powered-off or removed system
unreadable, for example after a disk was returned for warranty,
decommissioned or stolen. Implement it in the low-level installer, for
an encryption block in the installation config with the passphrase,
which the frontends and answer files get to set in follow-up commits.
The file system determines how the disks are encrypted.
ext4 and xfs installs put LVM, and with it root, swap and the guest
data thin pool, inside a LUKS2 container on the OS partition. Btrfs
installs get one container per member, all with the same passphrase,
which the decrypt_keyctl keyscript asks for once at boot and caches for
the other members. ZFS installs make the pool the encryption root of
native ZFS encryption, so every dataset on the rpool inherits it.
The installer hands the passphrase to cryptsetup and zfs in a key file
on tmpfs that only root can read and that is removed right after, so it
shows up neither in the installation log nor in the command lines of
processes. The file holds the passphrase encoded as UTF-8, as the
console sends it that way when it is typed at boot, so that non-ASCII
passphrases unlock as well.
Encrypted LVM installs get their ESPs managed by proxmox-boot-tool, like
ZFS and Btrfs installs, as GRUB cannot read the kernel from the
encrypted root anymore. With Secure Boot that is GRUB through shim,
otherwise systemd-boot, and the initramfs asks for the passphrase.
Everything that can be checked without the disks is checked before any
of them is wiped: UEFI boot, the passphrase rules, at most 2 ZFS
copies (as OpenZFS keeps encryption metadata where a third copy would
go), cryptsetup in the installer environment and the package pool, and
that no device is open under a name of the new LUKS containers, as
after unlocking an installation from a debug shell.
The passphrase needs at least 8 characters, like the root password,
which also covers the 8 bytes that ZFS requires. The memory cost of the
LUKS2 key slots is capped at a quarter of the memory, as unlocking in
the initramfs warns about, and can fail on, a key slot that needs more
than half of the memory free there, which formatting cannot measure
from the installer environment on hosts with little memory. As the
cryptsetup initramfs hook only warns if it leaves out a container, for
example when its keyscript is missing, the installation fails unless
the initramfs unlocks all of them.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
Proxmox/Install.pm | 254 +++++++++++++++++++++++++++++++++++---
Proxmox/Install/Config.pm | 15 +++
Proxmox/Sys/Block.pm | 2 +-
debian/control | 1 +
test/Makefile | 7 +-
test/fde-preflight.pl | 143 +++++++++++++++++++++
6 files changed, 403 insertions(+), 19 deletions(-)
create mode 100755 test/fde-preflight.pl
diff --git a/Proxmox/Install.pm b/Proxmox/Install.pm
index 08860cd4..363deb63 100644
--- a/Proxmox/Install.pm
+++ b/Proxmox/Install.pm
@@ -5,6 +5,7 @@ use warnings;
use Cwd 'abs_path';
use Encode;
+use Fcntl qw(O_WRONLY O_CREAT O_EXCL);
use POSIX ":sys_wait_h";
use Proxmox::Install::ISOEnv;
@@ -170,6 +171,59 @@ sub btrfs_create {
syscmd($cmd);
}
+# Secrets reach cryptsetup and zfs only through a key file on tmpfs that only root can read, which
+# keeps them out of the command log and of /proc/<pid>/cmdline. They are written as UTF-8, as the
+# console sends a passphrase typed at boot that way. Calls $code with the path of the key file,
+# which is removed afterwards.
+my sub with_secret_keyfile {
+ my ($secret, $code) = @_;
+
+ my $path = "/run/proxmox-installer-key.$$";
+ my $bytes = Encode::encode('UTF-8', $secret, Encode::FB_CROAK() | Encode::LEAVE_SRC());
+ sysopen(my $fh, $path, O_WRONLY | O_CREAT | O_EXCL, 0600)
+ or die "unable to create key file '$path' - $!\n";
+ eval {
+ print {$fh} $bytes or die "unable to write key file '$path' - $!\n";
+ close($fh) or die "unable to write key file '$path' - $!\n";
+ $code->($path);
+ };
+ my $err = $@;
+ unlink($path);
+ die $err if $err;
+}
+
+sub luks_format_and_open {
+ my ($dev, $name) = @_;
+
+ # pinned, so that changed cryptsetup defaults do not silently change new installations
+ my @format_opts = qw(
+ --batch-mode --type luks2 --cipher aes-xts-plain64 --key-size 512 --hash sha256
+ --pbkdf argon2id
+ );
+ # Unlocking in the initramfs warns about, and can fail on, a key slot that needs more than half
+ # of the memory free there, which luksFormat cannot measure from the installer. So use at most a
+ # quarter of the memory, and at most cryptsetup's default of 1 GiB.
+ my $total_kib = Proxmox::Install::RunEnv::get('total_memory') * 1024;
+ my $pbkdf_kib = int($total_kib / 4);
+ $pbkdf_kib = 1024 * 1024 if $pbkdf_kib > 1024 * 1024;
+ push @format_opts, '--pbkdf-memory', $pbkdf_kib, '--label', $name;
+
+ my $enc = Proxmox::Install::Config::get_encryption();
+ with_secret_keyfile(
+ $enc->{passphrase},
+ sub {
+ my ($keyfile) = @_;
+ my $format =
+ ['cryptsetup', 'luksFormat', @format_opts, '--key-file', $keyfile, $dev];
+ syscmd($format) == 0 || die "unable to set up encryption on '$dev'\n";
+ syscmd(['cryptsetup', 'open', '--key-file', $keyfile, $dev, $name]) == 0
+ || die "unable to open encrypted device '$dev'\n";
+ },
+ );
+
+ return "/dev/mapper/$name";
+}
+
sub zfs_ask_existing_zpool_rename {
my ($pool_name) = @_;
@@ -216,7 +270,24 @@ sub zfs_create_rpool {
my $cmd = "zpool create -f -o cachefile=none";
$cmd .= " -o ashift=$zfs_opts->{ashift}" if defined($zfs_opts->{ashift});
- syscmd("$cmd $pool_name $vdev") == 0 || die "unable to create zfs root pool\n";
+ if (my $enc = Proxmox::Install::Config::get_encryption()) {
+ # the pool is the encryption root, so all datasets inherit its key
+ with_secret_keyfile(
+ $enc->{passphrase},
+ sub {
+ my ($keyfile) = @_;
+ my $opts = "-O encryption=aes-256-gcm -O keyformat=passphrase"
+ . " -O keylocation=file://$keyfile";
+ syscmd("$cmd $opts $pool_name $vdev") == 0
+ || die "unable to create zfs root pool\n";
+ # before the key file goes away, so the pool never points to a missing file
+ syscmd("zfs set keylocation=prompt $pool_name") == 0
+ || die "unable to make zfs root pool ask for its passphrase at boot\n";
+ },
+ );
+ } else {
+ syscmd("$cmd $pool_name $vdev") == 0 || die "unable to create zfs root pool\n";
+ }
syscmd("zfs create $pool_name/ROOT") == 0
|| die "unable to create zfs $pool_name/ROOT volume\n";
@@ -947,6 +1018,95 @@ sub generate_ifupdown2_config {
return $ifaces;
}
+# OpenZFS stores encryption metadata where the third copy of a block would go.
+sub assert_zfs_encryption_copies {
+ my $copies = Proxmox::Install::Config::get_zfs_opt('copies') // 1;
+ die "native ZFS encryption allows at most 2 copies\n"
+ if $copies > 2 && defined(Proxmox::Install::Config::get_encryption());
+}
+
+sub assert_disk_passphrase {
+ my ($passphrase) = @_;
+
+ # the minimum of the root password, which also covers the 8 bytes that ZFS requires
+ die "the disk passphrase must be at least 8 characters long\n" if length($passphrase) < 8;
+ # neither can be typed at the boot prompt, and OpenZFS stops reading a key file at a newline
+ die "the disk passphrase must not contain control characters\n"
+ if $passphrase =~ m/[\x00-\x1f\x7f-\x9f]/;
+ my $bytes = Encode::encode('UTF-8', $passphrase, Encode::FB_CROAK() | Encode::LEAVE_SRC());
+ # cryptsetup's own prompt, as used for unlocking from a rescue system, reads at most 512
+ die "the disk passphrase must not be longer than 512 bytes\n" if length($bytes) > 512;
+}
+
+# Names of the LUKS containers that an installation creates, which are already in use.
+sub open_luks_container_names {
+ return grep { m/^luks-r(?:pv|fs\d+)$/ } map { s!^/dev/mapper/!!r } glob('/dev/mapper/luks-r*');
+}
+
+# Everything about the encryption setup that can be checked without the disks, so that a problem is
+# reported before any of them is wiped.
+sub fde_preflight_check {
+ my ($run_env, $pkgdir) = @_;
+
+ my $enc = Proxmox::Install::Config::get_encryption() // return;
+ my $luks = Proxmox::Install::Config::get_encryption_mode() eq 'luks';
+
+ die "full-disk encryption requires booting the installer in UEFI mode\n"
+ if $run_env->{boot_type} ne 'efi';
+ assert_zfs_encryption_copies() if !$luks;
+ assert_disk_passphrase($enc->{passphrase} // '');
+
+ return if is_test_mode();
+
+ if ($luks) {
+ die "this installer environment lacks cryptsetup, required for full-disk encryption\n"
+ if system('command -v cryptsetup >/dev/null 2>&1') != 0;
+ # unlocking at boot happens in the target's initramfs, installed from the package pool
+ my @missing = grep {
+ my @debs = glob("${pkgdir}/${_}_*.deb");
+ !@debs
+ } qw(cryptsetup-initramfs keyutils);
+ die "this installer image lacks packages required for full-disk encryption: @missing\n"
+ if @missing;
+ # opening a container under a name in use fails only after the disks were formatted
+ if (my ($name) = open_luks_container_names()) {
+ die "encrypted device '$name' is open, unmount or deactivate what is on it and close"
+ . " it with 'cryptsetup close $name'\n";
+ }
+ }
+}
+
+# The cryptsetup initramfs hook only warns if it leaves out a container, for example when its
+# keyscript is missing, so check that the initramfs unlocks all of them at boot.
+sub assert_initramfs_unlocks_luks {
+ my ($targetdir, $initrd, $bootdevinfo) = @_;
+
+ # on the target's disk, as its /tmp is a tmpfs during the installation
+ my $dir = '/var/tmp/initramfs-check';
+ eval {
+ syscmd(['chroot', $targetdir, 'unmkinitramfs', $initrd, $dir]) == 0
+ || die "unable to unpack initramfs '$initrd'\n";
+ # an initramfs with early microcode has its main archive in a subdirectory
+ my $root = -d "$targetdir$dir/main" ? "$targetdir$dir/main" : "$targetdir$dir";
+
+ my $crypttab = "$root/cryptroot/crypttab";
+ my %options = map { m/^(\S+)\s+\S+\s+\S+\s+(\S+)/ ? ($1 => $2) : () }
+ split(/\n/, -f $crypttab ? file_read_all($crypttab) : '');
+ my @missing =
+ grep { !defined($options{$_}) } map { $_->{luks_name} // () } @$bootdevinfo;
+ die "initramfs does not unlock the encrypted devices @missing at boot\n" if @missing;
+
+ if (grep { m/(?:^|,)keyscript=decrypt_keyctl(?:,|$)/ } values %options) {
+ for my $path ('lib/cryptsetup/scripts/decrypt_keyctl', 'bin/keyctl') {
+ die "initramfs lacks '/$path', needed to unlock at boot\n" if !-x "$root/$path";
+ }
+ }
+ };
+ my $err = $@;
+ syscmd(['rm', '-rf', "$targetdir$dir"]);
+ die $err if $err;
+}
+
sub extract_data {
my $iso_env = Proxmox::Install::ISOEnv::get();
my $run_env = Proxmox::Install::RunEnv::get();
@@ -961,6 +1121,8 @@ sub extract_data {
die "target '$targetdir' does not exist\n" if !-d $targetdir;
+ fde_preflight_check($run_env, $proxmox_pkgdir);
+
my $starttime = [Time::HiRes::gettimeofday];
my $bootdevinfo = [];
@@ -984,6 +1146,11 @@ sub extract_data {
$use_btrfs = 1;
}
+ my $encrypted = defined(Proxmox::Install::Config::get_encryption());
+ my $luks = (Proxmox::Install::Config::get_encryption_mode() // '') eq 'luks';
+ # ESPs managed by proxmox-boot-tool hold the kernels, as GRUB cannot read an encrypted root
+ my $use_proxmox_boot_tool = $use_zfs || $use_btrfs || $encrypted;
+
if ($use_zfs) {
my $i;
for ($i = 5; $i > 0; $i--) {
@@ -1006,6 +1173,7 @@ sub extract_data {
syscmd("vgchange -an") if !is_test_mode(); # deactivate all detected VGs
if (is_test_mode()) {
+ die "LUKS encryption is not supported in test mode\n" if $luks;
my $test_images = Proxmox::Install::ISOEnv::get_test_images();
$rootdev = abs_path($test_images->[0]); # FIXME: use all selected for test too!
@@ -1049,18 +1217,25 @@ sub extract_data {
my $logical_bsize = @$hd[4];
my ($size, $osdev, $efidev) =
- partition_bootable_disk($devname, $hdsize, '8300');
- $rootdev = $osdev if !defined($rootdev); # simply point to first disk
+ partition_bootable_disk($devname, $hdsize, $luks ? '8309' : '8300');
my $by_id = Proxmox::Sys::Block::get_disk_by_id_path($devname);
- push @$bootdevinfo,
- {
- esp => $efidev,
- devname => $devname,
- osdev => $osdev,
- by_id => $by_id,
- logical_bsize => $logical_bsize,
- };
- push @$btrfs_partitions, $osdev;
+ my $di = {
+ esp => $efidev,
+ devname => $devname,
+ osdev => $osdev,
+ by_id => $by_id,
+ logical_bsize => $logical_bsize,
+ };
+ push @$bootdevinfo, $di;
+
+ # each member gets its own LUKS container, all with the same passphrase
+ my $member = $osdev;
+ if ($luks) {
+ $di->{luks_name} = 'luks-rfs' . (scalar(@$bootdevinfo) - 1);
+ $member = luks_format_and_open($osdev, $di->{luks_name});
+ }
+ $rootdev = $member if !defined($rootdev); # simply point to first disk
+ push @$btrfs_partitions, $member;
}
Proxmox::Sys::Block::udevadm_trigger_block();
@@ -1132,7 +1307,7 @@ sub extract_data {
my $logical_bsize = Proxmox::Sys::Block::logical_blocksize($target_hd);
my ($os_size, $osdev, $efidev) =
- partition_bootable_disk($target_hd, $hdsize, '8E00');
+ partition_bootable_disk($target_hd, $hdsize, $luks ? '8309' : '8E00');
Proxmox::Sys::Block::udevadm_trigger_block();
@@ -1146,10 +1321,22 @@ sub extract_data {
logical_bsize => $logical_bsize,
};
+ # LVM goes inside the LUKS container, so root, swap and guest data are all encrypted
+ my ($pvdev, $pv_size) = ($osdev, $os_size);
+ if ($luks) {
+ update_progress(0, 0.025, $maxper, "set up encryption");
+ $bootdevinfo->[0]->{luks_name} = 'luks-rpv';
+ $pvdev = luks_format_and_open($osdev, 'luks-rpv');
+ # smaller than the partition by the LUKS2 header, in KiB like the partition size
+ my $bytes = run_command(['blockdev', '--getsize64', $pvdev]);
+ die "unable to get size of '$pvdev'\n" if $bytes !~ m/^(\d+)\s*$/;
+ $pv_size = int($1 / 1024);
+ }
+
update_progress(0, 0.03, $maxper, "create LVs");
- my $swap_size = compute_swapsize($os_size);
- ($rootdev, $swapfile, $datadev) = create_lvm_volumes($osdev, $os_size, $swap_size);
+ my $swap_size = compute_swapsize($pv_size);
+ ($rootdev, $swapfile, $datadev) = create_lvm_volumes($pvdev, $pv_size, $swap_size);
# trigger udev to create /dev/disk/by-uuid
Proxmox::Sys::Block::udevadm_trigger_block(1);
@@ -1329,6 +1516,24 @@ sub extract_data {
my $resolvconf = "search $domain\nnameserver $dnsserver\n";
file_write_all("$targetdir/etc/resolv.conf", $resolvconf);
+ # configure crypttab, native ZFS encryption is unlocked by the ZFS initramfs scripts
+ my @luks = grep { defined($_->{luks_name}) } @$bootdevinfo;
+ if (scalar(@luks)) {
+ # 'initramfs' makes cryptsetup-initramfs unlock all of them, not only the root device
+ my $opts = 'luks,discard,initramfs';
+ # asks once and passes the passphrase on to the other Btrfs members
+ $opts .= ',keyscript=decrypt_keyctl' if scalar(@luks) > 1;
+
+ my $crypttab = "# <target name> <source device> <key file> <options>\n";
+ for my $di (@luks) {
+ my $uuid = run_command(['cryptsetup', 'luksUUID', $di->{osdev}]);
+ die "unable to get LUKS UUID of '$di->{osdev}'\n"
+ if $uuid !~ m/^([0-9a-f-]+)\s*$/i;
+ $crypttab .= "$di->{luks_name} UUID=$1 none $opts\n";
+ }
+ file_write_all("$targetdir/etc/crypttab", $crypttab);
+ }
+
# configure fstab
my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
@@ -1374,7 +1579,7 @@ sub extract_data {
# Note: this is required by current grub, but really dangerous, because
# vfat does not have journaling, so it triggers manual fsck after each crash
# so we only mount /boot/efi if really required (efi systems).
- if ($run_env->{boot_type} eq 'efi' && !($use_zfs || $use_btrfs)) {
+ if ($run_env->{boot_type} eq 'efi' && !$use_proxmox_boot_tool) {
if (scalar(@$bootdevinfo)) {
my $di = @$bootdevinfo[0]; # simply use first disk
@@ -1471,6 +1676,8 @@ _EOD
next if ($deb =~ /^proxmox-grub/ && $run_env->{boot_type} ne 'efi');
next if ($deb =~ /^proxmox-secure-boot-support_/ && !$run_env->{secure_boot});
next if $deb =~ /^proxmox-first-boot/ && !needs_first_boot_package();
+ # only needed for LUKS, and the cryptsetup initramfs hook complains about a ZFS root
+ next if $deb =~ /^cryptsetup(?:-initramfs|-bin)?_/ && !$luks;
# CPU microcode packages are x86-only
next if $deb =~ /^amd64-microcode_/ && $run_env->{cpu_vendor_id} ne 'AuthenticAMD';
@@ -1614,6 +1821,16 @@ _EOD
);
}
+ if ($luks && !$use_btrfs) {
+ # encrypted LVM installs boot through proxmox-boot-tool, like ZFS and Btrfs ones
+ my ($vg, $lv) = $rootdev =~ m|^/dev/([^/]+)/([^/]+)$|
+ or die "unexpected root device '$rootdev'\n";
+ file_write_all(
+ "$targetdir/etc/kernel/cmdline",
+ "root=/dev/mapper/$vg-$lv $target_cmdline\n",
+ );
+ }
+
# Always write zfs module parameter - even if the user did not select ZFS-on-root.
# It still makes sense to provide a sensible default for zfs_arc_max, in case a
# separate zfs pool is created afterwards.
@@ -1641,6 +1858,9 @@ _EOD
eval {
syscmd("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0
|| die "unable to install initramfs\n";
+ assert_initramfs_unlocks_luks(
+ $targetdir, "/boot/initrd.img-$kapi", $bootdevinfo,
+ ) if $luks;
my $native_4k_disk_bootable = 0;
foreach my $di (@$bootdevinfo) {
@@ -1649,7 +1869,7 @@ _EOD
foreach my $di (@$bootdevinfo) {
my $dev = $di->{devname};
- if ($use_zfs || $use_btrfs) {
+ if ($use_proxmox_boot_tool) {
prepare_proxmox_boot_esp(
$di->{esp},
$targetdir,
diff --git a/Proxmox/Install/Config.pm b/Proxmox/Install/Config.pm
index dc0b0f63..11d6302c 100644
--- a/Proxmox/Install/Config.pm
+++ b/Proxmox/Install/Config.pm
@@ -84,6 +84,9 @@ my sub init_cfg {
btrfs_opts => {
compress => 'off',
},
+ # full-disk encryption, LUKS2 or native ZFS encryption as per the file system, disabled if
+ # undef, otherwise a hash with the passphrase that unlocks the system at boot
+ encryption => undef,
# TODO: single disk selection config
target_hd => undef,
disk_selection => {},
@@ -219,6 +222,15 @@ sub get_btrfs_opt {
return defined($k) ? $opts->{$k} : $opts;
}
+sub set_encryption { set_key('encryption', $_[0]); }
+sub get_encryption { return get('encryption'); }
+
+# 'luks' for ext4, xfs and btrfs, 'zfs-native' for ZFS, undef without encryption
+sub get_encryption_mode {
+ return undef if !defined(get_encryption());
+ return get_filesys() =~ m/^zfs/ ? 'zfs-native' : 'luks';
+}
+
sub set_target_hd { set_key('target_hd', $_[0]); }
sub get_target_hd { return get('target_hd'); }
@@ -231,6 +243,9 @@ sub get_redacted {
$r->{root_password} = { '<redacted>' => '<redacted>' };
}
$r->{subscription_key} = '<redacted>' if defined($r->{subscription_key});
+ if (defined($r->{encryption}) && defined($r->{encryption}->{passphrase})) {
+ $r->{encryption}->{passphrase} = '<redacted>';
+ }
return $r;
}
diff --git a/Proxmox/Sys/Block.pm b/Proxmox/Sys/Block.pm
index 89b01c96..aa012482 100644
--- a/Proxmox/Sys/Block.pm
+++ b/Proxmox/Sys/Block.pm
@@ -222,7 +222,7 @@ sub partition_bootable_disk {
die "too dangerous" if is_test_mode();
die "unknown partition type '$ptype'"
- if !($ptype eq '8E00' || $ptype eq '8300' || $ptype eq 'BF01');
+ if !($ptype eq '8E00' || $ptype eq '8300' || $ptype eq '8309' || $ptype eq 'BF01');
my $hdsize = hd_size($target_dev); # size in KB (1024 bytes)
diff --git a/debian/control b/debian/control
index 8fa134b1..7371908c 100644
--- a/debian/control
+++ b/debian/control
@@ -45,6 +45,7 @@ Homepage: https://www.proxmox.com
Package: proxmox-installer
Architecture: any
Depends: chrony,
+ cryptsetup-bin,
e2fsprogs,
geoip-bin,
iproute2,
diff --git a/test/Makefile b/test/Makefile
index c095fec8..2749cc2c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,7 +5,8 @@ export PERLLIB=..
.PHONY: check
check: test-zfs-arc-max test-run-command test-parse-fqdn test-ui2-stdio \
test-zfs-get-pool-list test-parse-kernel-cmdline \
- test-validate-link-pin-map test-generate-ifupdown2-config test-live-vlan-links
+ test-validate-link-pin-map test-generate-ifupdown2-config test-live-vlan-links \
+ test-fde-preflight
.PHONY: test-zfs-arc-max
test-zfs-arc-max:
@@ -42,3 +43,7 @@ test-generate-ifupdown2-config:
.PHONY: test-live-vlan-links
test-live-vlan-links:
./live-vlan-links.pl
+
+.PHONY: test-fde-preflight
+test-fde-preflight:
+ ./fde-preflight.pl
diff --git a/test/fde-preflight.pl b/test/fde-preflight.pl
new file mode 100755
index 00000000..4a838184
--- /dev/null
+++ b/test/fde-preflight.pl
@@ -0,0 +1,143 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use File::Temp;
+use Test::More;
+use Test::MockModule qw(strict);
+
+use Proxmox::Install;
+use Proxmox::Log;
+use Proxmox::UI;
+
+my $log_file = File::Temp->new();
+Proxmox::Log::init($log_file->filename);
+Proxmox::UI::init_stdio();
+
+my ($enc, $filesys, $test_mode);
+my $zfs_opts = {};
+my $open_luks = [];
+
+my $config = Test::MockModule->new('Proxmox::Install::Config');
+$config->redefine(
+ get_encryption => sub { return $enc },
+ get_filesys => sub { return $filesys },
+ get_zfs_opt => sub { return defined($_[0]) ? $zfs_opts->{ $_[0] } : $zfs_opts },
+);
+my $install = Test::MockModule->new('Proxmox::Install');
+$install->redefine(
+ is_test_mode => sub { return $test_mode },
+ open_luks_container_names => sub { return @$open_luks },
+);
+
+my $run_env = { boot_type => 'efi' };
+
+sub preflight {
+ my ($pkgdir) = @_;
+ eval { Proxmox::Install::fde_preflight_check($run_env, $pkgdir) };
+ return $@;
+}
+
+$test_mode = 1;
+
+is(preflight(), '', 'no encryption configured');
+
+my $passphrases = {
+ ascii => 'password',
+ latin1 => "p\x{e4}ssword",
+ 'non-latin1' => "\x{2603}" x 8,
+};
+for my $kind (sort keys %$passphrases) {
+ my $passphrase = $passphrases->{$kind};
+
+ $filesys = 'zfs (RAID0)';
+ $enc = { passphrase => $passphrase };
+ is(preflight(), '', "ZFS accepts the $kind passphrase");
+ is($enc->{passphrase}, $passphrase, "ZFS check keeps the $kind passphrase intact");
+
+ $filesys = 'ext4';
+ $enc = { passphrase => $passphrase };
+ is(preflight(), '', "ext4 accepts the $kind passphrase");
+ is($enc->{passphrase}, $passphrase, "ext4 check keeps the $kind passphrase intact");
+}
+
+for my $fs ('zfs (RAID0)', 'ext4') {
+ $filesys = $fs;
+ # 8 bytes encoded, although only 7 characters
+ $enc = { passphrase => "p\x{e4}sswor" };
+ like(preflight(), qr/at least 8 characters/, "$fs rejects a passphrase under 8 characters");
+ is($enc->{passphrase}, "p\x{e4}sswor", 'rejected passphrase is kept intact');
+}
+
+$filesys = 'zfs (RAID0)';
+$enc = { passphrase => 'x' x 513 };
+like(preflight(), qr/longer than 512 bytes/, 'ZFS rejects a passphrase over 512 bytes');
+
+$filesys = 'ext4';
+$enc = { passphrase => 'x' x 512 };
+is(preflight(), '', 'ext4 accepts a passphrase of 512 bytes');
+$enc = { passphrase => "\x{e4}" x 257 };
+like(preflight(), qr/longer than 512 bytes/, 'ext4 rejects a passphrase over 512 bytes');
+
+$filesys = 'btrfs (RAID1)';
+for my $ctrl ("\n", "\t", "\x00", "\x7f", "\x{85}") {
+ $enc = { passphrase => "pass${ctrl}word" };
+ like(
+ preflight(),
+ qr/control characters/,
+ sprintf('rejects control character 0x%02x', ord($ctrl)),
+ );
+}
+
+$enc = { passphrase => '' };
+like(preflight(), qr/at least 8 characters/, 'rejects an empty passphrase');
+
+$filesys = 'zfs (RAID1)';
+$enc = { passphrase => 'password' };
+$zfs_opts->{copies} = 2;
+is(preflight(), '', 'ZFS accepts 2 copies');
+$zfs_opts->{copies} = 3;
+like(preflight(), qr/at most 2 copies/, 'ZFS rejects 3 copies');
+$filesys = 'ext4';
+is(preflight(), '', 'ext4 ignores the ZFS copies');
+$zfs_opts = {};
+
+$filesys = 'xfs';
+$enc = { passphrase => 'password' };
+$run_env->{boot_type} = 'bios';
+like(preflight(), qr/UEFI/, 'requires UEFI boot');
+$run_env->{boot_type} = 'efi';
+
+SKIP: {
+ skip 'cryptsetup not available', 4 if system('command -v cryptsetup >/dev/null 2>&1') != 0;
+
+ $test_mode = 0;
+ my $pool = File::Temp->newdir();
+ like(
+ preflight("$pool"),
+ qr/lacks packages .*: cryptsetup-initramfs keyutils$/m,
+ 'reports missing pool packages',
+ );
+
+ for my $name ('cryptsetup-initramfs_2%3a2.7.5-2_all.deb', 'keyutils_1.6.3-6_amd64.deb') {
+ open(my $deb, '>', "$pool/$name") or die "open: $!\n";
+ close($deb);
+ }
+ is(preflight("$pool"), '', 'accepts a pool with the needed packages');
+
+ $open_luks = ['luks-rfs1'];
+ like(
+ preflight("$pool"),
+ qr/^encrypted device 'luks-rfs1' is open, .* 'cryptsetup close luks-rfs1'$/m,
+ 'refuses a container name that is in use',
+ );
+
+ $filesys = 'zfs (RAID0)';
+ my $empty = File::Temp->newdir();
+ is(preflight("$empty"), '', 'ZFS needs no extra packages and ignores LUKS containers');
+ $open_luks = [];
+ $test_mode = 1;
+}
+
+done_testing();
--
2.47.3
next prev parent reply other threads:[~2026-11-17 23:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 23:42 [PATCH proxmox/installer/docs 0/8] installer: add full-disk encryption of the system disks Thomas Lamprecht
2026-11-17 23:42 ` [PATCH proxmox 1/1] installer-types: add full-disk encryption to the disk setup Thomas Lamprecht
2026-11-17 23:42 ` Thomas Lamprecht [this message]
2026-11-17 23:42 ` [PATCH installer 2/5] auto: support full-disk encryption in answer files Thomas Lamprecht
2026-11-17 23:42 ` [PATCH installer 3/5] chroot enter: unlock the LUKS containers of an encrypted installation Thomas Lamprecht
2026-11-17 23:42 ` [PATCH installer 4/5] ui: offer full-disk encryption in the graphical and terminal installer Thomas Lamprecht
2026-11-17 23:42 ` [PATCH installer 5/5] assistant: keep the disk passphrase out of prepared ISOs Thomas Lamprecht
2026-11-17 23:42 ` [PATCH docs 1/2] installation: describe full-disk encryption Thomas Lamprecht
2026-11-17 23:42 ` [PATCH docs 2/2] local-zfs: update the limitations of native encryption Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117234330.801935-3-t.lamprecht@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox