'normal' tags require 'VM.Config.Options' on '/vm/<vmid>', but not
allowed tags (either limited with 'user-tag-privileges' or 'admin-tags'
in the datacenter config) require 'Sys.Modify' on '/'

this patch implements the proper checks on adding/editing/deleting
these permissions

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 src/PVE/LXC.pm | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index fe63087..c31c95c 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1333,6 +1333,45 @@ sub check_ct_modify_config_perm {
        } elsif ($opt eq 'hookscript') {
            # For now this is restricted to root@pam
            raise_perm_exc("changing the hookscript is only allowed for 
root\@pam");
+       } elsif ($opt eq 'tags') {
+           my $user_tags;
+           my $admin_tags;
+
+           my $check_tag_perms = sub {
+               my ($tag) = @_;
+               if ($rpcenv->check($authuser, '/', ['Sys.Modify'], 1)) {
+                   return;
+               }
+
+               $rpcenv->check_vm_perm($authuser, $vmid, undef, 
['VM.Config.Options']);
+
+               if (!defined($user_tags) && !defined($admin_tags)) {
+                   ($user_tags, $admin_tags) = 
PVE::DataCenterConfig::get_user_admin_tags();
+               }
+
+               if ((defined($user_tags) && !$user_tags->{$tag}) ||
+                   (defined($admin_tags) && $admin_tags->{$tag})
+               ) {
+                   $rpcenv->check($authuser, '/', ['Sys.Modify']);
+               }
+           };
+
+           my $old_tags = {};
+           my $new_tags = {};
+
+           map { $old_tags->{$_} += 1 } 
PVE::Tools::split_list($oldconf->{$opt} // '');
+           map { $new_tags->{$_} += 1 } 
PVE::Tools::split_list($newconf->{$opt});
+
+           my $check_tags = sub {
+               my ($a, $b) = @_;
+               foreach my $tag (keys %$a) {
+                   next if ($b->{$tag} // 0) == ($a->{$tag} // 0);
+                   $check_tag_perms->($tag);
+               }
+           };
+
+           $check_tags->($old_tags, $new_tags);
+           $check_tags->($new_tags, $old_tags);
        } else {
            $rpcenv->check_vm_perm($authuser, $vmid, $pool, 
['VM.Config.Options']);
        }
-- 
2.30.2



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

Reply via email to