ContainerDisk: Image Handling & Format Validation#
ContainerDisk is a KubeVirt volume type that packages guest disk images inside OCI container images, letting operators distribute and version VM disks via standard container registries. Each ContainerDisk volume runs as a sidecar container that copies the disk image into a shared directory, which QEMU/libvirt then exposes to the guest VM as a block device.
Key packages:
pkg/container-disk/container-disk.goβ volume lifecycle, sidecar container generation, image path resolutionpkg/os/disk/validation.goβ format validation viaqemu-imgpkg/os/disk/disk.goβDiskInfostruct andQEMUIMGPathpkg/virt-launcher/virtwrap/manager.goβ validation call site inSyncVMI
How ContainerDisk Works#
For each ContainerDisk volume, virt-controller calls GenerateContainers / GenerateInitContainers to produce a sidecar container spec. The sidecar runs /usr/bin/container-disk --copy-path <target> and mounts the disk into the pod's shared container-disks empty-dir volume . Sidecars run as non-root with all Linux capabilities dropped .
At runtime, GetImage resolves which file to use:
- If
containerDisk.pathis set, that path is resolved relative to the container's mounted root. - If
pathis empty, KubeVirt falls back to/disk/inside the container and requires exactly one file there.
The resolved image lands at disk_N.img under the shared mount base directory (/var/run/kubevirt/container-disks/), where virt-launcher picks it up before domain creation. The CreateEphemeralImages function then creates a QCOW2-backed ephemeral overlay on top of the base image for each ContainerDisk volume, using the detected format.
Format Validation#
Before building the libvirt domain, virt-launcher's SyncVMI validates every ContainerDisk image that is not already in its local cache :
-
GetDiskInfoWithValidationβ shells out toqemu-img info --output jsonunder tight resource limits (ulimit -t 10CPU seconds, configurable virtual-memory cap) and parses the result into aDiskInfostruct (Format,BackingFile,ActualSize,VirtualSize). -
VerifyImageβ dispatches on format:qcow2β delegates toVerifyQCOW2, which rejects images that have a backing file.rawβ returnsnilimmediately, with no structural or content check.- anything else β hard error.
If either step fails, SyncVMI returns an "invalid image in containerDisk" error and the VM does not start.
OSTIF Audit Finding INFO-10: The Raw-Disk Validation Gap#
Status: open / unresolved β tracked in kubevirt/kubevirt#19291.
The Quarkslab/OSTIF security audit of KubeVirt (full report) identified that the format-validation path described above does not actually prevent arbitrary files from being presented to a guest VM as block devices .
Root cause β two compounding gaps:
-
qemu-img infoclassifies any unrecognized file asraw. Raw format has no magic bytes, so/etc/passwd, a compiled binary, or any other file reportsformat: rawand passesVerifyImageunconditionally . -
containerDisk.pathis shape-validated, not content-validated. Admission webhooks enforce that the path is absolute, non-relative, and not/, but they do not restrict which files are allowable targets. Any file present in the referenced container image is a validpathvalue .
Demonstrated impact: An attacker (or misconfigured image) can set containerDisk.path: /etc/passwd in a VM spec. The VM boots, and the guest can read the full contents of that file by reading from the corresponding block device (e.g. /dev/vdb). Any secret, credential, or sensitive data accidentally or intentionally included in a container image can be silently leaked to the guest this way .
What would close the gap: Structural validation of files declared as raw β for example, checking a minimum size threshold, verifying that the file is a valid block-device image (e.g. by inspecting partition tables or MBR/GPT signatures), or rejecting files whose size is inconsistent with a disk image. QCOW2 images already benefit from header validation inside VerifyQCOW2 .