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 F31C388310 for ; Wed, 5 Jan 2022 16:22:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8CBE5A995 for ; Wed, 5 Jan 2022 16:22:26 +0100 (CET) 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 id B671BA914 for ; Wed, 5 Jan 2022 16:22:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9090846B73 for ; Wed, 5 Jan 2022 16:22:24 +0100 (CET) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Wed, 5 Jan 2022 16:22:14 +0100 Message-Id: <20220105152215.1307583-4-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220105152215.1307583-1-o.bektas@proxmox.com> References: <20220105152215.1307583-1-o.bektas@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.689 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lxc.pm] Subject: [pve-devel] [PATCH container 3/4] fix #2582: api: use common helper for checking root privileges 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: Wed, 05 Jan 2022 15:22:57 -0000 we just check if the authenticated user has the 'Sys.Root' privilege on a given path and set the $is_root variable accordingly if so. tagged as fix for #2582 since with this series the usecase on the bugreport should be fulfilled. Signed-off-by: Oguz Bektas --- src/PVE/API2/LXC.pm | 2 +- src/PVE/LXC.pm | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 7573814..64ecc5f 100644 --- a/src/PVE/API2/LXC.pm +++ b/src/PVE/API2/LXC.pm @@ -295,7 +295,7 @@ __PACKAGE__->register_method({ my $conf = {}; - my $is_root = $authuser eq 'root@pam'; + my $is_root = PVE::Tools::check_for_root("/vms"); my $no_disk_param = {}; my $mp_param = {}; diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index b07d986..1844b04 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1254,7 +1254,9 @@ sub template_create { sub check_ct_modify_config_perm { my ($rpcenv, $authuser, $vmid, $pool, $oldconf, $newconf, $delete, $unprivileged) = @_; - return 1 if $authuser eq 'root@pam'; + my $is_root = PVE::Tools::check_for_root("/vms/$vmid"); + return 1 if $is_root; + my $storage_cfg = PVE::Storage::config(); my $check = sub { @@ -1320,12 +1322,13 @@ sub check_ct_modify_config_perm { } } raise_perm_exc("changing feature flags (except nesting) is only allowed for root\@pam") - if $other_changed; + if $other_changed && !$is_root; $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Allocate']) if $nesting_changed; } elsif ($opt eq 'hookscript') { # For now this is restricted to root@pam - raise_perm_exc("changing the hookscript is only allowed for root\@pam"); + raise_perm_exc("changing the hookscript is only allowed for root\@pam") + if !$is_root; } else { $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Options']); } -- 2.30.2