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 7BA2A1FF15C for ; Fri, 25 Jul 2025 13:19:46 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 38C2816501; Fri, 25 Jul 2025 13:21:07 +0200 (CEST) From: Shannon Sterz To: pbs-devel@lists.proxmox.com Date: Fri, 25 Jul 2025 13:20:19 +0200 Message-ID: <20250725112019.245838-5-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250725112019.245838-1-s.sterz@proxmox.com> References: <20250725112019.245838-1-s.sterz@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753442459653 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.022 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 Subject: [pbs-devel] [PATCH proxmox-backup 1/1] api/proxy: set auth cookie name in rest server api config X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" set the name of the auth cookie when configuring apis to allow the rest server to remove invalid tickets on 401 requests. Signed-off-by: Shannon Sterz --- src/auth.rs | 10 +++++++++- src/auth_helpers.rs | 1 + src/bin/proxmox-backup-api.rs | 1 + src/bin/proxmox-backup-proxy.rs | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/auth.rs b/src/auth.rs index 86b12a76..ac24c8ca 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -13,7 +13,7 @@ use pbs_config::open_backup_lockfile; use proxmox_router::http_bail; use serde_json::json; -use proxmox_auth_api::api::{Authenticator, LockedTfaConfig}; +use proxmox_auth_api::api::{AuthContext, Authenticator, LockedTfaConfig}; use proxmox_auth_api::ticket::{Empty, Ticket}; use proxmox_auth_api::types::Authid; use proxmox_auth_api::{HMACKey, Keyring}; @@ -377,6 +377,14 @@ pub fn setup_auth_context(use_private_key: bool) { proxmox_auth_api::set_auth_context(AUTH_CONTEXT.get().unwrap()); } +pub fn get_auth_cookie_name() -> String { + AUTH_CONTEXT + .get() + .expect("auth context needs to be set before accessing the auth cookie name") + .prefixed_auth_cookie_name() + .to_string() +} + pub(crate) fn private_auth_keyring() -> &'static Keyring { &PRIVATE_KEYRING } diff --git a/src/auth_helpers.rs b/src/auth_helpers.rs index 65e36308..fdd8d663 100644 --- a/src/auth_helpers.rs +++ b/src/auth_helpers.rs @@ -10,6 +10,7 @@ use proxmox_sys::fs::{file_get_contents, replace_file, CreateOptions}; use pbs_buildcfg::configdir; use serde_json::json; +pub use crate::auth::get_auth_cookie_name; pub use crate::auth::setup_auth_context; pub use proxmox_auth_api::api::assemble_csrf_prevention_token; diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index 3d80b023..74528236 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -88,6 +88,7 @@ async fn run() -> Result<(), Error> { let config = ApiConfig::new(pbs_buildcfg::JS_DIR, RpcEnvironmentType::PRIVILEGED) .index_handler_func(|_, _| get_index()) .auth_handler_func(|h, m| Box::pin(check_pbs_auth(h, m))) + .auth_cookie_name(proxmox_backup::auth_helpers::get_auth_cookie_name()) .default_api2_handler(&proxmox_backup::api2::ROUTER) .enable_access_log( pbs_buildcfg::API_ACCESS_LOG_FN, diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 694c2463..4641fed1 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -195,6 +195,7 @@ async fn run() -> Result<(), Error> { let mut config = ApiConfig::new(pbs_buildcfg::JS_DIR, RpcEnvironmentType::PUBLIC) .index_handler_func(|e, p| Box::pin(get_index_future(e, p))) .auth_handler_func(|h, m| Box::pin(check_pbs_auth(h, m))) + .auth_cookie_name(proxmox_backup::auth_helpers::get_auth_cookie_name()) .register_template("index", &indexpath)? .register_template("console", "/usr/share/pve-xtermjs/index.html.hbs")? .default_api2_handler(&proxmox_backup::api2::ROUTER) -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel