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 384FD1FF15C for ; Fri, 25 Jul 2025 14:22:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1EFBC17AE8; Fri, 25 Jul 2025 14:23:21 +0200 (CEST) Message-ID: <76c1f7da-339e-45be-a05c-5d63a6a96a01@proxmox.com> Date: Fri, 25 Jul 2025 14:23:17 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta To: Proxmox Backup Server development discussion , Shannon Sterz References: <20250725112357.247866-1-s.sterz@proxmox.com> <20250725112357.247866-5-s.sterz@proxmox.com> Content-Language: en-US From: Dominik Csapak In-Reply-To: <20250725112357.247866-5-s.sterz@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753446194650 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: Re: [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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" LGTM Reviewed-by: Dominik Csapak Tested-by: Dominik Csapak On 7/25/25 13:24, Shannon Sterz wrote: > 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) _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel