---
title: "Virtualization.framework"
description: "How the VZ flavour gives a Virtualization.framework VM a TPM, measures its launch, anchors IMA from boot, and what that proves. For building the VM from a checkout."
source: "EQTY Notary"
---
The [Quick Start](./quick-start.mdx) installs this setup from packages. This page explains what
the `vz` flavour of `docker eqty` does on every boot, how to build the VM from a repository
checkout, and what the result proves. The outcome is the same as the [Colima](./wip/colima.mdx)
tutorial: containers get a TPM rooted in the Mac's Secure Enclave, and a program in a container
produces a manifest whose chain ends at the Mac's notary.

The VM underneath is different. It runs on **Apple's Virtualization.framework**, through
[vfkit](https://github.com/crc-org/vfkit), the engine Podman uses on macOS, instead of QEMU, and
the VM's kernel IMA is anchored in the vTPM from the first instruction.

Virtualization.framework has no TPM device, so this needs three things QEMU does not:

1. **A guest kernel we build**, with a `tpm_vsock` driver built in. It carries TPM commands to
   the Mac over vsock.
2. **Host helpers.** A relay connects the VM's vsock port to the notary's vTPM. A per-boot reset
   and a launch measurement do what QEMU's TPM device would.
3. **A local Docker socket.** A Mac proxy carries Docker API traffic through vfkit's vsock to a
   small proxy in the guest, every API connection a channel on one long-lived vsock stream.
   vfkit's per-connection dial stalls for good under a few dozen concurrent connections; one
   stream never trips it.

```text
 macOS                                                     VM (Virtualization.framework, vfkit)
 ┌───────────────────────────────────────────────┐        ┌──────────────────────────────────────┐
 │ Secure Enclave ◄── eqty-notary ── swtpm-notary │        │ our kernel: tpm_vsock (built in)     │
 │                                   ▲ data sock  │        │   └─ registers the TPM before IMA    │
 │                  host/vtpm-relay.py            │  vsock │      IMA extends PCR 10 from boot    │
 │                       ▲  (unix socket) ◄───────┼────────┤ /dev/tpmrm0 ──► docker run --device  │
 │ vfkit ── per-boot: vtpm-reset + measure-launch │  2321  │ guest notary ──► simple.py container │
 │ docker CLI ── local socket ── vsock 2375 ──────┼────────► Docker API proxy ──► dockerd       │
 │ guest control ──────── vsock 2376 ─────────────┼────────► readiness + clean shutdown          │
 └───────────────────────────────────────────────┘        └──────────────────────────────────────┘
```

## What is stock, what is ours

| Piece                                                                  | Kind                            | Notes                                                                                   |
| ---------------------------------------------------------------------- | ------------------------------- | --------------------------------------------------------------------------------------- |
| Virtualization.framework, vfkit, Ubuntu 26.04 cloud image, Docker, tpm2-tools | Stock                    | vfkit only gets launch flags                                                            |
| EQTY notary, swtpm-notary                                              | Ours, released                  | Set up as in the Colima tutorial                                                        |
| Linux kernel 6.18 with Apple's containerization config                 | Stock source plus configuration | `kernel/config-fragment` adds TPM, IMA, partitions, the eBPF features the guest notary needs, and what Docker's swarm and overlay networking and `/proc/pressure` need |
| `kernel/tpm_vsock.c`                                                   | Ours, new                       | About 230 lines of kernel C, GPL. Out of tree; carried as a patch per kernel version   |
| `host/vtpm-relay.py`, `host/vtpm-reset.py`, `host/measure-launch.py`  | Ours, stand-ins                 | Belong in the notary; not built there yet                                               |
| The numbered scripts in `MACOS_DOCKER_VZ/`                             | Tutorial glue                   |                                                                                         |

## Every boot

`docker eqty start`, or `04-start-vm.sh` from a checkout, does this in order:

| #   | Action                                                                    | Why                                                                                                                           |
| --- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| 1   | `eqty-notaryctl vtpm create` if needed, then `vtpm start`                 | Create the user's vTPM on first use and make sure it is running.                                                              |
| 2   | `vtpm-reset.py`: swtpm `CMD_INIT`                                         | A new boot must start with clean PCRs. QEMU's TPM device does this itself; vfkit has no TPM device, so nothing else would.    |
| 3   | `measure-launch.py`: PCR 8 = SHA-256 of the kernel command line, PCR 9 = SHA-256 of the kernel image | No firmware measures the boot, but the Mac knows exactly what it launches. IMA's `boot_aggregate` and every quote then cover it. |
| 4   | `vtpm-relay.py`                                                           | vfkit turns the guest's vsock port 2321 into a Unix socket; the relay connects it to the vTPM.                                |
| 5   | `vfkit --bootloader linux,kernel=…,initrd=…,cmdline=…`                    | Boots the kernel with `ima_policy=tcb tpm_vsock.port=2321`.                                                                    |
| 6   | `docker context use vz-tpm`                                               | Docker talks to the guest through a local socket carried over vsock port 2375.                                                 |

The guest's console shows `tpm-vsock: TPM 2.0 at vsock 2:2321`, and `/dev/tpm0` and
`/dev/tpmrm0` exist in the VM.

<Alert variant="warning" title="The reset and the relay are load-bearing">
  Without the reset, a reboot reuses the vTPM's PCRs: PCR 8 and 9 are extended twice and the IMA
  log no longer replays to PCR 10. Quotes still *verify*, because the signature is fine and only
  the values are wrong, so verifiers must check values, not just signatures. If the relay is down
  at boot, the kernel retries for 10 seconds, then boots without a TPM and IMA runs in bypass mode.
  If it dies while the VM runs, TPM commands fail until it is back, and any measurement taken
  meanwhile is not extended. That is detectable, but the evidence for that boot is spoiled.
</Alert>

### Why a built-in driver

IMA chooses its TPM once, while the kernel initialises, before any program runs. A module, or
anything started from userspace or an initramfs, arrives too late and IMA stays in bypass mode
for good. `tpm_vsock` registers after the vsock transport is up and before IMA starts. Its socket
I/O runs on a kernel workqueue rather than on the task being measured: a signal to that task,
such as runc's init during a container start, would otherwise interrupt the transfer, and an IMA
extend that never reaches the vTPM leaves PCR 10 out of step with the log for the rest of the
boot. `05-verify.sh` counts such errors and fails if there were any.

## Build from a checkout

For developing, or for making a VM disk yourself. You need Apple silicon, macOS 26 or later,
8 GB of RAM or more (the VM uses 3 GB, a local kernel build 6 GB), Homebrew, the `docker` CLI,
and the notary and swtpm-notary installed as in the Colima tutorial's first steps. The notary's
Linux arm64 `.deb` is needed only when making the disk locally.

```sh
cd MACOS_DOCKER_VZ
./00-check.sh
./01-install.sh                    # vfkit, qemu (for qemu-img), Apple container
```

### 1. Build the guest kernel

```sh
./02-build-kernel.sh
```

About 6 minutes. It fetches Apple's kernel config, at a pinned `apple/containerization` commit,
and the kernel source it names. In an arm64 Ubuntu container it adds `tpm_vsock.c`, its Kconfig
entry and the config fragment, and checks the result, because `olddefconfig` silently drops
options whose dependencies are missing. The output is `build/vmlinux-tpmvsock`, uncompressed as
vfkit requires, plus an empty `build/empty.cpio`, since vfkit insists on an initrd.

### 2. Make the VM disk

From the CI image artifact, with its `.img.zst` and `.sha256` in the same directory:

```sh
./03-make-disk.sh ~/Downloads/eqty-vz-guest-ubuntu-26.04-arm64-v0.10.2-eqty.1.img.zst
```

The script verifies the checksum and expands the 20 GB sparse disk. Docker, the Docker API
bridge, the guest control service and the guest notary are already installed; cloud-init applies
the VM metadata on first boot. The guest mounts a separate sparse `docker-eqty.raw` at
`/var/lib/docker` and `/var/lib/containerd`, 64 GiB by default (`docker eqty settings set
DiskSizeMiB=…`), so replacing the system disk preserves Docker data.

Or from Ubuntu, in a few minutes:

```sh
./03-make-disk.sh
```

This downloads the Ubuntu 26.04 arm64 cloud image, converts it to a 20 GB raw disk, and boots it
**once with Ubuntu's own kernel** so cloud-init can install Docker, buildx, tpm2-tools, Python and
git. Install the guest notary afterwards with `./06-install-guest-notary.sh <deb>`. From then on
the VM always boots our kernel directly; the disk's own kernel and GRUB are never used again.

The system disk holds `/var/lib/eqty-notary`, including the guest notary's key blobs and
attestation state, cloud-init and machine identity, logs, and any changes made inside Ubuntu.
Keep both disk files when backing up or moving a VM. The image contains no pre-created notary
identity.

### 3. Start, verify, run

```sh
./04-start-vm.sh
./05-verify.sh
./07-run-simple-py.sh
./08-verify-chain.sh
```

`05-verify.sh` builds the `eqty-tpm2` image in the VM and checks, from a container, that the IAK
certificate chains to the notary root in the vTPM, that the root is this Mac's notary, that a
quote over PCR 8, 9 and 10 signed by the IAK verifies, and that a container without `--device`
has no TPM. From the guest's TPM and IMA log, it checks that PCR 8 and 9 equal what the Mac
measured before boot, that the kernel's IMA log replays exactly to PCR 10, and that
`boot_aggregate` is non-zero.

`07-run-simple-py.sh` and `08-verify-chain.sh` are the Colima tutorial's steps 8 and 9, with two
differences: IMA is already on, so there is no VM restart; and the chain check also confirms that
**PCR 9 in the guest notary's quote is the kernel this Mac launched**. A QEMU VM cannot make that
check, because there the kernel comes from the VM's own disk.

### Day to day

| Task                      | Command                                                                                                      |
| ------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Stop the VM               | `./09-stop-vm.sh`                                                                                            |
| Start it again            | `./04-start-vm.sh`, which resets and re-measures the vTPM                                                    |
| Back to Docker Desktop    | `docker context use desktop-linux`                                                                           |
| Remove the VM             | `./10-remove.sh`: deletes the disks, state and context; keeps the vTPM and `build/`. `--yes` skips the prompt |
| Remove it and its vTPM    | `./10-remove.sh --delete-vtpm`: also crypto-shreds the vTPM                                                  |
| Several VMs               | One vTPM per VM: `VZ_NAME=other VTPM_ID=other ./04-start-vm.sh`                                               |

## What it proves

A quote from the vTPM is signed by a key only this Mac's Secure Enclave can use, chaining to this
Mac's notary DID: the same as the Colima setup. This one adds two things:

- **The launch is host-attested.** PCR 9 is the kernel the Mac launched, and PCR 8 its command
  line. That holds only because vfkit boots our kernel directly; booted through GRUB or EFI, the
  disk would pick the kernel and PCR 8 and 9 would describe the host's intent, not what ran.
- **IMA is anchored from boot** by the VM's own kernel, so the IMA log replays exactly to PCR 10.

The limits are unchanged: the Mac's root of trust is vouched for only by the signed notary, not
by Apple; the manifest carries only the guest notary's own IMA entry, not the full log; and guest
root can use the TPM.

## Gotchas

**Kernel and boot**

- **The kernel is ours to maintain.** No distribution kernel has `tpm_vsock`. Kernel security
  updates mean rebuilding and bumping the pinned Apple commit. `apt upgrade` inside the VM updates
  a kernel that is never booted.
- **Docker's own kernel needs.** Swarm's ingress sandbox SNATs with `-m ipvs`, so without
  `CONFIG_NETFILTER_XT_MATCH_IPVS` dockerd logs `Failed to add firewall mark rule in sbox ingress`
  and published swarm ports never answer; dockerd sets the default VLAN on every overlay bridge,
  which needs `CONFIG_BRIDGE_VLAN_FILTERING`; and monitoring agents read `/proc/pressure`,
  which needs `CONFIG_PSI`. All three are in the fragment and the build script checks them.
- **The guest notary needs eBPF features Apple's config leaves out:** kprobes, syscall
  tracepoints, BPF events, the JIT and BTF, which needs debug info and `pahole`. The fragment adds
  them, and `bpf` to `CONFIG_LSM`. Without them the notary's observer cannot load and the notary
  keeps restarting; the SDK then reports `API response is missing public_key field`.
- **The notary's key guard is still skipped** in this guest; it is best-effort. On arm64,
  attaching BPF LSM programs probably also needs the function tracer, which Apple's config lacks.
- **The kernel has no modules.** Everything Docker needs is built in. Anything that expects to
  `modprobe` fails, and `systemctl is-system-running` reports `degraded` because `multipathd`
  cannot start. Harmless.
- **The VM boots straight onto `/dev/vda1`.** No initramfs, so the root filesystem must be ext4
  on the first partition, as in Ubuntu cloud images.

**Networking**

- **The VM needs a fixed MAC address.** vfkit gives a new random MAC on every boot unless one is
  set, and cloud-init writes the network config on the first boot matched to that MAC, so later
  boots would have no network. `common.sh` derives a fixed MAC from the VM's name.
- **No guest IP is used for control.** SSH runs over vsock. Connections from macOS to the VM's
  NAT address can be blocked by macOS's local-network privacy rules.
- **Built-in drivers created interfaces cloud-init picked over the virtio NIC** on a fresh disk,
  so the command line adds `dummy.numdummies=0 bonding.max_bonds=0 ifb.numifbs=0`.

**Guest notary**

- **Turn Key Guardian off before installing the package, not after.** The package starts the
  notary immediately. With the stock settings it asked the dev Key Guardian for an AK certificate,
  and got one, and then preferred it over the vTPM IAK's, so the manifest's chain ended at the Key
  Guardian instead of the Mac. `06-install-guest-notary.sh` writes the drop-in first and deletes
  any Key Guardian certificate it finds. Note also that the dev Key Guardian certified a TPM that
  has no vendor EK certificate, so its certificate does not by itself prove real hardware.

**Docker**

- **Images must be arm64.** The VM is arm64 unless Rosetta is attached; `simple-py` is built
  locally because its public image is amd64-only.
- Settings, directory sharing, published ports, `host.docker.internal` and inotify relaying are
  described on the [docker eqty](./docker-eqty.mdx) page.

**The Mac**

- **Memory.** The kernel build needs a 6 GB container, and the VM takes 3 GB. On an 8 GB Mac, run
  one at a time and quit other VM apps.

## Files

| File                                            | What it does                                                                                       |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `00-check.sh`                                   | Checks prerequisites                                                                               |
| `01-install.sh`                                 | vfkit, qemu (`qemu-img`), Apple `container`                                                        |
| `02-build-kernel.sh`                            | Builds `build/vmlinux-tpmvsock` and `build/empty.cpio`                                             |
| `03-make-disk.sh [image.img.zst] [--force]`     | Expands a release guest disk, or provisions Ubuntu locally                                         |
| `04-start-vm.sh`                                | Per boot: vTPM start, reset, launch measurement, relay, vfkit, local Docker socket and context     |
| `05-verify.sh`                                  | Container TPM checks; PCR 8 and 9 equal the launch; IMA replays to PCR 10                           |
| `06-install-guest-notary.sh <deb>`              | Guest notary in the VM                                                                             |
| `07-run-simple-py.sh`                           | `simple.py` from eqtylab/container_example in a container, manifest to `out/`                      |
| `08-verify-chain.sh`                            | The chain check, plus PCR 9 equals the launched kernel                                             |
| `09-stop-vm.sh`, `10-remove.sh`                 | Stop (TERM, then KILL after 10 seconds); remove the VM, and with `--delete-vtpm` its vTPM           |
| `common.sh`                                     | Names and paths (`VZ_NAME`, `VTPM_ID`; state in `~/.local/share/eqty-vz-tpm/<name>`)              |
| `kernel/`                                       | `tpm_vsock.c`, `config-fragment`, `build-in-container.sh`                                          |
| `host/`, `guest/`                               | Host vTPM helpers and the paired Docker vsock proxy service                                        |
| `samples/`                                      | The host manifest and the `simple.py` manifest from the validation run                             |