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 D9CB874C4C for ; Thu, 2 Jun 2022 09:25:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 88F5F27800 for ; Thu, 2 Jun 2022 09:25:18 +0200 (CEST) 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 B850B27488 for ; Thu, 2 Jun 2022 09:25:06 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9090142A48 for ; Thu, 2 Jun 2022 09:25:06 +0200 (CEST) From: Oguz Bektas To: pve-devel@lists.proxmox.com Date: Thu, 2 Jun 2022 09:24:40 +0200 Message-Id: <20220602072450.55209-9-o.bektas@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220602072450.55209-1-o.bektas@proxmox.com> References: <20220602072450.55209-1-o.bektas@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.462 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. [qemu.pm] Subject: [pve-devel] [PATCH v4 qemu-server 08/18] api: allow superusers to use 'skiplock' option 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: Thu, 02 Jun 2022 07:25:18 -0000 also mark the intentionally root-only migration related options in param descriptions and leave a reminder comment. Suggested-by: Fabian Grünbichler Signed-off-by: Oguz Bektas --- PVE/API2/Qemu.pm | 71 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 2e75ab6..198e736 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1337,8 +1337,8 @@ my $update_vm_api = sub { my $is_superuser = $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'); @@ -1864,9 +1864,11 @@ __PACKAGE__->register_method({ my $authuser = $rpcenv->get_user(); my $vmid = $param->{vmid}; + my $is_superuser = $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 @@ -2474,25 +2476,27 @@ __PACKAGE__->register_method({ migration_type => { type => 'string', enum => ['secure', 'insecure'], - description => "Migration traffic is encrypted using an SSH " . + description => "Migration-internal parameter. Migration traffic is encrypted using an SSH " . "tunnel by default. On secure, completely private networks " . "this can be disabled to increase performance.", optional => 1, }, migration_network => { type => 'string', format => 'CIDR', - description => "CIDR of the (sub) network that is used for migration.", + description => "Migration-internal parameter. CIDR of the (sub)network " . + "that is used for migration.", optional => 1, }, machine => get_standard_option('pve-qemu-machine'), 'force-cpu' => { - description => "Override QEMU's -cpu argument with the given string.", + description => "Migration-internal parameter. Override QEMU's" . + "-cpu argument with the given string.", type => 'string', optional => 1, }, targetstorage => get_standard_option('pve-targetstorage'), timeout => { - description => "Wait maximal timeout seconds.", + description => "Migration-internal parameter. Wait maximal timeout seconds.", type => 'integer', minimum => 0, default => 'max(30, vm memory in GiB)', @@ -2514,6 +2518,14 @@ __PACKAGE__->register_method({ my $timeout = extract_param($param, 'timeout'); my $machine = extract_param($param, 'machine'); + my $is_superuser = $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; + + # since they are only used for migration-internal flows, + # these parameters are still intentionally limited to root@pam my $get_root_param = sub { my $value = extract_param($param, $_[0]); raise_param_exc({ "$_[0]" => "Only root may use this option." }) @@ -2522,7 +2534,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'); @@ -2662,9 +2673,11 @@ __PACKAGE__->register_method({ my $node = extract_param($param, 'node'); my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $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 $vmid = extract_param($param, 'vmid'); + my $is_superuser = $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); @@ -2806,9 +2821,11 @@ __PACKAGE__->register_method({ my $node = extract_param($param, 'node'); my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $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." }) @@ -2965,9 +2982,11 @@ __PACKAGE__->register_method({ my $statestorage = extract_param($param, 'statestorage'); + my $is_superuser = $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); @@ -3037,9 +3056,11 @@ __PACKAGE__->register_method({ my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $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." }) @@ -3109,9 +3130,11 @@ __PACKAGE__->register_method({ my $vmid = extract_param($param, 'vmid'); + my $is_superuser = $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}); @@ -4372,9 +4395,11 @@ __PACKAGE__->register_method({ my $sizestr = extract_param($param, 'size'); + my $is_superuser = $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