From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BC4AF9418C for ; Thu, 8 Feb 2024 15:18:33 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 988A71E41C for ; Thu, 8 Feb 2024 15:18:33 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 8 Feb 2024 15:18:32 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A00AF4511E for ; Thu, 8 Feb 2024 15:18:32 +0100 (CET) Date: Thu, 8 Feb 2024 15:18:31 +0100 From: Christoph Heiss To: Aaron Lauterer Cc: Proxmox VE development discussion Message-ID: References: <20240123170053.490250-1-a.lauterer@proxmox.com> <20240123170053.490250-15-a.lauterer@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240123170053.490250-15-a.lauterer@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v1 installer 14/18] auto-installer: add fetch answer binary X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Feb 2024 14:18:33 -0000 Sorry for not including this in the first email. On Tue, Jan 23, 2024 at 06:00:49PM +0100, Aaron Lauterer wrote: [..] > diff --git a/proxmox-auto-installer/src/fetch_plugins/partition.rs b/proxmox-auto-installer/src/fetch_plugins/partition.rs > new file mode 100644 > index 0000000..0552ddd > --- /dev/null > +++ b/proxmox-auto-installer/src/fetch_plugins/partition.rs > @@ -0,0 +1,102 @@ > +use anyhow::{bail, Result}; > +use log::{info, warn}; > +use std::fs::read_to_string; > +use std::path::{Path, PathBuf}; > +use std::process::Command; > + > +static ANSWER_FILE: &str = "answer.toml"; > +static ANSWER_MP: &str = "/mnt/answer"; > +static PARTLABEL: &str = "proxmoxinst"; > +static SEARCH_PATH: &str = "/dev/disk/by-label"; > + > +pub struct FetchFromPartition; > + > +impl FetchFromPartition { > + /// Returns the contents of the answer file > + pub fn get_answer() -> Result { > + let part_path = Self::scan_partlabels()?; > + Self::mount_part(part_path)?; > + Self::get_answer_file() Before returning, the partition should be unmounted, as it is not needed anymore after this point. This also prevents some funny error that occurs if the installation fails due to some error. The next time `proxmox-fetch-answer` is run, it cannot mount the answer partition anymore, due to being already mounted. > + [..] > + > + /// Will mount source path to ANSWER_MP > + /// > + /// # Arguments > + /// > + /// * `source` - `PathBuf` of the source location > + fn mount_part(source: PathBuf) -> Result<()> { > + info!("Mounting partition at {ANSWER_MP}"); > + // create dir for mountpoint > + match Command::new("/usr/bin/mkdir") > + .arg(ANSWER_MP) > + .arg("-p") > + .output() > + { > + Ok(output) => { > + if !output.status.success() { > + warn!( > + "Error creating mount path: {}", > + String::from_utf8(output.stderr)? > + ) > + } > + } > + Err(err) => bail!("Error creating mount path: {}", err), > + } > + match Command::new("/usr/bin/mount") > + .arg(source) > + .arg(ANSWER_MP) I'd argue the partition should be mounted with `-o ro` and thus readonly, just for the sake of it. We never write to it anyway and this would prevent any (accidental) attempt to do so in the future. > + .output() > + { > + Ok(output) => { > + if output.status.success() { > + Ok(()) > + } else { > + warn!("Error mounting: {}", String::from_utf8(output.stderr)?); > + Ok(()) > + } > + } > + Err(err) => bail!("Error mounting: {}", err), > + } > + } > + [..]