Skip to main content

Module virt

Module virt 

Source
Expand description

Virtualization and containers: what this program runs inside.

The answer is layered checks (CPUID, firmware strings, hypervisor files, container markers, the Kubernetes service account, WSL’s kernel release), read once and cached. Every check that fired is named in Virtualization::evidence, as a constant string, never a raw value.

Detection is advisory. Do not make security decisions on it: any of these markers can be planted, and a guest can hide from all of them (threat T14).

use sys_lib as sys;

let v = sys::virt::detect();
if sys::virt::is_container() {
    println!("in {:?}; kubernetes: {}", v.container, v.kubernetes);
}
for e in &v.evidence {
    println!("  {} ({:?})", e.check, e.strength);
}

Structs§

Evidence
One check that fired.
Virtualization
What this program runs inside. A container inside a VM sets both container and hypervisor; inside WSL 2 both hypervisor and wsl.

Enums§

Cloud
A cloud vendor, from firmware strings only: sys-lib never contacts a metadata service.
Container
A container runtime.
Hypervisor
A hypervisor.
Strength
How much a piece of evidence proves.

Functions§

cloud
The cloud vendor, from firmware strings and the hypervisor leaves. Instance types, regions, and zones need a network call and belong in a cloud crate.
container
The container runtime, when there is one.
detect
What this program runs inside. Cached: about 1 ns after the first call.
hypervisor
The hypervisor, when there is one.
is_container
Running in a container.
is_kubernetes
Running under Kubernetes (see Virtualization::kubernetes).
is_vm
Running on a hypervisor. Inside WSL 2 this and is_wsl are both true. A Windows host with Hyper-V, WSL 2, or virtualization-based security enabled is not a VM (E-84).
is_wsl
Running under WSL.