crates/image/MATERIALIZATION.md
This document specifies how one verified OCI layer pipeline feeds microsandbox's layered and flat rootfs representations. It is an implementation contract for microsandbox-image; user-facing selection is documented under msb pull --materialize.
diff_id content.| Target | Per-layer EROFS | fsmeta + VMDK | Flat ext4 |
|---|---|---|---|
layered | yes | yes | no |
flat | yes | no | yes |
all | yes | yes | yes |
layered remains the default. The target changes generated cache artifacts, not OCI resolution or verification. Every target resolves the platform manifest and config so the ordered compressed layer descriptors can be paired with the config's signed uncompressed diff_ids.
diff_id. Compression format and image manifest do not affect its identity.diff_ids, target platform, and ext4 materializer ABI. The published raw ext4 blob is addressed by its verified byte digest.The immutable EROFS layer is the common boundary between acquisition and rootfs-specific composition. Flat execution does not mount these layers; it consumes them while creating a complete ext4 artifact.
diff_id counts.diff_id.diff_id, write EROFS to a temporary path, and publish it atomically under a per-layer lock.layered or all, merge layer metadata with provenance and publish fsmeta plus VMDK. A missing manifest-specific fsmeta is reconstructed from cached EROFS metadata and block maps; it must not cause a shared layer to be downloaded again.flat or all, read the ordered cached EROFS layers, apply OCI merge semantics, write and validate one ext4 candidate, publish its content-addressed blob atomically, and finally replace the manifest reference.all runs the shared EROFS stage once and fans out to both compositions. flat skips layered-only fsmeta and VMDK generation entirely.
A normal pull is complete only when every artifact required by its target is valid. Extra representations do not affect the result: a cached flat image does not satisfy layered unless fsmeta and VMDK also exist, and layered artifacts do not satisfy flat unless its verified ext4 reference exists.
Without force, a valid EROFS layer is always reusable, including when the current manifest has never been pulled before. With force, registry blobs and derived artifacts are rebuilt according to the existing force contract. PullPolicy::Always refreshes the manifest but still reuses content-addressed layers unless force is also set. PullPolicy::Never succeeds only when all artifacts required by the selected target are already present locally.
Registry descriptor digests authenticate compressed bytes; config diff_ids authenticate the decompressed layer stream. Reusing EROFS is permitted only after that pair has been verified during its original publication. Readers still validate the structural subset they consume and fail closed on unsupported regular-file layouts, corrupt metadata, invalid device records, missing artifacts, or inconsistent sizes. Target selection never relaxes sandbox isolation or changes the guest-visible filesystem contents.
Flat mode retains shared EROFS inputs as well as complete per-image ext4 outputs. This intentionally spends cache capacity to preserve cross-image acquisition reuse and fast rematerialization. Garbage collection must treat manifest metadata, fsmeta/VMDK, flat references, and active sandbox disks as roots and remove an EROFS layer only when no reachable image composition references its diff_id.