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 A6A8261189 for ; Tue, 8 Feb 2022 14:10:51 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 925A22EC76 for ; Tue, 8 Feb 2022 14:10:21 +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 C3BE62EC55 for ; Tue, 8 Feb 2022 14:10:19 +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 9C670461C5 for ; Tue, 8 Feb 2022 14:10:19 +0100 (CET) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Tue, 8 Feb 2022 14:10:09 +0100 Message-Id: <20220208131011.752134-4-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220208131011.752134-1-o.bektas@proxmox.com> References: <20220208131011.752134-1-o.bektas@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.657 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 T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [status.pm, lxc.pm] Subject: [pve-devel] [PATCH v1 container 3/5] fix #2582: api: add checks for 'SuperUser' privilege for root-only options 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: Tue, 08 Feb 2022 13:10:51 -0000 this way we can allow non-root users to act as a SU on specific root-only API paths by giving them the built-in SA role or a custom role with the SU privilege included. Signed-off-by: Oguz Bektas --- src/PVE/API2/LXC.pm | 13 ++++++------- src/PVE/API2/LXC/Status.pm | 8 ++++++-- src/PVE/LXC.pm | 9 ++++++--- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm index 7573814..b24e405 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_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/vms/$vmid", ['SuperUser'], 1); my $no_disk_param = {}; my $mp_param = {}; @@ -330,8 +330,8 @@ __PACKAGE__->register_method({ my $mp = $mountpoint->{mp}; if ($mountpoint->{type} ne 'volume') { # bind or device - die "Only root can pass arbitrary filesystem paths.\n" - if !$is_root; + die "Only superusers can pass arbitrary filesystem paths.\n" + if !$is_superuser; } else { my ($sid, $volname) = PVE::Storage::parse_volume_id($volid); &$check_and_activate_storage($sid); @@ -371,7 +371,7 @@ __PACKAGE__->register_method({ # causing it to restore the raw lxc entries, among which there may be # 'lxc.idmap' entries. We need to make sure that the extracted contents # of the container match up with the restored configuration afterwards: - $conf->{lxc} = $orig_conf->{lxc} if $is_root; + $conf->{lxc} = $orig_conf->{lxc} if $is_superuser; $conf->{unprivileged} = $orig_conf->{unprivileged} if !defined($unprivileged) && defined($orig_conf->{unprivileged}); @@ -405,8 +405,7 @@ __PACKAGE__->register_method({ my $type = $mountpoint->{type}; die "restoring rootfs to $type mount is only possible by specifying -rootfs manually!\n" if ($ms eq 'rootfs'); - die "restoring '$ms' to $type mount is only possible for root\n" - if !$is_root; + die "restoring '$ms' to $type mount is only possible for root\n" if !$is_superuser; if ($mountpoint->{backup}) { warn "WARNING - unsupported configuration!\n"; @@ -447,7 +446,7 @@ __PACKAGE__->register_method({ if ($restore) { print "merging backed-up and given configuration..\n"; - PVE::LXC::Create::restore_configuration($vmid, $storage_cfg, $archive, $rootdir, $conf, !$is_root, $unique, $skip_fw_config_restore); + PVE::LXC::Create::restore_configuration($vmid, $storage_cfg, $archive, $rootdir, $conf, !$is_superuser, $unique, $skip_fw_config_restore); my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); $lxc_setup->template_fixup($conf); } else { diff --git a/src/PVE/API2/LXC/Status.pm b/src/PVE/API2/LXC/Status.pm index f7e3128..791cdc6 100644 --- a/src/PVE/API2/LXC/Status.pm +++ b/src/PVE/API2/LXC/Status.pm @@ -150,9 +150,11 @@ __PACKAGE__->register_method({ my $node = extract_param($param, 'node'); my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/vms/$vmid", ['SuperUser'], 1); + my $skiplock = extract_param($param, 'skiplock'); raise_param_exc({ skiplock => "Only root may use this option." }) - if $skiplock && $authuser ne 'root@pam'; + if $skiplock && !$is_superuser; die "CT $vmid already running\n" if PVE::LXC::check_running($vmid); @@ -234,9 +236,11 @@ __PACKAGE__->register_method({ my $node = extract_param($param, 'node'); my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/vms/$vmid", ['SuperUser'], 1); + my $skiplock = extract_param($param, 'skiplock'); raise_param_exc({ skiplock => "Only root may use this option." }) - if $skiplock && $authuser ne 'root@pam'; + if $skiplock && !$is_superuser; die "CT $vmid not running\n" if !PVE::LXC::check_running($vmid); diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index b07d986..6b5125c 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_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/vms/$vmid", ['SuperUser']); + return 1 if $is_superuser; + 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_superuser; $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_superuser; } else { $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Options']); } -- 2.30.2