[pve-devel] [PATCH installer v2 5/6] auto-installer: add new `global.root_password_hashed` answer option

Christoph Heiss c.heiss at proxmox.com
Mon Jul 15 09:56:05 CEST 2024


This allows user to specify the root password in a hashed format,
generated using e.g. mkpasswd(1), instead of plaintext.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
Changes v1 -> v2:
  * move root password setting validation into own function
  * explicitly check for case for both are unset

 proxmox-auto-installer/src/answer.rs |  3 ++-
 proxmox-auto-installer/src/utils.rs  | 16 ++++++++++++++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/proxmox-auto-installer/src/answer.rs b/proxmox-auto-installer/src/answer.rs
index aab7198..d691da1 100644
--- a/proxmox-auto-installer/src/answer.rs
+++ b/proxmox-auto-installer/src/answer.rs
@@ -26,7 +26,8 @@ pub struct Global {
     pub keyboard: KeyboardLayout,
     pub mailto: String,
     pub timezone: String,
-    pub root_password: String,
+    pub root_password: Option<String>,
+    pub root_password_hashed: Option<String>,
     #[serde(default)]
     pub reboot_on_error: bool,
     #[serde(default)]
diff --git a/proxmox-auto-installer/src/utils.rs b/proxmox-auto-installer/src/utils.rs
index 229b7e2..2500f43 100644
--- a/proxmox-auto-installer/src/utils.rs
+++ b/proxmox-auto-installer/src/utils.rs
@@ -303,6 +303,17 @@ pub fn verify_locale_settings(answer: &Answer, locales: &LocaleInfo) -> Result<(
     Ok(())
 }
 
+fn verify_root_password_settings(answer: &Answer) -> Result<()> {
+    if answer.global.root_password.is_some() && answer.global.root_password_hashed.is_some() {
+        bail!("`global.root_password` and `global.root_password_hashed` cannot be set at the same time");
+    } else if answer.global.root_password.is_none() && answer.global.root_password_hashed.is_none()
+    {
+        bail!("One of `global.root_password` or `global.root_password_hashed` must be set");
+    } else {
+        Ok(())
+    }
+}
+
 pub fn parse_answer(
     answer: &Answer,
     udev_info: &UdevInfo,
@@ -318,6 +329,7 @@ pub fn parse_answer(
     let network_settings = get_network_settings(answer, udev_info, runtime_info, setup_info)?;
 
     verify_locale_settings(answer, locales)?;
+    verify_root_password_settings(answer)?;
 
     let mut config = InstallConfig {
         autoreboot: 1_usize,
@@ -337,8 +349,8 @@ pub fn parse_answer(
         keymap: answer.global.keyboard.to_string(),
 
         root_password: InstallRootPassword {
-            plain: Some(answer.global.root_password.clone()),
-            hashed: None,
+            plain: answer.global.root_password.clone(),
+            hashed: answer.global.root_password_hashed.clone(),
         },
         mailto: answer.global.mailto.clone(),
         root_ssh_keys: answer.global.root_ssh_keys.clone(),
-- 
2.45.1





More information about the pve-devel mailing list