From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 72F949B801 for ; Thu, 25 May 2023 12:18:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1996F295A9 for ; Thu, 25 May 2023 12:18:00 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 25 May 2023 12:17:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 53CE4470D0 for ; Thu, 25 May 2023 12:17:57 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Thu, 25 May 2023 12:17:44 +0200 Message-Id: <20230525101753.2078811-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230525101753.2078811-1-d.csapak@proxmox.com> References: <20230525101753.2078811-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.135 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH access-control v4 1/1] add privileges and paths for cluster resource mapping X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 May 2023 10:18:00 -0000 uses the privileges: Resource.Use Resource.Modify on /resource/{TYPE}/{id} so that we can assign privileges on resource level this will generate new roles (PVEResourceUser, PVEResourceAdmin) note that every user with Permissions.Modify on '/' and propagate can add these new roles to themselves (Administrator and PVEAdmin roles currently have this privilege) Signed-off-by: Dominik Csapak --- src/PVE/AccessControl.pm | 20 +++++++++++++++++++- src/PVE/RPCEnvironment.pm | 7 +++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/PVE/AccessControl.pm b/src/PVE/AccessControl.pm index 89b7d90..d093970 100644 --- a/src/PVE/AccessControl.pm +++ b/src/PVE/AccessControl.pm @@ -1159,13 +1159,22 @@ my $privgroups = { 'Pool.Audit', ], }, + Resource => { + root => [], + admin => [ + 'Resource.Modify', + ], + user => [ + 'Resource.Use', + ], + }, }; my $valid_privs = {}; my $special_roles = { 'NoAccess' => {}, # no privileges - 'Administrator' => $valid_privs, # all privileges + 'Administrator' => {}, # all privileges }; sub create_roles { @@ -1175,6 +1184,7 @@ sub create_roles { foreach my $p (@{$cd->{root}}, @{$cd->{admin}}, @{$cd->{user}}, @{$cd->{audit}}) { $valid_privs->{$p} = 1; + $special_roles->{"Administrator"}->{$p} = 1; } foreach my $p (@{$cd->{admin}}, @{$cd->{user}}, @{$cd->{audit}}) { @@ -1191,6 +1201,11 @@ sub create_roles { } } + # remove Resource.Modify from Administrator and PVEAdmin, only + # root@pam and PVEResourceAdmin should be able to use that for now + delete $special_roles->{"Administrator"}->{"Resource.Modify"}; + delete $special_roles->{"PVEAdmin"}->{"Resource.Modify"}; + $special_roles->{"PVETemplateUser"} = { 'VM.Clone' => 1, 'VM.Audit' => 1 }; }; @@ -1288,6 +1303,9 @@ sub check_path { |/storage/[[:alnum:]\.\-\_]+ |/vms |/vms/[1-9][0-9]{2,} + |/resource + |/resource/[[:alnum:]\.\-\_]+/ + |/resource/[[:alnum:]\.\-\_]+/[[:alnum:]\.\-\_]+ )$!xs; } diff --git a/src/PVE/RPCEnvironment.pm b/src/PVE/RPCEnvironment.pm index 8586938..8454939 100644 --- a/src/PVE/RPCEnvironment.pm +++ b/src/PVE/RPCEnvironment.pm @@ -137,7 +137,9 @@ sub permissions { if ($user eq 'root@pam') { # root can do anything my $cfg = $self->{user_cfg}; - return { map { $_ => 1 } keys %{$cfg->{roles}->{'Administrator'}} }; + my $permissions = { map { $_ => 1 } keys %{$cfg->{roles}->{'Administrator'}} }; + $permissions->{"Resource.Modify"} = 1; + return $permissions; } if (!defined($path)) { @@ -187,10 +189,11 @@ sub compute_api_permission { nodes => qr/Sys\.|Permissions\.Modify/, sdn => qr/SDN\.|Permissions\.Modify/, dc => qr/Sys\.Audit|SDN\./, + resource => qr/Resource\./, }; map { $res->{$_} = {} } keys %$priv_re_map; - my $required_paths = ['/', '/nodes', '/access/groups', '/vms', '/storage', '/sdn']; + my $required_paths = ['/', '/nodes', '/access/groups', '/vms', '/storage', '/sdn', '/resource']; my $defined_paths = []; PVE::AccessControl::iterate_acl_tree("/", $usercfg->{acl_root}, sub { my ($path, $node) = @_; -- 2.30.2