From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 72C831FF15E for ; Mon, 29 Sep 2025 17:48:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D523616D79; Mon, 29 Sep 2025 17:48:32 +0200 (CEST) From: Christian Ebner To: pdm-devel@lists.proxmox.com Date: Mon, 29 Sep 2025 17:48:15 +0200 Message-ID: <20250929154820.892720-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250929154820.892720-1-c.ebner@proxmox.com> References: <20250929154820.892720-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759160890221 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.041 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH proxmox 1/3] proxmox-login: refactor PVE TFA compat mode X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" In preparation for extending the compat mode by Proxmox Backup Server version 3 API compatibility for login ticket parsing. Instead of storing the compat mode as simple boolean flag and only considering PVE, use a `CompatMode` enum instead. Further, make the variable and method names more generic. Signed-off-by: Christian Ebner --- proxmox-login/src/lib.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/proxmox-login/src/lib.rs b/proxmox-login/src/lib.rs index 4482f2e4..e7b8e023 100644 --- a/proxmox-login/src/lib.rs +++ b/proxmox-login/src/lib.rs @@ -49,7 +49,15 @@ pub struct Login { api_url: String, userid: String, password: Option, - pve_compat: bool, + compat_mode: CompatMode, +} + +/// Compatibility mode to use for login or ticket renewal. +#[derive(Copy, Clone, Debug, Default, PartialEq)] +pub enum CompatMode { + #[default] + Generic, + PveTfa, } fn normalize_url(mut api_url: String) -> String { @@ -90,9 +98,14 @@ impl Login { /// Prepare a request given an already parsed ticket. pub fn renew_ticket(api_url: impl Into, ticket: Ticket) -> Self { + let compat_mode = if ticket.product() == "PVE" { + CompatMode::PveTfa + } else { + CompatMode::default() + }; Self { api_url: normalize_url(api_url.into()), - pve_compat: ticket.product() == "PVE", + compat_mode, userid: ticket.userid().to_string(), password: Some(ticket.into()), } @@ -103,7 +116,7 @@ impl Login { pub fn renew_with_cookie(api_url: impl Into, userid: impl Into) -> Self { Self { api_url: normalize_url(api_url.into()), - pve_compat: false, + compat_mode: CompatMode::default(), userid: userid.into(), password: None, } @@ -119,13 +132,13 @@ impl Login { api_url: normalize_url(api_url.into()), userid: userid.into(), password: Some(password.into()), - pve_compat: false, + compat_mode: CompatMode::default(), } } /// Set the Proxmox VE compatibility parameter for Two-Factor-Authentication support. - pub fn pve_compatibility(mut self, compatibility: bool) -> Self { - self.pve_compat = compatibility; + pub fn set_compatibility(mut self, compat_mode: CompatMode) -> Self { + self.compat_mode = compat_mode; self } @@ -135,8 +148,13 @@ impl Login { /// [`response`](Login::response) method in order to extract the validated ticket or /// Two-Factor-Authentication challenge. pub fn request(&self) -> Request { + let new_format = if self.compat_mode == CompatMode::PveTfa { + Some(true) + } else { + None + }; let request = api::CreateTicket { - new_format: self.pve_compat.then_some(true), + new_format, username: self.userid.clone(), password: self.password.clone(), ..Default::default() @@ -225,7 +243,7 @@ impl Login { TicketResponse::Tfa(ticket, challenge) => { TicketResult::TfaRequired(SecondFactorChallenge { api_url: self.api_url.clone(), - pve_compat: self.pve_compat, + pve_compat: self.compat_mode == CompatMode::PveTfa, userid: response.username, ticket, challenge, -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel