From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 68C7A1FF0B6 for ; Thu, 12 Nov 2026 15:12:23 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CA9FC21688; Thu, 12 Nov 2026 15:12:18 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 03/26] oci: add `os` parameter to parse_and_extract_image Date: Thu, 12 Nov 2026 15:10:30 +0100 Message-ID: <20261112141109.137298-4-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112141109.137298-1-f.schauer@proxmox.com> References: <20261112141109.137298-1-f.schauer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794492735199 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.238 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: N7WYTGRCL6HZQQ7Z2VI3AA7UAIDYTF4L X-Message-ID-Hash: N7WYTGRCL6HZQQ7Z2VI3AA7UAIDYTF4L X-MailFrom: f.schauer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Manifest selection from a multi-platform image index only compared the architecture. Add an optional `os` argument to `parse_and_extract_image` and match it together with `arch`. Signed-off-by: Filip Schauer --- proxmox-oci/src/lib.rs | 10 +++++++--- proxmox-oci/src/oci_tar_image.rs | 9 ++++++--- proxmox-oci/tests/helper/mod.rs | 9 +++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/proxmox-oci/src/lib.rs b/proxmox-oci/src/lib.rs index 0e732324..f2664857 100644 --- a/proxmox-oci/src/lib.rs +++ b/proxmox-oci/src/lib.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use flate2::read::GzDecoder; use oci_spec::OciSpecError; -pub use oci_spec::image::{Arch, Config}; +pub use oci_spec::image::{Arch, Config, Os}; use oci_spec::image::{ImageConfiguration, ImageManifest, MediaType}; use sha2::digest::generic_array::GenericArray; use sha2::{Digest, Sha256}; @@ -109,6 +109,8 @@ pub enum ProxmoxOciError { /// /// * `oci_tar_path` - Path to the OCI image tar archive /// * `rootfs_path` - Destination path where the rootfs will be extracted to +/// * `os` - Optional operating system used to pick the first matching manifest from a multi-arch +/// image index. If `None`, the first manifest will be used. /// * `arch` - Optional CPU architecture used to pick the first matching manifest from a multi-arch /// image index. If `None`, the first manifest will be used. /// @@ -119,9 +121,10 @@ pub enum ProxmoxOciError { pub fn parse_and_extract_image>( oci_tar_path: P, rootfs_path: P, + os: Option<&Os>, arch: Option<&Arch>, ) -> Result, ProxmoxOciError> { - let (oci_tar_image, image_manifest, image_config) = parse_image(oci_tar_path, arch)?; + let (oci_tar_image, image_manifest, image_config) = parse_image(oci_tar_path, os, arch)?; extract_image_rootfs(oci_tar_image, &image_manifest, &image_config, rootfs_path)?; @@ -144,13 +147,14 @@ pub enum ParseError { fn parse_image>( oci_tar_path: P, + os: Option<&Os>, arch: Option<&Arch>, ) -> Result<(OciTarImage, ImageManifest, ImageConfiguration), ParseError> { let oci_tar_file = File::open(oci_tar_path)?; let mut oci_tar_image = OciTarImage::new(oci_tar_file)?; let image_manifest = oci_tar_image - .image_manifest(arch) + .image_manifest(os, arch) .ok_or(ParseError::NoMatchingManifest)??; let image_config_descriptor = image_manifest.config(); diff --git a/proxmox-oci/src/oci_tar_image.rs b/proxmox-oci/src/oci_tar_image.rs index ebe3edb4..f51556e9 100644 --- a/proxmox-oci/src/oci_tar_image.rs +++ b/proxmox-oci/src/oci_tar_image.rs @@ -4,7 +4,7 @@ use std::ops::Range; use std::path::{Path, PathBuf}; use oci_spec::OciSpecError; -use oci_spec::image::{Arch, Digest, ImageIndex, ImageManifest, MediaType}; +use oci_spec::image::{Arch, Digest, ImageIndex, ImageManifest, MediaType, Os}; use tar::Archive; use proxmox_io::RangeReader; @@ -73,12 +73,15 @@ impl OciTarImage { pub fn image_manifest( &mut self, + os: Option<&Os>, architecture: Option<&Arch>, ) -> Option> { let digest = match self.image_index.manifests().iter().find(|d| { d.media_type() == &MediaType::ImageManifest - && architecture - .is_none_or(|a| d.platform().as_ref().is_none_or(|p| p.architecture() == a)) + && d.platform().as_ref().is_none_or(|p| { + architecture.is_none_or(|a| p.architecture() == a) + && os.is_none_or(|os| p.os() == os) + }) }) { Some(descriptor) => descriptor.digest(), None => return None, diff --git a/proxmox-oci/tests/helper/mod.rs b/proxmox-oci/tests/helper/mod.rs index c07bbf9c..46491a89 100644 --- a/proxmox-oci/tests/helper/mod.rs +++ b/proxmox-oci/tests/helper/mod.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use anyhow::Result; -use proxmox_oci::{Arch, Config, ProxmoxOciError, parse_and_extract_image}; +use proxmox_oci::{Arch, Config, Os, ProxmoxOciError, parse_and_extract_image}; use proxmox_sys::fs::make_tmp_dir; mod oci_tar_image_builder; @@ -71,7 +71,12 @@ impl TestImage { } pub fn extract(&self) -> Result, ProxmoxOciError> { - parse_and_extract_image(&self.path, &self.extract_dir, Some(&Arch::Amd64)) + parse_and_extract_image( + &self.path, + &self.extract_dir, + Some(&Os::Linux), + Some(&Arch::Amd64), + ) } } -- 2.47.3