public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox 9/9] access-control: enforce token policy on token create and update
Date: Wed, 23 Sep 2026 22:59:58 +0200	[thread overview]
Message-ID: <20260923210000.4031318-10-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20260923210000.4031318-1-t.lamprecht@proxmox.com>

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 <t.lamprecht@proxmox.com>
---
 proxmox-access-control/src/api/tokens.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/proxmox-access-control/src/api/tokens.rs b/proxmox-access-control/src/api/tokens.rs
index f7417934..58295793 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_expiry_change(expire.unwrap_or(0), false, proxmox_time::epoch_i64())?;
+    }
+
     let secret = token_shadow::generate_and_set_secret(&tokenid)?;
 
     let token = ApiToken {
@@ -180,6 +186,7 @@ pub fn update_token(
     let tokenid_string = tokenid.to_string();
 
     let mut data: ApiToken = config.lookup("token", &tokenid_string)?;
+    let old_expire = data.expire.unwrap_or(0);
 
     if let Some(delete) = delete {
         for delete_prop in delete {
@@ -206,6 +213,16 @@ pub fn update_token(
         data.expire = if expire > 0 { Some(expire) } else { None };
     }
 
+    // enforce the policy only if this update actually changes the expiration date, so unrelated
+    // edits do not retroactively reject tokens that predate the policy; check before a requested
+    // secret regeneration so a rejected update does not rotate the secret either
+    let new_expire = data.expire.unwrap_or(0);
+    if new_expire != old_expire {
+        if let Some(policy) = crate::init::access_conf().token_policy()? {
+            policy.check_expiry_change(new_expire, true, proxmox_time::epoch_i64())?;
+        }
+    }
+
     let new_secret = if regenerate == Some(true) {
         let secret = token_shadow::generate_and_set_secret(&tokenid)?;
         Some(ApiTokenSecret { tokenid, secret })
-- 
2.47.3





      parent reply	other threads:[~2026-09-23 21:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 20:59 [PATCH cluster/access-control/manager/docs/proxmox 0/9] fix #7805: add a datacenter-wide API token policy Thomas Lamprecht
2026-09-23 20:59 ` [PATCH cluster 1/9] datacenter config: add token-policy option Thomas Lamprecht
2026-09-23 20:59 ` [PATCH access-control 2/9] fix #7805: api: token: enforce datacenter token policy Thomas Lamprecht
2026-09-23 20:59 ` [PATCH docs 3/9] user management: document the API " Thomas Lamprecht
2026-09-23 20:59 ` [PATCH manager 4/9] ui: token edit: only submit the expiration date when changed Thomas Lamprecht
2026-09-23 20:59 ` [PATCH manager 5/9] api: cluster options: return token-policy without Sys.Audit Thomas Lamprecht
2026-09-23 20:59 ` [PATCH manager 6/9] ui: dc options: allow editing the API token policy Thomas Lamprecht
2026-09-23 20:59 ` [PATCH manager 7/9] ui: token edit: adapt to the datacenter " Thomas Lamprecht
2026-09-23 20:59 ` [PATCH proxmox 8/9] access-control: add API token policy type with expiry checks Thomas Lamprecht
2026-09-23 20:59 ` Thomas Lamprecht [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260923210000.4031318-10-t.lamprecht@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal