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 v2 manager 12/19] ui: dc options: allow editing the API token policy
Date: Sun, 15 Nov 2026 20:40:33 +0100	[thread overview]
Message-ID: <20261115194043.3947825-13-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261115194043.3947825-1-t.lamprecht@proxmox.com>

Render and edit the new datacenter token-policy option. The maximum
lifetime is entered in days, fractional values are allowed for
sub-day lifetimes, and the exact stored value is kept when the field
is left untouched, so a finer grained value set via the API survives
unrelated edits.

A set maximum lifetime implies requiring an expiration date, so the
dialog locks that checkbox on while a lifetime is entered to make the
implication visible, and restores the previous choice once the
lifetime is cleared again.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---

changes since v1:
- adapt to 'disallow-expiry-extension'
- lock the require-expiry checkbox on while a maximum lifetime is set

 www/manager6/dc/OptionView.js | 136 ++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index dc12aa7e1..d5bc1a538 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -384,6 +384,142 @@ Ext.define('PVE.dc.OptionView', {
                 },
             ],
         });
+        me.rows['token-policy'] = {
+            required: true,
+            header: gettext('API Token Policy'),
+            renderer: function (policy) {
+                if (!policy) {
+                    return Proxmox.Utils.NoneText;
+                }
+                let parts = [];
+                if (Number(policy['require-expiry'])) {
+                    parts.push(gettext('Require Expiration Date'));
+                }
+                if (policy['max-lifetime'] !== undefined) {
+                    let lifetime = Proxmox.Utils.format_duration_human(
+                        Number(policy['max-lifetime']),
+                    );
+                    parts.push(Ext.String.format(gettext('Max. Lifetime: {0}'), lifetime));
+                }
+                if (Number(policy['disallow-expiry-extension'])) {
+                    parts.push(gettext('Disallow Extending Expiration'));
+                }
+                if (Number(policy['require-privilege-separation'])) {
+                    parts.push(gettext('Require Privilege Separation'));
+                }
+                return parts.length ? parts.join(', ') : Proxmox.Utils.NoneText;
+            },
+            editor: {
+                xtype: 'proxmoxWindowEdit',
+                subject: gettext('API Token Policy'),
+                onlineHelp: 'pveum_token_policy',
+                url: '/api2/extjs/cluster/options',
+                width: 450,
+                fieldDefaults: {
+                    labelWidth: 200,
+                },
+                setValues: function (values) {
+                    let me = this;
+                    // max-lifetime is stored in seconds but edited in days; keep the exact stored
+                    // value for saving an untouched field
+                    let policy = Ext.apply({}, values['token-policy'] || {});
+                    me.storedMaxLifetime = policy['max-lifetime'];
+                    // the maximum lifetime may lock the checkbox before it gets set below
+                    me.down('field[name=require-expiry]').explicitValue = !!Number(
+                        policy['require-expiry'],
+                    );
+                    if (policy['max-lifetime'] !== undefined) {
+                        policy['max-lifetime'] =
+                            Math.ceil((Number(policy['max-lifetime']) / 86400) * 100) / 100;
+                    }
+                    Ext.Array.each(me.query('inputpanel'), (panel) => panel.setValues(policy));
+                },
+                items: [
+                    {
+                        xtype: 'inputpanel',
+                        onGetValues: function (values) {
+                            let me = this;
+                            let win = me.up('proxmoxWindowEdit');
+                            let policy = {};
+                            // read the field directly, it is disabled and thus not part of the
+                            // values while a maximum lifetime implies it
+                            if (me.down('field[name=require-expiry]').getValue()) {
+                                policy['require-expiry'] = 1;
+                            }
+                            if (values['disallow-expiry-extension']) {
+                                policy['disallow-expiry-extension'] = 1;
+                            }
+                            if (values['require-privilege-separation']) {
+                                policy['require-privilege-separation'] = 1;
+                            }
+                            let days = values['max-lifetime'];
+                            if (days !== undefined && days !== null && days !== '') {
+                                let untouched = !me.down('field[name=max-lifetime]').isDirty();
+                                policy['max-lifetime'] =
+                                    untouched && win.storedMaxLifetime !== undefined
+                                        ? win.storedMaxLifetime
+                                        : Math.round(Number(days) * 86400);
+                            }
+                            if (Object.keys(policy).length === 0) {
+                                return { delete: 'token-policy' };
+                            }
+                            return { 'token-policy': PVE.Parser.printPropertyString(policy) };
+                        },
+                        items: [
+                            {
+                                xtype: 'proxmoxcheckbox',
+                                name: 'require-expiry',
+                                uncheckedValue: 0,
+                                fieldLabel: gettext('Require Expiration Date'),
+                                listeners: {
+                                    // remember an explicit choice to restore it once a maximum
+                                    // lifetime no longer implies it
+                                    change: function (field, value) {
+                                        if (!field.isDisabled()) {
+                                            field.explicitValue = value;
+                                        }
+                                    },
+                                },
+                            },
+                            {
+                                xtype: 'numberfield',
+                                name: 'max-lifetime',
+                                minValue: 0.01,
+                                emptyText: gettext('No limit'),
+                                fieldLabel: gettext('Maximum Lifetime (days)'),
+                                listeners: {
+                                    // a maximum lifetime implies requiring an expiration date,
+                                    // show that by locking the checkbox on
+                                    change: function (field, value) {
+                                        let requireExpiry = field
+                                            .up('inputpanel')
+                                            .down('field[name=require-expiry]');
+                                        let implied = value !== null && value !== undefined;
+                                        // lock before setting, to keep the remembered choice
+                                        requireExpiry.setDisabled(implied);
+                                        requireExpiry.setValue(
+                                            implied || !!requireExpiry.explicitValue,
+                                        );
+                                    },
+                                },
+                            },
+                            {
+                                xtype: 'proxmoxcheckbox',
+                                name: 'disallow-expiry-extension',
+                                uncheckedValue: 0,
+                                fieldLabel: gettext('Disallow Extending Expiration'),
+                            },
+                            {
+                                xtype: 'proxmoxcheckbox',
+                                name: 'require-privilege-separation',
+                                uncheckedValue: 0,
+                                fieldLabel: gettext('Require Privilege Separation'),
+                            },
+                        ],
+                    },
+                ],
+            },
+        };
         me.rows['tag-style'] = {
             required: true,
             renderer: (value) => {
-- 
2.47.3





  parent reply	other threads:[~2026-11-15 19:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 19:40 [PATCH v2 cluster/access-control/docs/manager/proxmox 0/19] fix #7805: add a datacenter-wide API token policy Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 cluster 1/19] datacenter config: add token-policy option Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 cluster 2/19] datacenter config: token policy: add default-to-max-lifetime setting Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 cluster 3/19] datacenter config: token policy: allow extension on regeneration Thomas Lamprecht
2026-11-17 13:30   ` Shannon Sterz
2026-11-15 19:40 ` [PATCH v2 access-control 4/19] fix #7805: api: token: enforce datacenter token policy Thomas Lamprecht
2026-11-17 13:30   ` Shannon Sterz
2026-11-15 19:40 ` [PATCH v2 access-control 5/19] api: token: apply the default lifetime from the " Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 access-control 6/19] api: token: allow extending tokens on secret regeneration Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 docs 7/19] user management: document the API token policy Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 docs 8/19] user management: document the default-to-max-lifetime setting Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 docs 9/19] user management: document extending tokens on secret regeneration Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 manager 10/19] ui: token edit: only submit the expiration date when changed Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 manager 11/19] api: cluster options: return token-policy without Sys.Audit Thomas Lamprecht
2026-11-15 19:40 ` Thomas Lamprecht [this message]
2026-11-15 19:40 ` [PATCH v2 manager 13/19] ui: token edit: adapt to the datacenter API token policy Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 manager 14/19] ui: token policy: expose the default-to-max-lifetime setting Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 manager 15/19] ui: token policy: allow extension on secret regeneration Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 proxmox 16/19] access-control: add API token policy type with expiry checks Thomas Lamprecht
2026-11-17 13:29   ` Shannon Sterz
2026-11-15 19:40 ` [PATCH v2 proxmox 17/19] access-control: enforce token policy on token create and update Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 proxmox 18/19] access-control: apply a default token lifetime from the policy Thomas Lamprecht
2026-11-15 19:40 ` [PATCH v2 proxmox 19/19] access-control: allow extending tokens on secret regeneration Thomas Lamprecht
2026-11-17 13:29   ` Shannon Sterz
2026-11-17 13:29 ` [PATCH v2 cluster/access-control/docs/manager/proxmox 0/19] fix #7805: add a datacenter-wide API token policy Shannon Sterz
2026-11-18  2:17 ` applied: " 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=20261115194043.3947825-13-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