From 811aa863cb66c1f49e6e4bd725c94626ed5082b5 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 18 Nov 2024 20:50:24 +0100 Subject: [PATCH] guest import: extract staging copy with same owner than running process Some OVAs have a UID/GID set for their inner file, for example the one from GNS3: > tar tvf 'GNS3 VM.ova' --numeric-owner > -rw-r----- 6/1 9047 2024-11-07 10:22 GNS3 VM.ovf > -rw-rw---- 6/1 904088064 2024-11-07 10:22 GNS3 VM-disk001.vmdk > -rw-rw---- 6/1 2879488 2024-11-07 10:22 GNS3 VM-disk002.vmdk As we run as root, tar is defaulting to the `--same-owner` option, where it tries extracting files with the same ownership as exists in the archive. This might not be ideal and results in an error for GNS3: > tar: GNS3 VM-disk001.vmdk: Cannot change ownership to uid 6, gid 1: Operation not permitted So, explicitly set the `--no-same-owner` option to make tar always use the UID/GID of the running process, which is what we want here. Signed-off-by: Thomas Lamprecht --- src/PVE/GuestImport.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/PVE/GuestImport.pm b/src/PVE/GuestImport.pm index c473d88..57e0d3f 100644 --- a/src/PVE/GuestImport.pm +++ b/src/PVE/GuestImport.pm @@ -47,7 +47,15 @@ sub extract_disk_from_import_file { my $target_path; my $target_volid; eval { - run_command(['tar', '-x', '--force-local', '-C', $tmpdir, '-f', $ova_path, $inner_file]); + run_command([ + 'tar', + '-x', + '--force-local', + '--no-same-owner', + '-C', $tmpdir, + '-f', $ova_path, + $inner_file, + ]); # check for symlinks and other non regular files if (-l $source_path || ! -f $source_path) {