public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Shannon Sterz" <s.sterz@proxmox.com>
To: "Thomas Lamprecht" <t.lamprecht@proxmox.com>,
	<pve-devel@lists.proxmox.com>
Subject: Re: [PATCH proxmox 9/9] access-control: enforce token policy on token create and update
Date: Tue, 10 Nov 2026 16:04:58 +0100	[thread overview]
Message-ID: <DMRMGBP25C3E.3T9NO5MD643A9@proxmox.com> (raw)
In-Reply-To: <20260923210000.4031318-10-t.lamprecht@proxmox.com>

On Wed Sep 23, 2026 at 10:59 PM CEST, Thomas Lamprecht wrote:
> 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())?;
> +        }
> +    }

nit: moving this check in the previous if-let clause that checks whether
the expiry is to be updated would make it a bit cleaner imo.

note that there is no way besides setting `expire = 0` to remove an
expiry.

> +
>      let new_secret = if regenerate == Some(true) {
>          let secret = token_shadow::generate_and_set_secret(&tokenid)?;
>          Some(ApiTokenSecret { tokenid, secret })





  reply	other threads:[~2026-11-10 15:05 UTC|newest]

Thread overview: 18+ 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-11-10 15:05   ` Shannon Sterz
2026-11-10 16:00     ` 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-11-10 15:05   ` Shannon Sterz
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-11-10 15:05   ` Shannon Sterz
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-11-10 15:05   ` Shannon Sterz
2026-09-23 20:59 ` [PATCH proxmox 9/9] access-control: enforce token policy on token create and update Thomas Lamprecht
2026-11-10 15:04   ` Shannon Sterz [this message]
2026-11-10 15:05 ` [PATCH cluster/access-control/manager/docs/proxmox 0/9] fix #7805: add a datacenter-wide API token policy Shannon Sterz
2026-11-10 15:28   ` Thomas Lamprecht

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=DMRMGBP25C3E.3T9NO5MD643A9@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.lamprecht@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