From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 687B21FF189 for ; Thu, 4 Sep 2025 01:19:07 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4851617265; Thu, 4 Sep 2025 01:19:20 +0200 (CEST) To: pve-devel@lists.proxmox.com Date: Wed, 3 Sep 2025 19:18:28 -0400 MIME-Version: 1.0 Message-ID: List-Id: Proxmox VE development discussion List-Post: From: Peter via pve-devel Precedence: list Cc: Peter X-Mailman-Version: 2.1.29 X-BeenThere: pve-devel@lists.proxmox.com List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Proxmox VE development discussion List-Help: Subject: [pve-devel] [PATCH installer v2 1/1] assistant: validate: add verify-password option Content-Type: multipart/mixed; boundary="===============1190719474556351278==" Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" --===============1190719474556351278== Content-Type: message/rfc822 Content-Disposition: inline Return-Path: X-Original-To: pve-devel@lists.proxmox.com Delivered-To: pve-devel@lists.proxmox.com Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E03BFD3859 for ; Thu, 4 Sep 2025 01:19:17 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BB76117238 for ; Thu, 4 Sep 2025 01:18:47 +0200 (CEST) Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 4 Sep 2025 01:18:46 +0200 (CEST) Received: by mail-qk1-x72e.google.com with SMTP id af79cd13be357-807e414bf03so64743585a.0 for ; Wed, 03 Sep 2025 16:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756941519; x=1757546319; darn=lists.proxmox.com; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=HwbAoqc9pVzFOniECWzFaTVxOlSafjNxWIlaPcbx0mc=; b=h/mwX+5Y91GcFRIPRGmQSGwG1/vDEXmeXUBQiYHl/Nfs1W+SNJyXNVa3mMyFXISreJ QJDrFOqfK0cWZMI3VmshKy6NOojbpk4MlTqr95FXu64NKZ55pCDa6gGOUV4FXOtr36fz DYY7gNw+u9ihLDDH2aixYzd71VhK7xX+cjd69Qhj3D9q+QkHQZxcgnoYeq+KkShWcz1L c0s9s81E+Mq5DgJs2QMBBJN/Qcq97A5WQjqVieDijui9Q5pn4WGdtBluDoJwQcNe4un/ fO5i9jvbnIJT63WAUXvcfQbugWUhh0lIrdpEQW/7v0ZYag0LeOkVcZyVR2pR/9BgQiXC 7GKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756941519; x=1757546319; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HwbAoqc9pVzFOniECWzFaTVxOlSafjNxWIlaPcbx0mc=; b=l6MTiW8XLTyiU2c8n5y52kYju75beqQMke5aACyj2xyhJKnJtJEA7jPRXX9nixExE+ MaDDT1BzgjG2uwFsnGnzw6ls2XQ5rnaQeE+paUYnLydx9TZpqcHtgaDLGgiaoINckV1Q nJacuthBzWFcuvVQk11gtgLsvcg+0Z5h3ahgiiX7HcSMpdlDCOMaH2CfNGs9uDyXqojj MsACql51H3Oby03IbJljihsk6RlaUXeT0PiIB4KGNI5ZrymK5S48W2wS5Sk+AQNIxFlI hJMIx76wAxBGiiR5+mKu4GlcOn/1m/xCgZHezwUL0IPBB8jY8PKOpBY5p1Cmr1UozuAf 1a8g== X-Gm-Message-State: AOJu0Yw6bl0p5XBTuu7jpQDB+K6v9/z6YaiOnGyj0NXUBtlFfA7ksem9 +4d3W5oNkrjVXZ7OS16G9km96IatE1Zq619Q76mv4SYSRy94BNcVx/B5/cy4cw== X-Gm-Gg: ASbGnctTrzdtTKirABpUsmTmfLWTq7YMIx6Mam+6cbSIQ9m17keCHcGBxfYpTElfMaH mdTLm3qrBfvbAzDE5N4p0klsvhKpWx3GLSB7vr/bjNn9CqbqohHFBu+0jLmIg+gsw/3wE/A64st xYJvqsE2IQpigHlShfTTrnw5CQtXH1J7iM/gYSNysZ0TivnqtW0PDcuct+u9n3M2YDEZe5u3F4x wtDhm6qZjmGNj3tLfTBByj4tqZUT5W7e1Z+M/5syZ1HWVZV2dIO1Ger3/H+JtAa22MRwyHrMLpR M2+obRGHuF/WBmTnfhtCpqlWPn39QieGnJlE2kp6tmbYsMfB+lw8XYoGblCkUSLYbinyMB2iC0b 9tcHddPP8UhE/O3M/XeyT/1xu1tC7f89SDc7mYj0KhNcRMMcfDouWiO4I+P8qdXxedqAK5UcQbk GXo+S2z75YrSS/lRgVuN/8EeAtqXVz9FE7aAPeKALx5YN01qHQHDaO4HBEfPUUN7RtpkJnIOhbC MWKRw== X-Google-Smtp-Source: AGHT+IH/flMPAyE5KehP+uZgO+W9bnV8svx7+EL2PkE7p2vIIJV28XkZKLA4tPSV39GJdRP/qNAwog== X-Received: by 2002:a05:620a:6003:b0:802:e408:1eb6 with SMTP id af79cd13be357-802e408228dmr1314922385a.18.1756941518648; Wed, 03 Sep 2025 16:18:38 -0700 (PDT) Received: from pvedev.in.creath.net (pool-173-76-101-7.bstnma.fios.verizon.net. [173.76.101.7]) by smtp.gmail.com with ESMTPSA id af79cd13be357-80aabd6b054sm178970085a.57.2025.09.03.16.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Sep 2025 16:18:38 -0700 (PDT) Sender: Peter Creath From: Peter To: pve-devel@lists.proxmox.com Subject: [PATCH installer v2 1/1] assistant: validate: add verify-password option Date: Wed, 3 Sep 2025 19:18:28 -0400 Message-ID: <20250903231828.53459-1-pjcreath+proxmox@gmail.com> X-Mailer: git-send-email 2.47.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy FREEMAIL_FROM 0.001 Sender email is commonly abused enduser mail provider RCVD_IN_DNSWL_NONE -0.0001 Sender listed at https://www.dnswl.org/, no trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [main.rs] Adds an option to interactively verify the hashed root password in the answer file, so that mistakes can be caught before installation. Signed-off-by: Peter --- changes since v1: * revised code to depend on proxmox crates instead of external crypt and rpassword * changed flag to --verify-root-password * added a check that stdin is a tty before prompting for password proxmox-auto-install-assistant/Cargo.toml | 1 + proxmox-auto-install-assistant/src/main.rs | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/proxmox-auto-install-assistant/Cargo.toml b/proxmox-auto-install-assistant/Cargo.toml index 9b4a9c4..eeba42f 100644 --- a/proxmox-auto-install-assistant/Cargo.toml +++ b/proxmox-auto-install-assistant/Cargo.toml @@ -17,4 +17,5 @@ proxmox-installer-common = { workspace = true, features = [ "cli" ] } serde_json.workspace = true toml.workspace = true +proxmox-sys = { version = "1.0.0", features = [ "crypt" ] } glob = "0.3" diff --git a/proxmox-auto-install-assistant/src/main.rs b/proxmox-auto-install-assistant/src/main.rs index 5d6c1d5..98b4f23 100644 --- a/proxmox-auto-install-assistant/src/main.rs +++ b/proxmox-auto-install-assistant/src/main.rs @@ -6,6 +6,9 @@ use anyhow::{Context, Result, bail, format_err}; use glob::Pattern; +use proxmox_sys::linux::tty::read_password; +use proxmox_sys::crypt::verify_crypt_pw; +use std::io::IsTerminal; use std::{ collections::BTreeMap, fmt, fs, @@ -153,12 +156,15 @@ struct CommandValidateAnswerArgs { path: PathBuf, /// Whether to also show the full answer as parsed. debug: bool, + /// Interactively verify the hashed root password. + verify_password: bool, } impl cli::Subcommand for CommandValidateAnswerArgs { fn parse(args: &mut cli::Arguments) -> Result { Ok(Self { debug: args.contains(["-d", "--debug"]), + verify_password: args.contains("--verify-root-password"), // Needs to be last path: args.free_from_str()?, }) @@ -176,6 +182,7 @@ ARGUMENTS: OPTIONS: -d, --debug Also show the full answer as parsed. + --verify-root-password Interactively verify the hashed root password. -h, --help Print this help -V, --version Print version "#, @@ -184,6 +191,10 @@ OPTIONS: } fn run(&self) -> Result<()> { + if self.verify_password && !std::io::stdin().is_terminal() { + Self::print_usage(); + bail!("Verifying the root password requires an interactive terminal."); + } validate_answer(self) } } @@ -545,6 +556,20 @@ fn validate_answer_file_keys(path: impl AsRef + fmt::Debug) -> Result Result<()> { + if let Some(hashed) = &answer.global.root_password_hashed { + println!("Verifying hashed root password."); + + let password = String::from_utf8(read_password("Enter root password to verify: ")?)?; + verify_crypt_pw(&password, hashed)?; + + println!("Password matches hashed password."); + Ok(()) + } else { + bail!("'root-password-hashed' not set in answer file, cannot verify."); + } +} + fn validate_answer(args: &CommandValidateAnswerArgs) -> Result<()> { let mut valid = validate_answer_file_keys(&args.path)?; @@ -553,6 +578,12 @@ fn validate_answer(args: &CommandValidateAnswerArgs) -> Result<()> { if args.debug { println!("Parsed data from answer file:\n{:#?}", answer); } + if args.verify_password { + if let Err(err) = verify_hashed_password_interactive(&answer) { + eprintln!("{err:#}"); + valid = false; + } + } } Err(err) => { eprintln!("{err:#}"); -- 2.47.2 --===============1190719474556351278== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel --===============1190719474556351278==--