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 41CE98C925 for ; Thu, 3 Nov 2022 14:05:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 245EE3081A for ; Thu, 3 Nov 2022 14:05:53 +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 for ; Thu, 3 Nov 2022 14:05:52 +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 4C14E44D0D for ; Thu, 3 Nov 2022 14:05:52 +0100 (CET) From: Leo Nunner To: pve-devel@lists.proxmox.com Date: Thu, 3 Nov 2022 14:04:22 +0100 Message-Id: <20221103130423.52460-2-l.nunner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221103130423.52460-1-l.nunner@proxmox.com> References: <20221103130423.52460-1-l.nunner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.145 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 Subject: [pve-devel] [PATCH qemu-server 1/1] fix #4321: properly check cloud-init drive permissions 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, 03 Nov 2022 13:05:53 -0000 The process for editing cloud-init drives checked for inconsistent permissions: for adding, the VM.Config.Disk permission was needed, while the VM.Config.CDROM permission was needed to remove a drive. The regex in drive_is_cloudinit needed to be adapted since the drive names have different formats before/after they are actually generated. Furthermore, the VM.Config.Cloudinit permission should be required to edit cloud-init drives. Signed-off-by: Leo Nunner --- PVE/API2/Qemu.pm | 6 ++++-- PVE/QemuServer/Drive.pm | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 3ec31c2..cacd233 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1512,11 +1512,13 @@ my $update_vm_api = sub { my $check_drive_perms = sub { my ($opt, $val) = @_; my $drive = PVE::QemuServer::parse_drive($opt, $val, 1); - # FIXME: cloudinit: CDROM or Disk? - if (PVE::QemuServer::drive_is_cdrom($drive)) { # CDROM + if(PVE::QemuServer::drive_is_cloudinit($drive)) { + $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Cloudinit', 'VM.Config.Disk']); + } elsif (PVE::QemuServer::drive_is_cdrom($drive, 1)) { # CDROM $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.CDROM']); } else { $rpcenv->check_vm_perm($authuser, $vmid, undef, ['VM.Config.Disk']); + } }; diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm index 1dc6171..12a1fbe 100644 --- a/PVE/QemuServer/Drive.pm +++ b/PVE/QemuServer/Drive.pm @@ -540,7 +540,7 @@ sub verify_bootdisk { sub drive_is_cloudinit { my ($drive) = @_; - return $drive->{file} =~ m@[:/]vm-\d+-cloudinit(?:\.$QEMU_FORMAT_RE)?$@; + return $drive->{file} =~ m@[:/](?:vm-\d+-)?cloudinit(?:\.$QEMU_FORMAT_RE)?$@; } sub drive_is_cdrom { -- 2.30.2