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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht
2024-11-18 20:50:24 +01:00
parent b9f9ffcc57
commit 811aa863cb

View File

@ -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) {