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 8674669100 for ; Fri, 11 Mar 2022 12:25:52 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1227D2367C for ; Fri, 11 Mar 2022 12:25:25 +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 5F3132354F for ; Fri, 11 Mar 2022 12:25:18 +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 1F8A4463BD for ; Fri, 11 Mar 2022 12:25:18 +0100 (CET) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Fri, 11 Mar 2022 12:24:55 +0100 Message-Id: <20220311112504.595964-4-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220311112504.595964-1-o.bektas@proxmox.com> References: <20220311112504.595964-1-o.bektas@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.584 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 - Subject: [pve-devel] [PATCH v2 qemu-server 03/12] api: allow 'skiplock' option to be used by SU privileged users 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: Fri, 11 Mar 2022 11:25:52 -0000 Signed-off-by: Oguz Bektas --- PVE/API2/Qemu.pm | 59 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 21fc82b..95cc46d 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1126,8 +1126,8 @@ my $update_vm_api = sub { 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $delete_str = extract_param($param, 'delete'); @@ -1645,9 +1645,11 @@ __PACKAGE__->register_method({ my $authuser = $rpcenv->get_user(); my $vmid = $param->{vmid}; + my $is_superuser = $authuser eq 'root@pam' || $rpcenv->check($authuser, "/vms/$vmid", ['SuperUser'], 1); + my $skiplock = $param->{skiplock}; - raise_param_exc({ skiplock => "Only root may use this option." }) - if $skiplock && $authuser ne 'root@pam'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $early_checks = sub { # test if VM exists @@ -2290,6 +2292,12 @@ __PACKAGE__->register_method({ my $timeout = extract_param($param, 'timeout'); my $machine = extract_param($param, 'machine'); + 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 superusers may use this option." }) + if $skiplock && !$is_superuser; + my $get_root_param = sub { my $value = extract_param($param, $_[0]); raise_param_exc({ "$_[0]" => "Only root may use this option." }) @@ -2298,7 +2306,6 @@ __PACKAGE__->register_method({ }; my $stateuri = $get_root_param->('stateuri'); - my $skiplock = $get_root_param->('skiplock'); my $migratedfrom = $get_root_param->('migratedfrom'); my $migration_type = $get_root_param->('migration_type'); my $migration_network = $get_root_param->('migration_network'); @@ -2436,9 +2443,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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $keepActive = extract_param($param, 'keepActive'); raise_param_exc({ keepActive => "Only root may use this option." }) @@ -2513,9 +2522,11 @@ __PACKAGE__->register_method({ 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid); @@ -2580,9 +2591,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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $keepActive = extract_param($param, 'keepActive'); raise_param_exc({ keepActive => "Only root may use this option." }) @@ -2739,9 +2752,11 @@ __PACKAGE__->register_method({ my $statestorage = extract_param($param, 'statestorage'); + 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid); @@ -2811,9 +2826,11 @@ __PACKAGE__->register_method({ 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $nocheck = extract_param($param, 'nocheck'); raise_param_exc({ nocheck => "Only root may use this option." }) @@ -2883,9 +2900,11 @@ __PACKAGE__->register_method({ 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; PVE::QemuServer::vm_sendkey($vmid, $skiplock, $param->{key}); @@ -4114,9 +4133,11 @@ __PACKAGE__->register_method({ my $sizestr = extract_param($param, 'size'); + 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'; + raise_param_exc({ skiplock => "Only superusers may use this option." }) + if $skiplock && !$is_superuser; my $storecfg = PVE::Storage::config(); -- 2.30.2