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 39E4E941B3 for ; Thu, 8 Feb 2024 17:47:09 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 130043018B for ; Thu, 8 Feb 2024 17:46:39 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 8 Feb 2024 17:46:38 +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 CCA6045551 for ; Thu, 8 Feb 2024 17:46:37 +0100 (CET) Message-ID: <326092b9-4f52-427c-850c-963ba33f3839@proxmox.com> Date: Thu, 8 Feb 2024 17:46:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Christoph Heiss Cc: Proxmox VE development discussion References: <20240123170053.490250-1-a.lauterer@proxmox.com> <20240123170053.490250-15-a.lauterer@proxmox.com> From: Aaron Lauterer In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.065 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 16:47:09 -0000 On 2/8/24 15:18, Christoph Heiss wrote: > 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. For now sure. If we add additional plugins to fetch the answer file via a URL, we might want to place the ssl fingerprint on the same partition. Then we would have to either mount it again, or wait with the unmount until we have reached the end of going through the plugins, as a cleanup measure. > >> + > [..] >> + >> + /// 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. Good point! > >> + .output() >> + { >> + Ok(output) => { >> + if output.status.success() { >> + Ok(()) >> + } else { >> + warn!("Error mounting: {}", String::from_utf8(output.stderr)?); >> + Ok(()) >> + } >> + } >> + Err(err) => bail!("Error mounting: {}", err), >> + } >> + } >> + > [..]