all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Markus Frank <m.frank@proxmox.com>, pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH widget-toolkit v1 1/2] window: add optional autocreate-role selector to openid realm edit
Date: Thu, 27 Feb 2025 09:46:34 +0100	[thread overview]
Message-ID: <d7b318b3-53c5-428a-858e-c595d736f7f8@proxmox.com> (raw)
In-Reply-To: <20250227075517.3364-2-m.frank@proxmox.com>

Am 27.02.25 um 08:55 schrieb Markus Frank:
> The enableRoleSelector option enables the role selector, and
> roleSelector can be overridden with a specific role selector such as
> pmgRoleSelector (displayfield is used as a placeholder for the role
> selector).
> 
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
>  src/panel/AuthView.js        |  4 ++++
>  src/window/AuthEditBase.js   |  6 ++++++
>  src/window/AuthEditOpenId.js | 35 +++++++++++++++++++++++------------
>  3 files changed, 33 insertions(+), 12 deletions(-)
> 
> diff --git a/src/panel/AuthView.js b/src/panel/AuthView.js
> index 7bebf0d..2f777fc 100644
> --- a/src/panel/AuthView.js
> +++ b/src/panel/AuthView.js
> @@ -14,6 +14,8 @@ Ext.define('Proxmox.panel.AuthView', {
>  
>      baseUrl: '/access/domains',
>      storeBaseUrl: '/access/domains',
> +    enableRoleSelector: false,
> +    roleSelector: 'displayfield',

meh, this "common" component really gets overly-specialized, would have been
probably much easier to maintain and flexible if we copied that over to PMG..

Anyhow, I'd favor changing the configuration for role-assignment, having just
a fixed one is IMO not really ideal, and as is the "autocreate-role" property
is confusing (no role gets autocreated) and not flexible enough.

I'd rather transform the backend into something like the diff below, maybe
skipping the from-claim for today as such a format then would be easy to
extend later anyway.

The UI component might be better off for now to get a generic extraColumn1/2
parameter to avoid having to add an over-specialized one for every product
specific feature (@Dominik, what do you think about that?).

----8<----
diff --git a/src/PMG/API2/OIDC.pm b/src/PMG/API2/OIDC.pm
index 92ff88d..f2cba60 100644
--- a/src/PMG/API2/OIDC.pm
+++ b/src/PMG/API2/OIDC.pm
@@ -204,7 +204,21 @@ __PACKAGE__->register_method ({
                    if (defined(my $family_name = $info->{'family_name'})) {
                        $entry->{lastname} = $family_name;
                    }
-                   $entry->{role} = $config->{'autocreate-role'} // 'audit';
+                   $entry->{role} = 'audit'; # default
+                   if (my $role_assignment_raw = $config->{'autocreate-role-assignment'}) {
+                       my $role_assignment =
+                           PVE::Plugin::Auth::OIDC::parse_autocreate_role_assignment($role_assignment_raw);
+
+                       if ($role_assignment->{source} eq 'fixed') {
+                           $entry->{role} = $role_assignment->{'fixed-role'};
+                       } elsif ($role_assignment->{source} eq 'fixed') {
+                           my $role_attr = $role_assignment->{'role-claim'};
+                           $entry->{role} = $info->{$role_attr}
+                               or die "required '$role_attr' role-claim attribute not found, cannot autocreate user\n";
+                       } else {
+                           die "unkown role assignment source '$role_assignment->{source}' - implement me";
+                       }
+                   }
                    $entry->{userid} = $username;
                    $entry->{username} = $unique_name;
                    $entry->{realm} = $realm;
diff --git a/src/PMG/Auth/OIDC.pm b/src/PMG/Auth/OIDC.pm
index 4129d47..26a1e3f 100755
--- a/src/PMG/Auth/OIDC.pm
+++ b/src/PMG/Auth/OIDC.pm
@@ -4,6 +4,8 @@ use strict;
 use warnings;
 
 use PVE::Tools;
+use PVE::JSONSchema qw(parse_property_string);
+
 use PMG::Auth::Plugin;
 
 use base qw(PMG::Auth::Plugin);
@@ -12,6 +14,44 @@ sub type {
     return 'oidc';
 }
 
+my $autocreate_role_assignment_format = {
+    source => {
+       type => 'string',
+       enum => ['fixed', 'from-claim'],
+       default => 'fixed',
+       description => "How the access role for a newly auto-created user should be selected.",
+    },
+    'fixed-role' => {
+       type => 'string',
+       enum => ['admin', 'qmanager', 'audit', 'helpdesk'],
+       default => 'audit',
+       optional => 1,
+       description => "The fixed role that should be assigned to auto-created users.",
+    },
+    'role-claim' => {
+       description => "OIDC claim used to assign the unique username.",
+       type => 'string',
+       default => 'role',
+       optional => 1,
+       pattern => qr/^[a-zA-Z0-9._:-]+$/,
+    },
+};
+
+
+sub parse_autocreate_role_assignment {
+    my ($raw) = @_;
+    return undef if !$raw or !length($raw);
+
+    my $role_assignment = parse_property_string($autocreate_role_assignment_format, $raw);
+    $role_assignment->{'fixed-role'} = 'audit'
+       if $role_assignment->{'source'} eq 'fixed' && !defined($role_assignment->{'fixed-role'});
+
+    $role_assignment->{'role-claim'} = 'role'
+       if $role_assignment->{'source'} eq 'from-clain' && !defined($role_assignment->{'role-claim'});
+
+    return $role_assignment;
+}
+
 sub properties {
     return {
        'issuer-url' => {
@@ -39,11 +79,10 @@ sub properties {
            type => 'boolean',
            default => 0,
        },
-       'autocreate-role' => {
-           description => "Automatically create users with a specific role.",
-           type => 'string',
-           enum => ['admin', 'qmanager', 'audit', 'helpdesk'],
-           default => 'audit',
+       'autocreate-role-assignment' => {
+           description => "Defines which role should be assigned to auto-created users.",
+           type => 'string', format => $autocreate_role_assignment_format,
+           default => 'source=fixed,fixed-role=auditor',
            optional => 1,
        },
        'username-claim' => {
@@ -84,7 +123,7 @@ sub options {
        'client-id' => {},
        'client-key' => { optional => 1 },
        autocreate => { optional => 1 },
-       'autocreate-role' => { optional => 1 },
+       'autocreate-role-assignment' => { optional => 1 },
        'username-claim' => { optional => 1, fixed => 1 },
        prompt => { optional => 1 },
        scopes => { optional => 1 },


_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


  reply	other threads:[~2025-02-27  8:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-27  7:55 [pmg-devel] [PATCH widget-toolkit/pmg-api v1 0/2] add roleSelector for OIDC Markus Frank
2025-02-27  7:55 ` [pmg-devel] [PATCH widget-toolkit v1 1/2] window: add optional autocreate-role selector to openid realm edit Markus Frank
2025-02-27  8:46   ` Thomas Lamprecht [this message]
2025-02-27  7:55 ` [pmg-devel] [PATCH pmg-gui v1 2/2] realm: enable role selector for realm edit windows Markus Frank

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=d7b318b3-53c5-428a-858e-c595d736f7f8@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=m.frank@proxmox.com \
    --cc=pmg-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal