From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id A350D1FF0C0 for ; Wed, 18 Nov 2026 00:44:34 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 398E02172E; Wed, 18 Nov 2026 00:43:48 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH installer 2/5] auto: support full-disk encryption in answer files Date: Wed, 18 Nov 2026 00:42:26 +0100 Message-ID: <20261117234330.801935-4-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117234330.801935-1-t.lamprecht@proxmox.com> References: <20261117234330.801935-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794959018375 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.193 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: Y37OIHWDAOIG6TDJ247D3FSADZSQBXVI X-Message-ID-Hash: Y37OIHWDAOIG6TDJ247D3FSADZSQBXVI X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Pass the `[disk-setup.encryption]` section of answer files on to the low-level installer, which picks LUKS2 or native ZFS encryption based on the filesystem. The encryption options are checked along with the rest of the answer file, before any disk is touched. The post-installation webhook reports the encryption mode, as schema version 1.4. proxmox-chroot loads the key of a natively encrypted pool from the saved installation config, so that the post-installation hook sees the installed system and not a pool imported with all its datasets locked and unmounted. In a rescue shell, where no such config exists, it asks for the passphrase on the terminal, and it exports the pool again if unlocking fails, so that it can be retried. Signed-off-by: Thomas Lamprecht --- Cargo.toml | 2 +- debian/control | 2 +- proxmox-auto-installer/src/utils.rs | 13 ++- proxmox-auto-installer/tests/parse-answer.rs | 5 + .../parse_answer/encryption_luks.json | 26 +++++ .../parse_answer/encryption_luks.toml | 17 ++++ .../parse_answer/encryption_zfs.json | 36 +++++++ .../parse_answer/encryption_zfs.toml | 24 +++++ .../encryption_empty_passphrase.json | 3 + .../encryption_empty_passphrase.toml | 17 ++++ .../encryption_passphrase_control_char.json | 3 + .../encryption_passphrase_control_char.toml | 17 ++++ .../encryption_passphrase_too_short.json | 3 + .../encryption_passphrase_too_short.toml | 17 ++++ proxmox-chroot/src/main.rs | 95 +++++++++++++++++++ proxmox-installer-common/src/setup.rs | 17 ++++ proxmox-post-hook/src/main.rs | 8 +- proxmox-tui-installer/src/setup.rs | 1 + 18 files changed, 300 insertions(+), 6 deletions(-) create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.toml create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.json create mode 100644 proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.toml diff --git a/Cargo.toml b/Cargo.toml index 90ee0415..c3abf84b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ toml = "0.8" proxmox-auto-installer.path = "./proxmox-auto-installer" proxmox-installer-common.path = "./proxmox-installer-common" proxmox-network-types = "1.2" -proxmox-installer-types = { version = "0.3.1", features = ["legacy"] } +proxmox-installer-types = { version = "0.4", features = ["legacy"] } # Local path overrides # NOTE: You must run `cargo update` after changing this for it to take effect! diff --git a/debian/control b/debian/control index 7371908c..8de90ba4 100644 --- a/debian/control +++ b/debian/control @@ -19,7 +19,7 @@ Build-Depends: cargo:native, librust-native-tls-dev, librust-pico-args-0.5-dev, librust-pretty-assertions-1.4-dev, - librust-proxmox-installer-types-0.3+legacy-dev (>= 0.3.1-~~), + librust-proxmox-installer-types-0.4+legacy-dev, librust-proxmox-network-types-1-dev (>= 1.2-~~), librust-proxmox-sys+crypt-dev, librust-regex-1+default-dev (>= 1.7~~), diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs index 9813f56e..bfa54e4e 100644 --- a/proxmox-auto-installer/src/utils.rs +++ b/proxmox-auto-installer/src/utils.rs @@ -23,8 +23,8 @@ use proxmox_installer_common::{ is_bond_mode_unsuitable_for_bridge, }, setup::{ - InstallBtrfsOption, InstallConfig, InstallFirstBootSetup, InstallRootPassword, - InstallZfsOption, LocaleInfo, NetworkInfo, RuntimeInfo, SetupInfo, + InstallBtrfsOption, InstallConfig, InstallEncryption, InstallFirstBootSetup, + InstallRootPassword, InstallZfsOption, LocaleInfo, NetworkInfo, RuntimeInfo, SetupInfo, }, }; use proxmox_network_types::MacAddress; @@ -615,6 +615,8 @@ pub fn verify_disks_settings(answer: &AutoInstallerConfig) -> Result<()> { _ => {} } + answer.disks.verify_encryption()?; + Ok(()) } @@ -745,6 +747,7 @@ pub fn parse_answer( maxvz: None, zfs_opts: None, btrfs_opts: None, + encryption: None, target_hd: None, disk_selection: BTreeMap::new(), existing_storage_auto_rename: 1, @@ -820,6 +823,12 @@ pub fn parse_answer( } } + if let Some(encryption) = &answer.disks.encryption { + config.encryption = Some(InstallEncryption { + passphrase: encryption.passphrase.clone(), + }); + } + if let Some(first_boot) = &answer.first_boot { config.first_boot.enabled = true; config.first_boot.ordering_target = diff --git a/proxmox-auto-installer/tests/parse-answer.rs b/proxmox-auto-installer/tests/parse-answer.rs index 1923bf84..c4652225 100644 --- a/proxmox-auto-installer/tests/parse-answer.rs +++ b/proxmox-auto-installer/tests/parse-answer.rs @@ -121,6 +121,8 @@ mod tests { disk_match_all, disk_match_all_missing_property, disk_match_any, + encryption_luks, + encryption_zfs, first_boot, fqdn_from_dhcp, fqdn_from_dhcp_empty_dhcp_domain_setting, @@ -156,6 +158,9 @@ mod tests { both_password_and_hashed_set, btrfs_raid_single_disk, duplicate_disk, + encryption_empty_passphrase, + encryption_passphrase_control_char, + encryption_passphrase_too_short, fqdn_from_dhcp_no_default_domain, fqdn_hostname_only, ipv4_and_subnet_mask_33, diff --git a/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.json b/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.json new file mode 100644 index 00000000..f161ee7f --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.json @@ -0,0 +1,26 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "testinstall", + "filesys": "ext4", + "gateway": "192.168.1.1", + "hdsize": 223.57088470458984, + "existing_storage_auto_rename": 1, + "hostname": "pveauto", + "keymap": "de", + "mailto": "mail@no.invalid", + "mngmt_nic": "eno1", + "root_password": { + "plain": "12345678" + }, + "target_hd": "/dev/sda", + "timezone": "Europe/Vienna", + "first_boot": { + "enabled": 0 + }, + "encryption": { + "passphrase": "pässphrase" + } +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.toml b/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.toml new file mode 100644 index 00000000..3cfa43e1 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/encryption_luks.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "pveauto.testinstall" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] + +[disk-setup.encryption] +passphrase = "p\u00e4ssphrase" diff --git a/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.json b/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.json new file mode 100644 index 00000000..d284edc8 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.json @@ -0,0 +1,36 @@ +{ + "autoreboot": 1, + "cidr": "192.168.1.114/24", + "country": "at", + "dns": "192.168.1.254", + "domain": "testinstall", + "disk_selection": { + "6": "6", + "7": "7" + }, + "existing_storage_auto_rename": 1, + "filesys": "zfs (RAID1)", + "gateway": "192.168.1.1", + "hdsize": 80.0, + "hostname": "pveauto", + "keymap": "de", + "mailto": "mail@no.invalid", + "mngmt_nic": "eno1", + "root_password": { + "plain": "12345678" + }, + "timezone": "Europe/Vienna", + "zfs_opts": { + "arc_max": 2048, + "ashift": 12, + "checksum": "on", + "compress": "lz4", + "copies": 2 + }, + "first_boot": { + "enabled": 0 + }, + "encryption": { + "passphrase": "zfs passphrase" + } +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.toml b/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.toml new file mode 100644 index 00000000..9b6baf79 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer/encryption_zfs.toml @@ -0,0 +1,24 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "pveauto.testinstall" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "zfs" +zfs.raid = "raid1" +zfs.ashift = 12 +zfs.checksum = "on" +zfs.compress = "lz4" +zfs.copies = 2 +zfs.hdsize = 80 +zfs.arc-max = 2048 +disk-list = ["sda", "sdb"] + +[disk-setup.encryption] +passphrase = "zfs passphrase" diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.json new file mode 100644 index 00000000..6ad207d7 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.json @@ -0,0 +1,3 @@ +{ + "error": "'disk-setup.encryption.passphrase' must be at least 8 characters long" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.toml new file mode 100644 index 00000000..3e02c3f6 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_empty_passphrase.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "pveauto.testinstall" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] + +[disk-setup.encryption] +passphrase = "" diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.json new file mode 100644 index 00000000..36414984 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.json @@ -0,0 +1,3 @@ +{ + "error": "'disk-setup.encryption.passphrase' must not contain control characters" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.toml new file mode 100644 index 00000000..39c02370 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_control_char.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "pveauto.testinstall" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] + +[disk-setup.encryption] +passphrase = "pass\nphrase" diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.json b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.json new file mode 100644 index 00000000..6ad207d7 --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.json @@ -0,0 +1,3 @@ +{ + "error": "'disk-setup.encryption.passphrase' must be at least 8 characters long" +} diff --git a/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.toml b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.toml new file mode 100644 index 00000000..ef00995b --- /dev/null +++ b/proxmox-auto-installer/tests/resources/parse_answer_fail/encryption_passphrase_too_short.toml @@ -0,0 +1,17 @@ +[global] +keyboard = "de" +country = "at" +fqdn = "pveauto.testinstall" +mailto = "mail@no.invalid" +timezone = "Europe/Vienna" +root-password = "12345678" + +[network] +source = "from-dhcp" + +[disk-setup] +filesystem = "ext4" +disk-list = ["sda"] + +[disk-setup.encryption] +passphrase = "p\u00e4sswor" diff --git a/proxmox-chroot/src/main.rs b/proxmox-chroot/src/main.rs index bcba1ce5..d6cd48b7 100644 --- a/proxmox-chroot/src/main.rs +++ b/proxmox-chroot/src/main.rs @@ -240,10 +240,105 @@ fn mount_zpool(pool_id: Option) -> Result<()> { Ok(s) if !s.success() => bail!("Could not import ZFS pool. Abort!"), _ => (), } + + // A natively encrypted pool imports with its datasets locked and unmounted, so import success + // alone does not mean that the target is mounted. + if let Err(err) = unlock_zpool() { + // exported again, so that a retry can import it + umount_zpool(); + return Err(err); + } + println!("successfully imported ZFS pool to {TARGET_DIR}"); Ok(()) } +fn unlock_zpool() -> Result<()> { + if !zpool_keystatus_unavailable()? { + return Ok(()); + } + + load_zpool_key()?; + // Only this pool, other pools may be imported in the installer environment. + let status = Command::new("zfs") + .args(["mount", "-R", ZPOOL_NAME]) + .status() + .map_err(|err| anyhow::anyhow!("failed to run 'zfs mount -R {ZPOOL_NAME}': {err}"))?; + if !status.success() { + bail!("could not mount the datasets of '{ZPOOL_NAME}' after loading its key"); + } + let mounted = Command::new("mountpoint") + .args(["-q", TARGET_DIR]) + .status() + .map_err(|err| anyhow::anyhow!("failed to run 'mountpoint': {err}"))?; + if !mounted.success() { + bail!("{TARGET_DIR} is not mounted after unlocking '{ZPOOL_NAME}'"); + } + Ok(()) +} + +/// Whether the pool's encryption root still needs its key loaded. An unencrypted pool reports `-`. +fn zpool_keystatus_unavailable() -> Result { + let out = Command::new("zfs") + .args(["get", "-H", "-o", "value", "keystatus", ZPOOL_NAME]) + .output() + .map_err(|err| anyhow::anyhow!("failed to query ZFS keystatus: {err}"))?; + if !out.status.success() { + bail!( + "failed to query the keystatus of '{ZPOOL_NAME}': {}", + String::from_utf8_lossy(&out.stderr).trim() + ); + } + match String::from_utf8_lossy(&out.stdout).trim() { + "unavailable" => Ok(true), + "available" | "-" => Ok(false), + other => bail!("unexpected keystatus '{other}' for '{ZPOOL_NAME}'"), + } +} + +/// Right after an installation, the passphrase comes from the 0600 low-level config on the +/// installer's tmpfs, as the caller may be the unattended post-installation hook. Otherwise, for +/// example in a rescue shell, `zfs` asks for it on the terminal. +fn load_zpool_key() -> Result<()> { + use std::io::{IsTerminal, Write}; + + let passphrase = get_low_level_config() + .ok() + .and_then(|config| config.encryption) + .map(|encryption| encryption.passphrase); + let Some(passphrase) = passphrase else { + if !io::stdin().is_terminal() { + bail!( + "cannot unlock ZFS pool '{ZPOOL_NAME}' - its passphrase can only be entered on a terminal" + ); + } + let status = Command::new("zfs") + .args(["load-key", ZPOOL_NAME]) + .status() + .map_err(|err| anyhow::anyhow!("failed to run 'zfs load-key': {err}"))?; + if !status.success() { + bail!("could not load the key of ZFS pool '{ZPOOL_NAME}'"); + } + return Ok(()); + }; + + let mut child = Command::new("zfs") + .args(["load-key", "-L", "prompt", ZPOOL_NAME]) + .stdin(process::Stdio::piped()) + .spawn() + .map_err(|err| anyhow::anyhow!("failed to run 'zfs load-key': {err}"))?; + child + .stdin + .as_mut() + .ok_or_else(|| anyhow::anyhow!("could not write to 'zfs load-key' stdin"))? + .write_all(format!("{passphrase}\n").as_bytes())?; + + if !child.wait()?.success() { + bail!("'zfs load-key' failed for pool '{ZPOOL_NAME}'"); + } + Ok(()) +} + fn umount_zpool() { match Command::new("zpool").arg("export").arg(ZPOOL_NAME).status() { Ok(s) if !s.success() => println!("failure on exporting {ZPOOL_NAME}"), diff --git a/proxmox-installer-common/src/setup.rs b/proxmox-installer-common/src/setup.rs index 3882f892..9e041e4c 100644 --- a/proxmox-installer-common/src/setup.rs +++ b/proxmox-installer-common/src/setup.rs @@ -546,6 +546,20 @@ pub fn spawn_low_level_installer(test_mode: bool) -> io::Result .spawn() } +/// See Proxmox::Install::Config +#[derive(Clone, Deserialize, Serialize)] +pub struct InstallEncryption { + pub passphrase: String, +} + +impl fmt::Debug for InstallEncryption { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("InstallEncryption") + .field("passphrase", &"") + .finish() + } +} + /// See Proxmox::Install::Config #[derive(Debug, Deserialize, Serialize)] pub struct InstallConfig { @@ -568,6 +582,9 @@ pub struct InstallConfig { #[serde(skip_serializing_if = "Option::is_none")] pub btrfs_opts: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub encryption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub target_hd: Option, diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs index 4b24b16a..55ca515f 100644 --- a/proxmox-post-hook/src/main.rs +++ b/proxmox-post-hook/src/main.rs @@ -20,7 +20,7 @@ use proxmox_installer_common::http::{self, header::HeaderMap}; use proxmox_installer_types::answer::{AutoInstallerConfig, PostNotificationHookInfo}; /// Current version of the schema sent by this implementation. -const POST_HOOK_SCHEMA_VERSION: &str = "1.3"; +const POST_HOOK_SCHEMA_VERSION: &str = "1.4"; mod detail { use anyhow::{Context, Result, anyhow, bail}; @@ -39,7 +39,7 @@ mod detail { setup::{InstallConfig, RuntimeInfo, SetupInfo, load_installer_setup_files}, }; use proxmox_installer_types::{ - ProxmoxProduct, SystemDMI, UdevInfo, + EncryptionMode, ProxmoxProduct, SystemDMI, UdevInfo, answer::{AutoInstallerConfig, FqdnConfig, FqdnFromDhcpConfig, FqdnSourceMode}, post_hook::{ BootInfo, CpuInfo, DiskInfo, KernelVersionInformation, NetworkInterfaceInfo, @@ -154,6 +154,10 @@ mod detail { } }), filesystem: answer.disks.filesystem_details()?.to_type(), + encryption: config + .encryption + .as_ref() + .map(|_| EncryptionMode::for_filesystem(config.filesys)), fqdn, machine_id: read_file("/etc/machine-id").unwrap_or_else(|e| { eprintln!("could not gather machine-id: {e:#}"); diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs index b8a990fd..fc3c43df 100644 --- a/proxmox-tui-installer/src/setup.rs +++ b/proxmox-tui-installer/src/setup.rs @@ -21,6 +21,7 @@ impl From for InstallConfig { maxvz: None, zfs_opts: None, btrfs_opts: None, + encryption: None, target_hd: None, disk_selection: BTreeMap::new(), existing_storage_auto_rename: 0, -- 2.47.3