From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id B6E001FF09D for ; Sun, 15 Nov 2026 20:42:44 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 5C56421832; Sun, 15 Nov 2026 20:41:08 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH v2 proxmox 17/19] access-control: enforce token policy on token create and update Date: Sun, 15 Nov 2026 20:40:38 +0100 Message-ID: <20261115194043.3947825-18-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261115194043.3947825-1-t.lamprecht@proxmox.com> References: <20261115194043.3947825-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794771650204 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.227 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 43GQCHPZUPWJVS3LNGY4LW2MIDJRYPI2 X-Message-ID-Hash: 43GQCHPZUPWJVS3LNGY4LW2MIDJRYPI2 X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: An update only checks the expiration date if its value actually changes, so unrelated edits or clients resubmitting unchanged fields are not rejected for tokens that predate the policy. The check runs before the secret is generated, or rotated on update, to avoid leaving an orphaned entry in the token shadow file, or losing the old secret, for a rejected request. Signed-off-by: Thomas Lamprecht --- changes since v1: - use separate expiry checks for new tokens and updates; fetch the policy when an expiration date is submitted and let the update check accept an unchanged date proxmox-access-control/src/api/tokens.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/proxmox-access-control/src/api/tokens.rs b/proxmox-access-control/src/api/tokens.rs index f7417934..e2d144eb 100644 --- a/proxmox-access-control/src/api/tokens.rs +++ b/proxmox-access-control/src/api/tokens.rs @@ -97,6 +97,12 @@ pub fn generate_token( ); } + // check the policy before generating the secret to avoid leaving an orphaned entry in the + // token shadow file on rejection + if let Some(policy) = crate::init::access_conf().token_policy()? { + policy.check_new_expiry(expire.unwrap_or(0), proxmox_time::epoch_i64())?; + } + let secret = token_shadow::generate_and_set_secret(&tokenid)?; let token = ApiToken { @@ -203,6 +209,10 @@ pub fn update_token( } if let Some(expire) = expire { + if let Some(policy) = crate::init::access_conf().token_policy()? { + let current = data.expire.unwrap_or(0); + policy.check_expiry_update(expire, current, proxmox_time::epoch_i64())?; + } data.expire = if expire > 0 { Some(expire) } else { None }; } -- 2.47.3