From 166da833b47ab39e3605673812c75bca19360a83 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Sat, 14 Nov 2026 00:31:14 +0000 Subject: [PATCH 1/3] test: reject unbound and stale provider snapshots Signed-off-by: James Sturtevant --- cli/tests/artifact.rs | 53 ++++++++++++++++ providers/tests/test_snapshot_oci.py | 95 ++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) diff --git a/cli/tests/artifact.rs b/cli/tests/artifact.rs index a678153..4127a78 100644 --- a/cli/tests/artifact.rs +++ b/cli/tests/artifact.rs @@ -235,6 +235,59 @@ fn indexed_snapshots_select_the_exact_compatible_variant_without_copying() { } } +#[test] +fn selected_snapshot_requires_all_cold_asset_digests_to_match() { + for (field, missing) in [ + ("rootfs", false), + ("program", false), + ("kernel", false), + ("rootfs", true), + ("program", true), + ("kernel", true), + ("all", true), + ] { + let (root, mut manifest) = artifact(); + let kernel = digest("kernel", b"test kernel"); + std::fs::write(root.path().join("kernel"), b"test kernel").unwrap(); + manifest.kernel = Some(kernel.clone()); + let mut selected = variant(&root, &host()); + for (asset, sha256) in [ + ("rootfs", &manifest.rootfs.sha256), + ("program", &manifest.program.sha256), + ("kernel", &kernel.sha256), + ] { + selected.annotations.insert( + format!("dev.lampyr.provider.{asset}.sha256"), + sha256.clone(), + ); + } + save_index(&root, &mut manifest, vec![selected.clone()]); + let matched = + Artifact::load_for_host_with_registry(root.path(), "test", &host(), None).unwrap(); + assert!(matched.snapshot.is_some()); + if missing { + for asset in ["rootfs", "program", "kernel"] { + if field == "all" || field == asset { + selected + .annotations + .remove(&format!("dev.lampyr.provider.{asset}.sha256")); + } + } + } else { + selected.annotations.insert( + format!("dev.lampyr.provider.{field}.sha256"), + "0".repeat(64), + ); + } + save_index(&root, &mut manifest, vec![selected]); + let result = Artifact::load_for_host_with_registry(root.path(), "test", &host(), None); + assert!( + result.is_err(), + "selected snapshot with invalid {field} binding (missing: {missing}) was accepted" + ); + } +} + #[test] fn incompatible_or_unknown_hosts_cold_boot_without_loading_any_snapshot() { let (root, mut manifest) = artifact(); diff --git a/providers/tests/test_snapshot_oci.py b/providers/tests/test_snapshot_oci.py index 3084c55..5aaad61 100644 --- a/providers/tests/test_snapshot_oci.py +++ b/providers/tests/test_snapshot_oci.py @@ -97,6 +97,101 @@ def provider_source(self, root, name, prepared): def assemble(self, variants=None): return oci.assemble(self.intel, [self.intel, self.amd, self.arm] if variants is None else variants, self.output) + def record_snapshot_inputs(self, directory): + manifest = oci.read_json(directory / "manifest.json") + index_path = directory / manifest["snapshotIndex"]["path"] + index = oci.read_json(index_path) + for item in index["manifests"]: + for field in ("rootfs", "program", "kernel"): + item["annotations"][f"dev.lampyr.provider.{field}.sha256"] = manifest[field]["sha256"] + index_path.write_bytes(oci.json_bytes(index)) + manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) + (directory / "manifest.json").write_text(json.dumps(manifest)) + + def test_layout_and_platform_packaging_reject_stale_snapshot_inputs(self): + for field in ("rootfs", "program", "kernel"): + with self.subTest(field=field): + root = self.root / f"stale-{field}" + directory = root / "providers/test/build/rootfs" + directory.parent.mkdir(parents=True) + shutil.copytree(self.intel, directory) + self.record_snapshot_inputs(directory) + manifest = oci.read_json(directory / "manifest.json") + path = directory / manifest[field]["path"] + path.write_bytes(b"changed cold asset") + manifest[field] = package.file_digest(path) + (directory / "manifest.json").write_text(json.dumps(manifest)) + for name, check in ( + ("layout", lambda: oci.layout_files(directory)), + ("platform package", lambda: platform_package["provider_files"](root, "test")), + ): + with self.subTest(check=name): + with self.assertRaisesRegex(ValueError, "snapshot.*(digest|asset|input)"): + check() + + def test_assembly_rejects_snapshot_captured_from_different_same_platform_assets(self): + for field in ("rootfs", "kernel"): + with self.subTest(field=field): + candidate = self.root / f"different-{field}" + shutil.copytree(self.intel, candidate) + manifest = oci.read_json(candidate / "manifest.json") + path = candidate / manifest[field]["path"] + path.write_bytes(b"different capture input") + manifest[field] = package.file_digest(path) + (candidate / "manifest.json").write_text(json.dumps(manifest)) + self.record_snapshot_inputs(candidate) + with self.assertRaisesRegex(ValueError, "snapshot.*(digest|asset|input)"): + oci.assemble(self.intel, [candidate], self.root / f"assembled-{field}") + + def test_layout_and_platform_packaging_reject_missing_snapshot_inputs(self): + for missing in ("rootfs", "program", "kernel", "all"): + with self.subTest(missing=missing): + root = self.root / f"missing-{missing}" + directory = root / "providers/test/build/rootfs" + directory.parent.mkdir(parents=True) + shutil.copytree(self.intel, directory) + self.record_snapshot_inputs(directory) + manifest = oci.read_json(directory / "manifest.json") + index_path = directory / manifest["snapshotIndex"]["path"] + index = oci.read_json(index_path) + for item in index["manifests"]: + for field in ("rootfs", "program", "kernel"): + if missing in (field, "all"): + item["annotations"].pop(f"dev.lampyr.provider.{field}.sha256") + index_path.write_bytes(oci.json_bytes(index)) + manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) + (directory / "manifest.json").write_text(json.dumps(manifest)) + for name, check in ( + ("layout", lambda: oci.layout_files(directory)), + ("platform package", lambda: platform_package["provider_files"](root, "test")), + ): + with self.subTest(check=name): + with self.assertRaisesRegex(ValueError, "snapshot.*(digest|asset|input)"): + check() + + def test_distinct_platform_assets_still_assemble_and_bind(self): + for directory, operating_system, architecture in ( + (self.intel, "linux", "x86_64"), + (self.arm, "macos", "aarch64"), + ): + manifest = oci.read_json(directory / "manifest.json") + manifest["coldCompatibility"] = {"os": operating_system, "architecture": architecture} + for field in ("rootfs", "kernel"): + path = directory / manifest[field]["path"] + path.write_bytes(f"{architecture} {field}".encode()) + manifest[field] = package.file_digest(path) + (directory / "manifest.json").write_text(json.dumps(manifest)) + self.record_snapshot_inputs(directory) + oci.assemble(self.intel, [self.intel, self.arm], self.output) + bound = self.root / "bound-distinct-arm" + oci.bind(self.arm, self.output, "ghcr.io/example/snapshots", bound) + for directory in (self.output, bound): + manifest, _ = oci.layout_files(directory) + self.assertEqual(len(oci.read_json(directory / "index.json")["manifests"]), 2) + architecture = manifest["coldCompatibility"]["architecture"] + self.assertEqual((directory / "rootfs.cpio").read_bytes(), + f"{architecture} rootfs".encode()) + def test_multi_platform_index_is_reproducible_and_digest_pinned(self): digest = self.assemble() second = self.root / "second" From 0ded7cbf3e1b75cbc62b337ad16689cba013e960 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Sat, 14 Nov 2026 00:59:12 +0000 Subject: [PATCH 2/3] fix: bind provider snapshots to exact source assets Signed-off-by: James Sturtevant --- cli/src/artifact.rs | 15 +++- cli/src/artifact/variants.rs | 126 +++++++++++++++++++++++++-- cli/src/assets.rs | 35 +++++++- cli/src/embedded-kernels.json | 7 ++ cli/src/provider_registry.rs | 33 ++++++- cli/src/provider_registry/tests.rs | 59 +++++++++++++ cli/src/provider_snapshot.rs | 61 ++++++++++++- cli/tests/artifact.rs | 61 +++++++++---- docs/provider-authoring.md | 32 +++++-- providers/package.py | 18 ++-- providers/snapshot_oci.py | 39 ++++++++- providers/tests/test_snapshot_oci.py | 112 +++++++++++++++++++----- 12 files changed, 531 insertions(+), 67 deletions(-) create mode 100644 cli/src/embedded-kernels.json diff --git a/cli/src/artifact.rs b/cli/src/artifact.rs index bd1367b..09e3693 100644 --- a/cli/src/artifact.rs +++ b/cli/src/artifact.rs @@ -407,7 +407,11 @@ impl Artifact { None } Some(registry) => { - match registry.pull_selected(&format!("sha256:{}", index.sha256), host) { + match registry.pull_for_provider( + &format!("sha256:{}", index.sha256), + host, + &manifest, + ) { Ok(Some(layout)) if layout.digest.is_none() => { warn_no_snapshot_variant(&manifest.id, host); None @@ -443,8 +447,13 @@ impl Artifact { } }, _ => { - let selected = - variants::select_layout(&directory, index, host, &artifact_path)?; + let selected = variants::select_layout( + &directory, + index, + host, + &artifact_path, + &manifest, + )?; if selected.is_none() { warn_no_snapshot_variant(&manifest.id, host); } diff --git a/cli/src/artifact/variants.rs b/cli/src/artifact/variants.rs index 2d08b80..6896a25 100644 --- a/cli/src/artifact/variants.rs +++ b/cli/src/artifact/variants.rs @@ -10,7 +10,7 @@ use cap_std::fs::Dir; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; -use super::{FileDigest, open_artifact_file}; +use super::{FileDigest, Manifest, open_artifact_file}; use crate::runtime::PAYLOAD_LIMIT; const INDEX: &str = "application/vnd.oci.image.index.v1+json"; @@ -114,7 +114,12 @@ fn native_compatibility() -> Option<(String, String)> { } impl SnapshotIndex { - pub fn select(&self, host: &HostCompatibility) -> Result> { + /// Prefetch has no provider manifest, but still requires complete input bindings. + pub fn select( + &self, + host: &HostCompatibility, + provider: Option<&Manifest>, + ) -> Result> { ensure!( self.schema_version == 2 && self.media_type == INDEX, "unsupported provider snapshot OCI index" @@ -126,7 +131,7 @@ impl SnapshotIndex { let (Some(hypervisor), Some(vendor)) = (&host.hypervisor, &host.cpu_vendor) else { return Ok(None); }; - Ok(self + let selected = self .manifests .iter() .filter(|descriptor| { @@ -139,7 +144,11 @@ impl SnapshotIndex { .is_some_and(|release| release.ends_with('-')) }) }) - .min_by(|left, right| (&left.digest, left.size).cmp(&(&right.digest, right.size)))) + .min_by(|left, right| (&left.digest, left.size).cmp(&(&right.digest, right.size))); + if let Some(selected) = selected { + selected.validate_inputs(provider, &host.architecture)?; + } + Ok(selected) } } @@ -148,6 +157,7 @@ pub(super) fn select_layout( file: &FileDigest, host: &HostCompatibility, artifact_path: &Path, + provider: &Manifest, ) -> Result> { let (bytes, _) = read_verified(directory, file, PAYLOAD_LIMIT as u64, true)?; let index: SnapshotIndex = @@ -159,7 +169,7 @@ pub(super) fn select_layout( .is_some_and(|name| name == "index.json"), "provider snapshot index must name a native OCI index.json" ); - let Some(descriptor) = index.select(host)? else { + let Some(descriptor) = index.select(host, Some(provider))? else { return Ok(None); }; let parent = index_path @@ -275,6 +285,46 @@ impl SnapshotManifest { } impl OciDescriptor { + fn validate_inputs(&self, provider: Option<&Manifest>, architecture: &str) -> Result<()> { + let kernel = provider + .map(|provider| { + provider.kernel.as_ref().map_or_else( + || crate::assets::embedded_kernel_sha256(architecture), + |file| Ok(file.sha256.clone()), + ) + }) + .transpose()?; + for (field, expected) in [ + ( + "rootfs", + provider.map(|provider| provider.rootfs.sha256.as_str()), + ), + ( + "program", + provider.map(|provider| provider.program.sha256.as_str()), + ), + ("kernel", kernel.as_deref()), + ] { + let actual = self + .annotations + .get(&format!("dev.lampyr.provider.{field}.sha256")); + ensure!( + actual.is_some_and(|hash| hash.len() == 64 + && hash + .bytes() + .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))), + "selected provider snapshot {field} digest is missing or invalid; recapture the variant" + ); + if let Some(expected) = expected { + ensure!( + actual.map(String::as_str) == Some(expected), + "selected provider snapshot {field} digest does not match the provider's cold-boot asset" + ); + } + } + Ok(()) + } + pub(crate) fn hash(&self, limit: u64) -> Result<&str> { let hash = self .digest @@ -347,6 +397,72 @@ fn read_verified( #[cfg(test)] mod tests { use super::*; + use serde_json::json; + + #[test] + fn selected_variant_bindings_are_required_and_checked_before_blob_loading() { + let host = HostCompatibility { + architecture: "x86_64".into(), + hypervisor: Some("kvm".into()), + cpu_vendor: Some("GenuineIntel".into()), + }; + let provider: Manifest = serde_json::from_value(json!({ + "protocolVersion": 1, "id": "test", "version": "1", + "runtimeVersion": crate::assets::VERSION, "memoryMiB": 256, + "rootfs": {"path": "rootfs.cpio", "sha256": "a".repeat(64)}, + "program": {"path": "provider.py", "sha256": "b".repeat(64)}, + "operations": {"describe": []}, + })) + .unwrap(); + let mut selected = layer(MANIFEST, 1); + selected.annotations = BTreeMap::from([ + (ARCH.into(), host.architecture.clone()), + (HYPERVISOR.into(), "kvm".into()), + (CPU_VENDOR.into(), "GenuineIntel".into()), + ( + REF_NAME.into(), + format!( + "{}-{}", + crate::assets::VERSION, + hyperlight_unikraft::SNAPSHOT_KEY + ), + ), + ( + "dev.lampyr.provider.rootfs.sha256".into(), + provider.rootfs.sha256.clone(), + ), + ( + "dev.lampyr.provider.program.sha256".into(), + provider.program.sha256.clone(), + ), + ( + "dev.lampyr.provider.kernel.sha256".into(), + crate::assets::embedded_kernel_sha256(&host.architecture).unwrap(), + ), + ]); + let index = SnapshotIndex { + schema_version: 2, + media_type: INDEX.into(), + manifests: vec![selected], + }; + assert!(index.select(&host, Some(&provider)).unwrap().is_some()); + for field in ["rootfs", "program", "kernel"] { + for value in [None, Some("c".repeat(64)), Some("SHA256:bad".into())] { + let mut invalid = index.clone(); + let key = format!("dev.lampyr.provider.{field}.sha256"); + if let Some(value) = value { + invalid.manifests[0].annotations.insert(key, value); + } else { + invalid.manifests[0].annotations.remove(&key); + } + let error = invalid.select(&host, Some(&provider)).unwrap_err(); + assert!(error.to_string().contains(field), "{error}"); + let mut other = host.clone(); + other.cpu_vendor = Some("AuthenticAMD".into()); + assert!(invalid.select(&other, Some(&provider)).unwrap().is_none()); + } + } + } fn layer(media_type: &str, size: u64) -> OciDescriptor { OciDescriptor { diff --git a/cli/src/assets.rs b/cli/src/assets.rs index f9dc963..184dedc 100644 --- a/cli/src/assets.rs +++ b/cli/src/assets.rs @@ -18,7 +18,33 @@ pub(crate) const UNIKRAFT_COMMIT: &str = "3b7cba8816c02a497e7b5aa9c901655784a010 const RELEASE: &str = "https://github.com/hyperlight-dev/hyperlight-unikraft/releases/download/v0.21.0"; const KERNEL: &str = "https://raw.githubusercontent.com/hyperlight-dev/hyperlight-unikraft/34c0d647a9f8679c0ce53b76e174894b2c5bfa7a/kernel/elfloader_hyperlight-x86_64"; -const KERNEL_HASH: &str = "fb05f5f9150b9c48de9c035b94eee0fa4c580bd5332586b48f0cee2e860cf861"; + +/// Full hashes of the kernels in the checksum-locked hyperlight-unikraft crate. +pub fn embedded_kernel_sha256(architecture: &str) -> Result { + let pins: serde_json::Value = serde_json::from_str(include_str!("embedded-kernels.json"))?; + ensure!( + pins["runtimeVersion"] == VERSION, + "embedded provider kernel hashes need updating for runtime {VERSION}" + ); + let hash = pins["kernels"][architecture] + .as_str() + .map(str::to_owned) + .context("provider snapshot has no pinned embedded kernel for its architecture")?; + ensure!( + hash.len() == 64 + && hash + .bytes() + .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte)), + "invalid pinned embedded provider kernel hash" + ); + if architecture == std::env::consts::ARCH { + ensure!( + hyperlight_unikraft::SNAPSHOT_KEY.starts_with(&format!("k{}-c", &hash[..16])), + "embedded provider kernel hash does not match the runtime snapshot key" + ); + } + Ok(hash) +} struct Binary { target: &'static str, @@ -115,16 +141,17 @@ pub fn setup(root: &Path, host: &Host) -> Result<()> { install_binary(&native, &native_path(root), host)?; } let kernel = root.join("build/kernel"); - if !matches(&kernel, KERNEL_HASH)? { + let kernel_hash = embedded_kernel_sha256("x86_64")?; + if !matches(&kernel, &kernel_hash)? { let file = download( KERNEL, root.join("build").as_path(), - KERNEL_HASH, + &kernel_hash, 128 << 20, Duration::from_secs(120), host, )?; - install(file.reopen()?, &kernel, KERNEL_HASH)?; + install(file.reopen()?, &kernel, &kernel_hash)?; } Ok(()) } diff --git a/cli/src/embedded-kernels.json b/cli/src/embedded-kernels.json new file mode 100644 index 0000000..542bcf7 --- /dev/null +++ b/cli/src/embedded-kernels.json @@ -0,0 +1,7 @@ +{ + "runtimeVersion": "0.21.0", + "kernels": { + "x86_64": "fb05f5f9150b9c48de9c035b94eee0fa4c580bd5332586b48f0cee2e860cf861", + "aarch64": "097a8080d7532764d557526b5a5da536cbf5269d52cdb09b7664d53a285ca5be" + } +} diff --git a/cli/src/provider_registry.rs b/cli/src/provider_registry.rs index a342a50..cf05051 100644 --- a/cli/src/provider_registry.rs +++ b/cli/src/provider_registry.rs @@ -25,7 +25,9 @@ use sha2::{Digest, Sha256}; use url::Url; use zeroize::{Zeroize, Zeroizing}; -use crate::artifact::{HostCompatibility, OciDescriptor, SnapshotIndex, SnapshotManifest}; +use crate::artifact::{ + HostCompatibility, Manifest, OciDescriptor, SnapshotIndex, SnapshotManifest, +}; use crate::runtime::{Cancellation, PAYLOAD_LIMIT}; const INDEX: &str = "application/vnd.oci.image.index.v1+json"; @@ -170,14 +172,37 @@ impl SnapshotRegistry { &self, digest: &str, host: &HostCompatibility, + ) -> Result> { + self.pull_checked(digest, host, None) + } + + pub(crate) fn pull_for_provider( + &self, + digest: &str, + host: &HostCompatibility, + provider: &Manifest, + ) -> Result> { + self.pull_checked(digest, host, Some(provider)) + } + + fn pull_checked( + &self, + digest: &str, + host: &HostCompatibility, + provider: Option<&Manifest>, ) -> Result> { ensure!(!self.cancellation.is_cancelled(), "snapshot pull cancelled"); - let result = self.pull_inner(digest, host); + let result = self.pull_inner(digest, host, provider); ensure!(!self.cancellation.is_cancelled(), "snapshot pull cancelled"); result } - fn pull_inner(&self, digest: &str, host: &HostCompatibility) -> Result> { + fn pull_inner( + &self, + digest: &str, + host: &HostCompatibility, + provider: Option<&Manifest>, + ) -> Result> { let index_descriptor = OciDescriptor { media_type: INDEX.into(), digest: digest.into(), @@ -265,7 +290,7 @@ impl SnapshotRegistry { }; let parsed: SnapshotIndex = serde_json::from_slice(&index).context("decode registry snapshot index")?; - let selected = parsed.select(host)?; + let selected = parsed.select(host, provider)?; if let Some(descriptor) = selected { let bytes = read_limited( self.blob( diff --git a/cli/src/provider_registry/tests.rs b/cli/src/provider_registry/tests.rs index b95b764..c6a9ee6 100644 --- a/cli/src/provider_registry/tests.rs +++ b/cli/src/provider_registry/tests.rs @@ -576,6 +576,18 @@ fn fixture() -> Fixture { "dev.hyperlight.snapshot.cpu.vendor".into(), "GenuineIntel".into(), ), + ( + "dev.lampyr.provider.rootfs.sha256".into(), + hex(&Sha256::digest(b"rootfs")), + ), + ( + "dev.lampyr.provider.program.sha256".into(), + hex(&Sha256::digest(b"# provider")), + ), + ( + "dev.lampyr.provider.kernel.sha256".into(), + crate::assets::embedded_kernel_sha256(&host().architecture).unwrap(), + ), ]); let index = serde_json::to_vec(&SnapshotIndex { schema_version: 2, @@ -921,6 +933,53 @@ fn pulls_verified_layout_and_startup_consumes_it_offline() { ); } +#[test] +fn provider_input_mismatch_from_registry_is_not_a_cold_boot_or_a_layer_download() { + for field in ["rootfs", "program", "kernel"] { + let mut fixture = fixture(); + let original_route = format!("/v2/provider/test/manifests/{}", fixture.digest); + let mut index: SnapshotIndex = + serde_json::from_slice(&fixture.routes.remove(&original_route).unwrap()).unwrap(); + index.manifests[0].annotations.insert( + format!("dev.lampyr.provider.{field}.sha256"), + "0".repeat(64), + ); + let bytes = serde_json::to_vec(&index).unwrap(); + fixture.digest = descriptor(&bytes, INDEX).digest; + let index_route = format!("/v2/provider/test/manifests/{}", fixture.digest); + fixture.routes.insert(index_route.clone(), bytes); + let digest = fixture.digest.clone(); + let calls = Arc::new(Mutex::new(Vec::new())); + let requests = calls.clone(); + let mock = Mock::new(move |request| { + requests.lock().unwrap().push(request.path.clone()); + Reply::new(200, fixture.routes[&request.path].clone()) + }); + let source = tempfile::tempdir().unwrap(); + artifact(source.path(), &digest); + let cache = tempfile::tempdir().unwrap(); + let registry = client(&mock, cache.path()); + let error = + Artifact::load_for_host_with_registry(source.path(), "test", &host(), Some(®istry)) + .err() + .expect("registry input mismatch must not cold-boot"); + assert!( + error + .to_string() + .contains(&format!("snapshot {field} digest")), + "{error}" + ); + assert!(!SnapshotRegistry::is_unavailable(&error)); + let calls = calls.lock().unwrap(); + assert!(calls.contains(&index_route)); + assert!( + calls + .iter() + .all(|path| path == "/v2/" || path == &index_route) + ); + } +} + #[test] fn fallback_is_only_absent_index_or_no_compatible_variant() { let fixture = fixture(); diff --git a/cli/src/provider_snapshot.rs b/cli/src/provider_snapshot.rs index 1c03ff4..4502400 100644 --- a/cli/src/provider_snapshot.rs +++ b/cli/src/provider_snapshot.rs @@ -1,12 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright 2026 The Hyperlight Authors. -use std::path::PathBuf; +use std::collections::BTreeMap; +use std::io::Read; +use std::path::{Path, PathBuf}; use anyhow::{Context, Result, ensure}; use clap::Parser; use hyperlight_unikraft::SandboxBuilder; -use lampyr_cli::artifact::HostCompatibility; +use lampyr_cli::artifact::{HostCompatibility, SnapshotIndex}; +use sha2::{Digest, Sha256}; #[derive(Parser)] #[command(about = "Create a warm snapshot for a packaged provider guest")] @@ -14,6 +17,8 @@ struct Args { #[arg(long)] rootfs: PathBuf, #[arg(long)] + program: PathBuf, + #[arg(long)] kernel: Option, #[arg(long)] output: PathBuf, @@ -21,6 +26,39 @@ struct Args { memory_mib: usize, } +fn file_hash(path: &Path) -> Result { + let mut file = std::fs::File::open(path)?; + let mut digest = Sha256::new(); + let mut buffer = [0_u8; 64 * 1024]; + loop { + let count = file.read(&mut buffer)?; + if count == 0 { + break; + } + digest.update(&buffer[..count]); + } + Ok(digest + .finalize() + .iter() + .map(|b| format!("{b:02x}")) + .collect()) +} + +fn input_annotations(args: &Args) -> Result> { + let kernel = match &args.kernel { + Some(path) => file_hash(path)?, + None => lampyr_cli::assets::embedded_kernel_sha256(std::env::consts::ARCH)?, + }; + Ok([ + ("rootfs", file_hash(&args.rootfs)?), + ("program", file_hash(&args.program)?), + ("kernel", kernel), + ] + .into_iter() + .map(|(field, hash)| (format!("dev.lampyr.provider.{field}.sha256"), hash)) + .collect()) +} + fn run(args: Args) -> Result<()> { ensure!( (128..=4096).contains(&args.memory_mib), @@ -31,7 +69,8 @@ fn run(args: Args) -> Result<()> { compatibility.hypervisor.is_some() && compatibility.cpu_vendor.is_some(), "provider snapshots require a supported native hypervisor" ); - let output = std::path::absolute(args.output)?; + let inputs = input_annotations(&args).context("hash provider snapshot inputs")?; + let output = std::path::absolute(&args.output)?; let parent = output .parent() .context("provider snapshot output has no parent")?; @@ -40,13 +79,27 @@ fn run(args: Args) -> Result<()> { .prefix(".provider-snapshot-") .tempdir_in(parent)?; let mut builder = SandboxBuilder::from_initrd(&args.rootfs).scratch_mb(args.memory_mib); - if let Some(kernel) = args.kernel { + if let Some(kernel) = &args.kernel { builder = builder.kernel(kernel); } let mut sandbox = builder.boot().context("boot provider guest for snapshot")?; sandbox .snapshot_to(staging.path()) .context("save provider runtime snapshot")?; + ensure!( + input_annotations(&args)? == inputs, + "provider inputs changed during snapshot capture" + ); + let index_path = staging.path().join("index.json"); + let mut index: SnapshotIndex = serde_json::from_slice(&std::fs::read(&index_path)?)?; + ensure!( + !index.manifests.is_empty(), + "captured provider snapshot has no variants" + ); + for descriptor in &mut index.manifests { + descriptor.annotations.extend(inputs.clone()); + } + std::fs::write(index_path, serde_json::to_vec(&index)?)?; let restored = hyperlight_unikraft::load_snapshot(staging.path()) .context("load captured provider snapshot")?; SandboxBuilder::from_snapshot(restored) diff --git a/cli/tests/artifact.rs b/cli/tests/artifact.rs index 4127a78..8bfca00 100644 --- a/cli/tests/artifact.rs +++ b/cli/tests/artifact.rs @@ -177,6 +177,22 @@ fn variant(root: &tempfile::TempDir, compatibility: &HostCompatibility) -> OciDe compatibility.cpu_vendor.clone().unwrap(), ), ]); + let provider: Manifest = + serde_json::from_slice(&std::fs::read(root.path().join("manifest.json")).unwrap()).unwrap(); + for (field, hash) in [ + ("rootfs", provider.rootfs.sha256), + ("program", provider.program.sha256), + ( + "kernel", + provider.kernel.map(|file| file.sha256).unwrap_or_else(|| { + lampyr_cli::assets::embedded_kernel_sha256(&compatibility.architecture).unwrap() + }), + ), + ] { + descriptor + .annotations + .insert(format!("dev.lampyr.provider.{field}.sha256"), hash); + } descriptor } @@ -375,15 +391,15 @@ fn variant_selection_is_order_independent_and_requires_all_compatibility_fields( unsupported, ], }; - assert!(index.select(&host()).unwrap().is_none()); + assert!(index.select(&host(), None).unwrap().is_none()); index.manifests.extend([first, second.clone()]); assert_eq!( - index.select(&host()).unwrap().unwrap().digest, + index.select(&host(), None).unwrap().unwrap().digest, second.digest ); index.manifests.reverse(); assert_eq!( - index.select(&host()).unwrap().unwrap().digest, + index.select(&host(), None).unwrap().unwrap().digest, second.digest ); } @@ -699,20 +715,35 @@ fn hyperlight_native_writer_round_trips_through_provider_variant_loading() { std::fs::write(root.path().join("rootfs.cpio"), &cpio).unwrap(); manifest.rootfs = digest("rootfs.cpio", &cpio); let layout = root.path().join("snapshot"); - let mut sandbox = - hyperlight_unikraft::SandboxBuilder::from_initrd(root.path().join("rootfs.cpio")) - .scratch_mb(128) - .boot() - .unwrap(); - sandbox.snapshot_to(&layout).unwrap_or_else(|error| { - panic!( - "save native snapshot: {error}; guest output: {}", - sandbox.drain_output() - ) - }); - drop(sandbox); + let captured = std::process::Command::new(env!("CARGO_BIN_EXE_provider-snapshot")) + .arg("--rootfs") + .arg(root.path().join("rootfs.cpio")) + .arg("--program") + .arg(root.path().join("provider.py")) + .args(["--memory-mib", "128", "--output"]) + .arg(&layout) + .output() + .unwrap(); + assert!( + captured.status.success(), + "capture provider snapshot: {}", + String::from_utf8_lossy(&captured.stderr) + ); let mut index: SnapshotIndex = serde_json::from_slice(&std::fs::read(layout.join("index.json")).unwrap()).unwrap(); + for (field, hash) in [ + ("rootfs", manifest.rootfs.sha256.clone()), + ("program", manifest.program.sha256.clone()), + ( + "kernel", + lampyr_cli::assets::embedded_kernel_sha256(std::env::consts::ARCH).unwrap(), + ), + ] { + assert_eq!( + index.manifests[0].annotations[&format!("dev.lampyr.provider.{field}.sha256")], + hash + ); + } let mut incompatible = index.manifests[0].clone(); incompatible.annotations.insert( "dev.hyperlight.snapshot.cpu.vendor".into(), diff --git a/docs/provider-authoring.md b/docs/provider-authoring.md index ddb4284..c260c7c 100644 --- a/docs/provider-authoring.md +++ b/docs/provider-authoring.md @@ -145,12 +145,11 @@ snapshot key. It also records the kernel and host-contract `SNAPSHOT_KEY`. If KVM is not accessible, the script creates an artifact without a snapshot. -The CLI restores a supplied single snapshot only if its compatibility metadata -matches the host. +The CLI restores a supplied snapshot only if its compatibility metadata +matches the host and its input digests match the provider artifact. The snapshot key must match the current kernel and host contract. -It checks single snapshots without matching metadata but does not restore them. -If the artifact has no snapshot, the CLI starts the guest from the root -filesystem. This procedure is called a cold boot. +If the artifact has no host-compatible snapshot, the CLI starts the guest from +the root filesystem. This procedure is called a cold boot. `ly` uses installed cold-boot assets in place; it does not copy the rootfs or a custom kernel into a temporary directory. The artifact directory and its files @@ -201,6 +200,29 @@ For multiple matches, the smallest digest wins; size breaks equal-digest ties. No match causes a cold boot. `snapshotIndex` takes precedence over `snapshot`. An invalid index or corrupt selected snapshot causes an error, not a cold boot. +Each manifest descriptor must also record these capture-input annotations: + +| Annotation | Value | +|---|---| +| `dev.lampyr.provider.rootfs.sha256` | SHA-256 of the exact rootfs bytes. | +| `dev.lampyr.provider.program.sha256` | SHA-256 of the exact provider program bytes. | +| `dev.lampyr.provider.kernel.sha256` | SHA-256 of the custom kernel, or the native embedded kernel when `kernel` is absent. | + +Use 64 lowercase hexadecimal characters without a `sha256:` prefix. +`providers/package.py --snapshot-mode variant` records these values through +`provider-snapshot`. Recapture the variant when any input changes. Old variants +without these values are not accepted. A missing or different input digest in +the selected variant causes an error, not a cold boot. + +Assembly checks each variant against its source artifact. For a shared Linux +and macOS index, set `coldCompatibility` on each source artifact. The rootfs +and kernel must match the cold assets for that platform; the program must match +for every platform. Assembly, binding, and platform packaging check these values +when the local layout is present. Release jobs build and capture both platforms +again, check the complete layouts, and then omit them from release archives. +The full embedded-kernel hashes are pinned in `cli/src/embedded-kernels.json` +from the checksum-locked runtime crate. Update these pins with the runtime. + These compatibility labels are the minimum selection keys, not a substitute for Hyperlight's restore-time checks of snapshot internals and CPU features. The provider's protocol/runtime version, program, memory, and cold-boot assets diff --git a/providers/package.py b/providers/package.py index 92121cc..012f1bd 100644 --- a/providers/package.py +++ b/providers/package.py @@ -13,6 +13,7 @@ import sys from permissions import others_can_write +import snapshot_oci def file_digest(path): @@ -151,6 +152,12 @@ def main(): shutil.copyfile(project / "provider.py", output / "provider.py") manifest["rootfs"] = file_digest(output / "rootfs.cpio") manifest["program"] = file_digest(output / "provider.py") + if args.kernel is not None: + shutil.copyfile(args.kernel, output / "kernel") + restrict_artifact_permissions(output, allow_stale_snapshot_symlinks=True) + manifest["kernel"] = file_digest(output / "kernel") + else: + manifest["kernel"] = None if args.cold_os is None: manifest.pop("coldCompatibility", None) else: @@ -188,13 +195,15 @@ def main(): command.extend([ "--rootfs", str(output / "rootfs.cpio"), + "--program", + str(output / "provider.py"), "--memory-mib", str(manifest["memoryMiB"]), "--output", str(output / "snapshot"), ]) if args.kernel is not None: - command.extend(["--kernel", str(args.kernel.resolve(strict=True))]) + command.extend(["--kernel", str(output / "kernel")]) subprocess.run(command, check=True) restrict_artifact_permissions(output) snapshot_directory = output / "snapshot" @@ -206,15 +215,12 @@ def main(): f"provider snapshot not generated: {reason}; using cold-boot fallback", file=sys.stderr, ) - if args.kernel is not None: - shutil.copyfile(args.kernel, output / "kernel") - manifest["kernel"] = file_digest(output / "kernel") - else: - manifest["kernel"] = None temporary = output / ".manifest.json" temporary.write_text(json.dumps(manifest, indent=2) + "\n", encoding="utf-8") temporary.replace(output / "manifest.json") restrict_artifact_permissions(output) + if manifest.get("snapshotIndex") is not None: + snapshot_oci.layout_files(output, all_assets=True) print(f"packaged {manifest['id']} {manifest['version']}: {output}") diff --git a/providers/snapshot_oci.py b/providers/snapshot_oci.py index a562ea3..b7c956a 100644 --- a/providers/snapshot_oci.py +++ b/providers/snapshot_oci.py @@ -219,6 +219,40 @@ def cold_files(directory): return manifest, files +def embedded_kernel_hash(architecture): + pins = read_json(Path(__file__).resolve().parents[1] / "cli/src/embedded-kernels.json") + if pins["runtimeVersion"] != RUNTIME_VERSION: + raise ValueError("embedded provider kernel hashes need updating for this runtime") + try: + return pins["kernels"][architecture] + except KeyError: + raise ValueError("snapshot architecture has no pinned embedded kernel") from None + + +def snapshot_platform(annotations): + return { + "os": {"hvf": "macos", "whp": "windows"}.get(annotations[HYPERVISOR], "linux"), + "architecture": annotations[ARCH], + } + + +def checked_snapshot_inputs(annotations, manifest, all_assets=False): + same_platform = ( + all_assets or manifest.get("coldCompatibility") is None + or manifest["coldCompatibility"] == snapshot_platform(annotations) + ) + for field in ("rootfs", "program", "kernel"): + actual = annotations.get(f"dev.lampyr.provider.{field}.sha256") + if not isinstance(actual, str) or not re.fullmatch(r"[0-9a-f]{64}", actual): + raise ValueError(f"snapshot {field} digest is missing or invalid; recapture the variant") + if field != "program" and not same_platform: + continue + expected = manifest.get(field) + expected_hash = expected["sha256"] if expected is not None else embedded_kernel_hash(annotations[ARCH]) + if actual != expected_hash: + raise ValueError(f"snapshot {field} digest does not match the provider's cold-boot asset") + + def identity(manifest): return {key: value for key, value in manifest.items() if key not in ("rootfs", "kernel", "coldCompatibility", @@ -361,6 +395,8 @@ def assemble(artifact, variants, output): raise ValueError("at most 128 snapshot variants are supported") for native in index["manifests"]: annotations = native["annotations"] + checked_snapshot_inputs(annotations, candidate, all_assets=True) + checked_snapshot_inputs(annotations, manifest) key = tuple(annotations[name] for name in (ARCH, HYPERVISOR, CPU_VENDOR, REF_NAME)) if key in seen: raise ValueError("duplicate snapshot compatibility tuple") @@ -434,7 +470,7 @@ def checked_annotations(item): return annotations -def layout_files(directory): +def layout_files(directory, *, all_assets=False): """Validate all variants, not just the current host's selected variant.""" manifest, files = cold_files(directory) index_path = checked_file(directory, manifest["snapshotIndex"], JSON_LIMIT) @@ -481,6 +517,7 @@ def layout_files(directory): ("arch", ARCH), ("hypervisor", HYPERVISOR), ("cpu_vendor", CPU_VENDOR), )): raise ValueError("snapshot config does not match compatibility annotations") + checked_snapshot_inputs(annotations, manifest, all_assets=all_assets) # The layers' kinds and declared total are checked before any memory layer is hashed. *memory_layers, transport_layer = image["layers"] if (not all(isinstance(layer, dict) for layer in image["layers"]) diff --git a/providers/tests/test_snapshot_oci.py b/providers/tests/test_snapshot_oci.py index 5aaad61..4411159 100644 --- a/providers/tests/test_snapshot_oci.py +++ b/providers/tests/test_snapshot_oci.py @@ -47,6 +47,10 @@ def variant(self, name, vendor, architecture="amd64", hypervisor="kvm", memory_l manifest = { "id": "test", "version": "1.2.3", "protocolVersion": 1, "runtimeVersion": oci.RUNTIME_VERSION, "memoryMiB": 256, "operations": {"describe": []}, + "coldCompatibility": { + "os": {"hvf": "macos", "whp": "windows"}.get(hypervisor, "linux"), + "architecture": {"amd64": "x86_64", "arm64": "aarch64"}[architecture], + }, } for field, filename in (("rootfs", "rootfs.cpio"), ("program", "provider.py"), ("kernel", "kernel")): path = directory / filename @@ -74,6 +78,8 @@ def variant(self, name, vendor, architecture="amd64", hypervisor="kvm", memory_l image["annotations"] = { oci.ARCH: native_arch, oci.HYPERVISOR: hypervisor, oci.CPU_VENDOR: vendor, oci.REF_NAME: f"{oci.RUNTIME_VERSION}-test-snapshot-key", + **{f"dev.lampyr.provider.{field}.sha256": manifest[field]["sha256"] + for field in ("rootfs", "program", "kernel")}, } (snapshot / "index.json").write_bytes(oci.json_bytes({ "schemaVersion": 2, "mediaType": oci.INDEX, "manifests": [image], @@ -103,7 +109,11 @@ def record_snapshot_inputs(self, directory): index = oci.read_json(index_path) for item in index["manifests"]: for field in ("rootfs", "program", "kernel"): - item["annotations"][f"dev.lampyr.provider.{field}.sha256"] = manifest[field]["sha256"] + asset = manifest.get(field) + item["annotations"][f"dev.lampyr.provider.{field}.sha256"] = ( + asset["sha256"] if asset is not None + else oci.embedded_kernel_hash(item["annotations"][oci.ARCH]) + ) index_path.write_bytes(oci.json_bytes(index)) manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) (directory / "manifest.json").write_text(json.dumps(manifest)) @@ -192,6 +202,23 @@ def test_distinct_platform_assets_still_assemble_and_bind(self): self.assertEqual((directory / "rootfs.cpio").read_bytes(), f"{architecture} rootfs".encode()) + def test_embedded_kernel_binding_is_checked_without_a_custom_kernel(self): + manifest_path = self.intel / "manifest.json" + manifest = oci.read_json(manifest_path) + manifest["kernel"] = None + manifest_path.write_text(json.dumps(manifest)) + self.record_snapshot_inputs(self.intel) + oci.layout_files(self.intel) + manifest = oci.read_json(manifest_path) + index_path = self.intel / manifest["snapshotIndex"]["path"] + index = oci.read_json(index_path) + index["manifests"][0]["annotations"]["dev.lampyr.provider.kernel.sha256"] = "0" * 64 + index_path.write_bytes(oci.json_bytes(index)) + manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) + manifest_path.write_text(json.dumps(manifest)) + with self.assertRaisesRegex(ValueError, "snapshot kernel digest"): + oci.layout_files(self.intel) + def test_multi_platform_index_is_reproducible_and_digest_pinned(self): digest = self.assemble() second = self.root / "second" @@ -390,6 +417,7 @@ def test_empty_index_keeps_cold_assets(self): def test_rejects_mismatched_logical_identity_but_allows_platform_cold_assets(self): original = (self.amd / "manifest.json").read_bytes() + original_index = (self.amd / "snapshot/index.json").read_bytes() for field in ("version", "runtimeVersion", "memoryMiB", "program", "operations"): with self.subTest(field=field): manifest = json.loads(original) @@ -401,6 +429,8 @@ def test_rejects_mismatched_logical_identity_but_allows_platform_cold_assets(sel else: manifest[field] = 128 if field == "memoryMiB" else ({} if field == "operations" else "other") (self.amd / "manifest.json").write_text(json.dumps(manifest)) + if field == "program": + self.record_snapshot_inputs(self.amd) error = {"runtimeVersion": "incompatible provider runtime", "operations": "invalid provider operations"}.get(field, "differ") with self.assertRaisesRegex(ValueError, error): @@ -410,11 +440,14 @@ def test_rejects_mismatched_logical_identity_but_allows_platform_cold_assets(sel if field == "program": path.write_bytes(previous) (self.amd / "manifest.json").write_bytes(original) + (self.amd / "snapshot/index.json").write_bytes(original_index) + original = (self.arm / "manifest.json").read_bytes() + original_index = (self.arm / "snapshot/index.json").read_bytes() for field in ("rootfs", "kernel"): with self.subTest(field=field): manifest = json.loads(original) - path = self.amd / manifest[field]["path"] + path = self.arm / manifest[field]["path"] previous = path.read_bytes() path.write_bytes(b"other") manifest[field] = package.file_digest(path) @@ -422,12 +455,14 @@ def test_rejects_mismatched_logical_identity_but_allows_platform_cold_assets(sel "os": "macos", "architecture": "aarch64", } - (self.amd / "manifest.json").write_text(json.dumps(manifest)) + (self.arm / "manifest.json").write_text(json.dumps(manifest)) + self.record_snapshot_inputs(self.arm) self.assemble() self.assertTrue(self.output.is_dir()) shutil.rmtree(self.output) path.write_bytes(previous) - (self.amd / "manifest.json").write_bytes(original) + (self.arm / "manifest.json").write_bytes(original) + (self.arm / "snapshot/index.json").write_bytes(original_index) def test_rejects_corruption_duplicate_compatibility_and_limits(self): with self.assertRaisesRegex(ValueError, "duplicate"): @@ -1157,25 +1192,26 @@ def test_layer_kinds_are_checked_before_any_layer_is_hashed(self): "unsupported snapshot OCI manifest") def test_aggregate_variant_limit_precedes_next_blob_copy(self): - index_path = self.intel / "snapshot/index.json" - index = oci.read_json(index_path) - native = index["manifests"][0] - variants = [] - for i in range(128): - item = dict(native) - item["annotations"] = dict(native["annotations"]) - item["annotations"][oci.REF_NAME] = f"{oci.RUNTIME_VERSION}-{i}-test-key" - variants.append(item) - index["manifests"] = variants - index_path.write_bytes(oci.json_bytes(index)) - manifest = oci.read_json(self.intel / "manifest.json") - manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) - (self.intel / "manifest.json").write_text(json.dumps(manifest)) + for directory, count in ((self.intel, 64), (self.amd, 65)): + index_path = directory / "snapshot/index.json" + index = oci.read_json(index_path) + native = index["manifests"][0] + variants = [] + for i in range(count): + item = dict(native) + item["annotations"] = dict(native["annotations"]) + item["annotations"][oci.REF_NAME] = f"{oci.RUNTIME_VERSION}-{i}-test-key" + variants.append(item) + index["manifests"] = variants + index_path.write_bytes(oci.json_bytes(index)) + manifest = oci.read_json(directory / "manifest.json") + manifest["snapshotIndex"]["sha256"] = oci.file_hash(index_path) + (directory / "manifest.json").write_text(json.dumps(manifest)) with mock.patch.object(oci, "copy_blob", wraps=oci.copy_blob) as copy: with self.assertRaisesRegex(ValueError, "128"): self.assemble([self.intel, self.amd]) # Each variant's manifest, config, two memory layers and transport. - self.assertEqual(copy.call_count, 128 * 5) + self.assertEqual(copy.call_count, 64 * 5) self.assertTrue(all(call.args[1].is_relative_to(self.intel) for call in copy.call_args_list)) self.assertFalse(self.output.exists()) @@ -1374,7 +1410,7 @@ def test_shared_blobs_are_hashed_and_copied_once_per_distinct_file(self): index = oci.read_json(index_path) native = index["manifests"][0] index["manifests"] = [] - for i in range(128): + for i in range(64): item = dict(native) item["annotations"] = dict(native["annotations"]) item["annotations"][oci.REF_NAME] = f"{oci.RUNTIME_VERSION}-{i}-test-key" @@ -1597,6 +1633,10 @@ def test_package_none_does_not_boot_guest_and_variant_records_native_host(self): copyfile = package.shutil.copyfile def capture(*args, **kwargs): + command = args[0] + self.assertEqual(command[command.index("--program") + 1], str(output / "provider.py")) + self.assertEqual(command[command.index("--kernel") + 1], str(output / "kernel")) + self.assertEqual((output / "kernel").read_bytes(), (self.intel / "kernel").read_bytes()) self.assertFalse((output / "snapshot").is_symlink()) # Stands in for the snapshot tool, so copy with the real # copyfile, not the patched one that checks package.py's copies. @@ -1644,6 +1684,38 @@ def check_permissions_before_digest(path): self.assertIn("snapshotIndex", result) oci.layout_files(output) + def test_package_variant_rejects_stale_or_unbound_capture_helpers(self): + project = self.root / "project" + output = project / "build/rootfs" + shutil.copytree(self.intel, output) + shutil.copyfile(self.intel / "provider.py", project / "provider.py") + (project / "artifact.json").write_text((self.intel / "manifest.json").read_text()) + + def capture(*_args, **_kwargs): + shutil.copytree(self.intel / "snapshot", output / "snapshot") + index_path = output / "snapshot/index.json" + index = oci.read_json(index_path) + for item in index["manifests"]: + if binding == "missing": + for field in ("rootfs", "program", "kernel"): + item["annotations"].pop(f"dev.lampyr.provider.{field}.sha256") + else: + item["annotations"]["dev.lampyr.provider.rootfs.sha256"] = "0" * 64 + index_path.write_bytes(oci.json_bytes(index)) + + for binding in ("missing", "different", "different platform"): + arguments = [ + "package.py", str(project), "rootfs", "--snapshot-mode", "variant", + "--kernel", str(self.intel / "kernel"), + ] + if binding == "different platform": + arguments += ["--cold-os", "macos", "--cold-architecture", "aarch64"] + with self.subTest(binding=binding), mock.patch.object(sys, "argv", arguments), \ + mock.patch.object(package, "native_snapshot_available", return_value=True), \ + mock.patch.object(package.subprocess, "run", side_effect=capture): + with self.assertRaisesRegex(ValueError, "snapshot rootfs digest"): + package.main() + def test_provider_permission_scan_reports_walk_errors(self): output = self.root / "artifact" output.mkdir() From d13eb1992259d7b14c27b0671498e691bf637117 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 16 Nov 2026 19:37:32 -0800 Subject: [PATCH 3/3] fixup! fix: bind provider snapshots to exact source assets Signed-off-by: James Sturtevant --- cli/tests/provider.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cli/tests/provider.rs b/cli/tests/provider.rs index 591c868..eccb547 100644 --- a/cli/tests/provider.rs +++ b/cli/tests/provider.rs @@ -127,13 +127,21 @@ fn exercise_provider_scaffolding(snapshot: bool) { let artifact = artifact(include_str!("fixtures/provider.py")); if snapshot { let layout = artifact.path().join("snapshot"); - let mut guest = - hyperlight_unikraft::SandboxBuilder::from_initrd(artifact.path().join("rootfs.cpio")) - .scratch_mb(256) - .boot() - .unwrap(); - guest.snapshot_to(&layout).unwrap(); - drop(guest); + let output = std::process::Command::new(env!("CARGO_BIN_EXE_provider-snapshot")) + .arg("--rootfs") + .arg(artifact.path().join("rootfs.cpio")) + .arg("--program") + .arg(artifact.path().join("provider.py")) + .arg("--output") + .arg(&layout) + .args(["--memory-mib", "256"]) + .output() + .unwrap(); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); let mut manifest: Manifest = serde_json::from_slice(&std::fs::read(artifact.path().join("manifest.json")).unwrap()) .unwrap();