[pmg-devel] [PATCH pmg-api v6 5/12] config: add oidc type authentication realm
Mira Limbeck
m.limbeck at proxmox.com
Wed Feb 26 11:20:28 CET 2025
On 2/25/25 14:36, Markus Frank wrote:
> PMG::Auth::OIDC is based on pve-access-control's PVE::Auth::OpenId and
> adds an autocreate-role option. If the autocreate option is enabled, the
> user is automatically created with the Audit role. With autocreate-role
> this role can be changed.
>
> Signed-off-by: Markus Frank <m.frank at proxmox.com>
> ---
> v6: added regex patterns to restrict the string types
>
> src/Makefile | 1 +
> src/PMG/AccessControl.pm | 2 +
> src/PMG/Auth/OIDC.pm | 101 +++++++++++++++++++++++++++++++++++++++
> 3 files changed, 104 insertions(+)
> create mode 100755 src/PMG/Auth/OIDC.pm
>
> diff --git a/src/Makefile b/src/Makefile
> index 659a666..3cae7c7 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -169,6 +169,7 @@ LIBSOURCES = \
> PMG/Auth/Plugin.pm \
> PMG/Auth/PAM.pm \
> PMG/Auth/PMG.pm \
> + PMG/Auth/OIDC.pm \
>
> SOURCES = ${LIBSOURCES} ${CLI_BINARIES} ${TEMPLATES_FILES} ${CONF_MANS} ${CLI_MANS} ${SERVICE_MANS} ${SERVICE_UNITS} ${TIMER_UNITS} pmg-sources.list pmg-initramfs.conf
>
> diff --git a/src/PMG/AccessControl.pm b/src/PMG/AccessControl.pm
> index 78105c0..57d80f8 100644
> --- a/src/PMG/AccessControl.pm
> +++ b/src/PMG/AccessControl.pm
> @@ -15,9 +15,11 @@ use PMG::LDAPSet;
> use PMG::TFAConfig;
>
> use PMG::Auth::Plugin;
> +use PMG::Auth::OIDC;
> use PMG::Auth::PAM;
> use PMG::Auth::PMG;
>
> +PMG::Auth::OIDC->register();
> PMG::Auth::PAM->register();
> PMG::Auth::PMG->register();
> PMG::Auth::Plugin->init();
> diff --git a/src/PMG/Auth/OIDC.pm b/src/PMG/Auth/OIDC.pm
> new file mode 100755
> index 0000000..600e124
> --- /dev/null
> +++ b/src/PMG/Auth/OIDC.pm
> @@ -0,0 +1,101 @@
> +package PMG::Auth::OIDC;
> +
> +use strict;
> +use warnings;
> +
> +use PVE::Tools;
> +use PMG::Auth::Plugin;
> +
> +use base qw(PMG::Auth::Plugin);
> +
> +sub type {
> + return 'oidc';
> +}
> +
> +sub properties {
> + return {
> + 'issuer-url' => {
> + description => "OpenID Connect Issuer Url",
> + type => 'string',
> + maxLength => 256,
> + pattern => qr/^(https?):\/\/([a-zA-Z0-9.-]+)(:[0-9]{1,5})?(\/[^\s]*)?$/,
> + },
> + 'client-id' => {
> + description => "OpenID Connect Client ID",
> + type => 'string',
> + maxLength => 256,
> + pattern => qr/^[a-zA-Z0-9._:-]+$/,
> + },
> + 'client-key' => {
> + description => "OpenID Connect Client Key",
> + type => 'string',
> + optional => 1,
> + maxLength => 256,
> + pattern => qr/^[a-zA-Z0-9._:-]+$/,
> + },
> + autocreate => {
> + description => "Automatically create users if they do not exist.",
> + optional => 1,
> + type => 'boolean',
> + default => 0,
> + },
> + 'autocreate-role' => {
> + description => "Automatically create users with a specific role.",
> + type => 'string',
> + enum => ['admin', 'qmanager', 'audit', 'helpdesk'],
> + optional => 1,
> + },
In code (patch 7/12) we default to `audit`, maybe `default => 'audit'`
should be added here?
> + 'username-claim' => {
> + description => "OpenID Connect claim used to generate the unique username.",
> + type => 'string',
> + optional => 1,
> + pattern => qr/^[a-zA-Z0-9._:-]+$/,
> + },
same as above, maybe we should add `default => 'sub'` here. In the code
(patch 7/12) we default to `sub`, same as in PVE.
> + prompt => {
> + description => "Specifies whether the Authorization Server prompts the End-User for"
> + ." reauthentication and consent.",
> + type => 'string',
> + pattern => '(?:none|login|consent|select_account|\S+)', # \S+ is the extension variant
> + optional => 1,
> + },
> + scopes => {
> + description => "Specifies the scopes (user details) that should be authorized and"
> + ." returned, for example 'email' or 'profile'.",
> + type => 'string', # format => 'some-safe-id-list', # FIXME: TODO
> + default => "email profile",
> + pattern => qr/^[a-zA-Z0-9._:-]+$/,
> + optional => 1,
> + },
> + 'acr-values' => {
> + description => "Specifies the Authentication Context Class Reference values that the"
> + ."Authorization Server is being requested to use for the Auth Request.",
> + type => 'string', # format => 'some-safe-id-list', # FIXME: TODO
> + pattern => qr/^[a-zA-Z0-9._:-]+$/,
> + optional => 1,
> + },
> + };
> +}
> +
> +sub options {
> + return {
> + 'issuer-url' => {},
> + 'client-id' => {},
> + 'client-key' => { optional => 1 },
> + autocreate => { optional => 1 },
> + 'autocreate-role' => { optional => 1 },
> + 'username-claim' => { optional => 1, fixed => 1 },
> + prompt => { optional => 1 },
> + scopes => { optional => 1 },
> + 'acr-values' => { optional => 1 },
> + default => { optional => 1 },
> + comment => { optional => 1 },
> + };
> +}
> +
> +sub authenticate_user {
> + my ($class, $config, $realm, $username, $password) = @_;
> +
> + die "OpenID Connect realm does not allow password verification.\n";
> +}
> +
> +1;
More information about the pmg-devel
mailing list