all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH access-control 2/2] acls: restrict less-privileged ACL modifications
Date: Mon,  5 Jun 2023 16:21:37 +0200	[thread overview]
Message-ID: <20230605142137.854891-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20230605142137.854891-1-f.gruenbichler@proxmox.com>

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 <f.gruenbichler@proxmox.com>
---

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





  reply	other threads:[~2023-06-05 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 14:21 [pve-devel] [PATCH access-control 1/2] roles: restrict Permissions.Modify to Administrator Fabian Grünbichler
2023-06-05 14:21 ` Fabian Grünbichler [this message]
2023-06-07  9:18 ` [pve-devel] applied-series: " 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=20230605142137.854891-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@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 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