From fe3b2915f2ac5a5b1e4842c67dd2056c7b8f6327 Mon Sep 17 00:00:00 2001 From: Filip Schauer Date: Mon, 17 Nov 2025 18:13:14 +0100 Subject: [PATCH] api: oci image pull: pull OCI image to temporary file Pull the OCI image to a temporary file first. Once it has finished, rename it, which is an atomic operation. This prevents accidental usage of an incomplete OCI image file for container creation. Signed-off-by: Filip Schauer Link: https://lore.proxmox.com/20251117171528.262443-2-f.schauer@proxmox.com Signed-off-by: Thomas Lamprecht --- src/PVE/API2/Storage/Status.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PVE/API2/Storage/Status.pm b/src/PVE/API2/Storage/Status.pm index 5abf53b..96832b9 100644 --- a/src/PVE/API2/Storage/Status.pm +++ b/src/PVE/API2/Storage/Status.pm @@ -959,14 +959,26 @@ __PACKAGE__->register_method({ die "storage '$storage' is not configured for content-type 'vztmpl'\n" if !$scfg->{content}->{vztmpl}; - my $filename = PVE::Storage::normalize_content_filename($reference); + my $filename = PVE::Storage::normalize_content_filename($reference) . ".tar"; + my $tmp_filename = "$filename.tmp.$$"; my $path = PVE::Storage::get_vztmpl_dir($cfg, $storage); PVE::Storage::activate_storage($cfg, $storage); + local $SIG{INT} = sub { + unlink "$path/$tmp_filename" + or warn "could not cleanup temporary file: $!" + if -e "$path/$tmp_filename"; + die "got interrupted by signal\n"; + }; + my $worker = sub { PVE::Tools::run_command( - ["skopeo", "copy", "docker://$reference", "oci-archive:$path/$filename.tar"], + [ + "skopeo", "copy", "docker://$reference", "oci-archive:$path/$tmp_filename", + ], ); + rename("$path/$tmp_filename", "$path/$filename") + or die "unable to rename temporary file: $!\n"; }; my $worker_id = PVE::Tools::encode_text($filename); # must not pass : or the like as w-ID