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 895C6A2A06 for ; Tue, 20 Jun 2023 09:42:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3F7BA31217 for ; Tue, 20 Jun 2023 09:41:57 +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 for ; Tue, 20 Jun 2023 09:41:56 +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 6A2194050E for ; Tue, 20 Jun 2023 09:41:56 +0200 (CEST) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pve-devel@lists.proxmox.com Date: Tue, 20 Jun 2023 09:41:49 +0200 Message-Id: <20230620074149.2922098-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620074149.2922098-1-f.gruenbichler@proxmox.com> References: <20230620074149.2922098-1-f.gruenbichler@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.071 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 qemu-server 2/2] restore: extend permissions checks 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, 20 Jun 2023 07:42:27 -0000 to allow early checking of the merged config, if the backup archive passed in is a proper volume where extraction is possible. Signed-off-by: Fabian Grünbichler --- Notes: this check needs to be inside the worker since we don't know how long extracting the config takes.. for pipe (doesn't allow early extraction at all) or absolute path (not supported by the extraction helper) we don't need to check, since those are limited to root anyhow. PVE/API2/Qemu.pm | 13 +++++++++++++ PVE/QemuServer.pm | 11 +++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index b7832d88..59307133 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -958,6 +958,19 @@ __PACKAGE__->register_method({ live => $live_restore, override_conf => $param, }; + if (my $volid = $archive->{volid}) { + # best effort, real check is after restoring! + my $merged = eval { + my $old_conf = PVE::Storage::extract_vzdump_config($storecfg, $volid); + PVE::QemuServer::restore_merge_config("backup/qemu-server/$vmid.conf", $old_conf, $param); + }; + if ($@) { + warn "Could not extract backed up config: $@\n"; + warn "Skipping early checks!\n"; + } else { + PVE::QemuServer::check_restore_permissions($rpcenv, $authuser, $merged); + } + } if ($archive->{type} eq 'file' || $archive->{type} eq 'pipe') { die "live-restore is only compatible with backup images from a Proxmox Backup Server\n" if $live_restore; diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 940cdacd..0fa43a74 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -6542,10 +6542,9 @@ sub check_mapping_access { } }; -# FIXME: improve checks on restore by checking before actually extracing and -# merging the new config sub check_restore_permissions { my ($rpcenv, $user, $conf) = @_; + check_bridge_access($rpcenv, $user, $conf); check_mapping_access($rpcenv, $user, $conf); } @@ -6865,7 +6864,7 @@ my $restore_destroy_volumes = sub { } }; -my $restore_merge_config = sub { +sub restore_merge_config { my ($filename, $backup_conf_raw, $override_conf) = @_; my $backup_conf = parse_vm_config($filename, $backup_conf_raw); @@ -6874,7 +6873,7 @@ my $restore_merge_config = sub { } return $backup_conf; -}; +} sub scan_volids { my ($cfg, $vmid) = @_; @@ -7192,7 +7191,7 @@ sub restore_proxmox_backup_archive { $new_conf_raw .= "\nlock: create"; } - my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $options->{override_conf}); + my $new_conf = restore_merge_config($conffile, $new_conf_raw, $options->{override_conf}); check_restore_permissions($rpcenv, $user, $new_conf); PVE::QemuConfig->write_config($vmid, $new_conf); @@ -7506,7 +7505,7 @@ sub restore_vma_archive { die $err; } - my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $opts->{override_conf}); + my $new_conf = restore_merge_config($conffile, $new_conf_raw, $opts->{override_conf}); check_restore_permissions($rpcenv, $user, $new_conf); PVE::QemuConfig->write_config($vmid, $new_conf); -- 2.39.2