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 6D93C9D955 for ; Mon, 5 Jun 2023 16:21:49 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4EC5128A25 for ; Mon, 5 Jun 2023 16:21:49 +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 ; Mon, 5 Jun 2023 16:21:48 +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 1F078489DE for ; Mon, 5 Jun 2023 16:21:48 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Mon, 5 Jun 2023 16:21:37 +0200 Message-Id: <20230605142137.854891-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230605142137.854891-1-f.gruenbichler@proxmox.com> References: <20230605142137.854891-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.073 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 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 2/2] acls: restrict less-privileged ACL modifications 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: Mon, 05 Jun 2023 14:21:49 -0000 there are currently three possibilities to modify ACLs without the 'Permissions.Modify' privilege in PVE::RPCEnvironment::check_perm_modify: if ($path =~ m|^/storage/.+$|) { push @$testperms, 'Datastore.Allocate'; } elsif ($path =~ m|^/vms/.+$|) { push @$testperms, 'VM.Allocate'; } elsif ($path =~ m|^/pool/.+$|) { push @$testperms, 'Pool.Allocate'; } lock those down by only allowing the currently authenticated user to hand out a subset of their own privileges, never more. for example, this still allows a PVEVMAdmin to create ACLs for other users/tokens with PVEVMUser (on '/vm/XXX'), but not with Administrator or PVEPermAdmin. Signed-off-by: Fabian Grünbichler --- Notes: this one is also a breaking change, but a bit more niche -> IMHO a callout in the release notes is sufficient. src/PVE/API2/ACL.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/PVE/API2/ACL.pm b/src/PVE/API2/ACL.pm index f0c9efb..93adb78 100644 --- a/src/PVE/API2/ACL.pm +++ b/src/PVE/API2/ACL.pm @@ -148,9 +148,12 @@ __PACKAGE__->register_method ({ PVE::AccessControl::lock_user_config( sub { - my $cfg = cfs_read_file("user.cfg"); + my $rpcenv = PVE::RPCEnvironment::get(); + my $authuser = $rpcenv->get_user(); + my $auth_user_privs = $rpcenv->permissions($authuser, $path); + my $propagate = 1; if (defined($param->{propagate})) { @@ -163,6 +166,25 @@ __PACKAGE__->register_method ({ die "role '$role' does not exist\n" if !$cfg->{roles}->{$role}; + if (!$auth_user_privs->{'Permissions.Modify'}) { + # 'perm-modify' allows /vms/* with VM.Allocate and similar restricted use cases + # filter those to only allow handing out a subset of currently active privs + my $role_privs = $cfg->{roles}->{$role}; + my $verb = $param->{delete} ? 'remove' : 'add'; + foreach my $priv (keys $role_privs->%*) { + raise_param_exc({ role => "Cannot $verb role '$role' - requires 'Permissions.Modify' or superset of privileges." }) + if !defined($auth_user_privs->{$priv}); + + # propagation is only potentially problematic for adding ACLs, not removing.. + raise_param_exc({ role => "Cannot $verb role '$role' with propagation - requires 'Permissions.Modify' or propagated superset of privileges." }) + if $propagate && $auth_user_privs->{$priv} != $propagate && !$param->{delete}; + } + + # NoAccess has no privs, needs an explicit check + raise_param_exc({ role => "Cannot $verb role '$role' - requires 'Permissions.Modify'"}) + if $role eq 'NoAccess'; + } + foreach my $group (split_list($param->{groups})) { die "group '$group' does not exist\n" -- 2.39.2