Skip to content

feat(host): run Firecracker VMs through the jailer on root hosts - #434

Merged
kalaspuff merged 7 commits into
fctl/802-firecracker-hosts-package-caches-buildsfrom
fctl/802-firecracker-jailer
Nov 6, 2026
Merged

kalaspuff merged 7 commits into
fctl/802-firecracker-hosts-package-caches-buildsfrom
fctl/802-firecracker-jailer

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A host that runs as root now runs each Firecracker VM through Firecracker's jailer, so that a VM escape lands as a user of its own in a chroot rather than as the host's user, who can read the runner's token. Each VM gets a uid and gid of its own (from 1,900,000,000 up, picked under a lock so that no other running VM's jail has it), a chroot under firecracker/jail/, and a cgroup of its own (fctl/<VM key>, at most 256 processes):

  • What the jail holds. Hard links of the VM's disks (the images' filesystems readable by all) and of its kernel and initramfs (copies where they're private or on another filesystem, and links resolved first). Its writable disk is lent to the jail's user while it runs, noted beside the chroot where that user can't change the note, and given back to root as the VM stops, so a later jail with the same uid owns nothing of the host's; jails that a stopped or crashed host left go before the next VM starts.
  • How the host reaches it. The jail's user owns the chroot, so the host never goes through it: once Firecracker has made its API and vsock sockets there, the host opens each without following links, checks it's a socket, and hard-links that inode into a directory of root's beside the chroot, which the VM's socket path leads to. A jail can't send the host to another VM's sockets.
  • What it needs. The jailer comes with the pinned Firecracker, or sits beside the one host.toml names (as jailer or as the release names it). It needs cgroup v2 and a data directory on a filesystem that allows device files; without either, or without a jailer, the driver reports itself not ready with what to change. jailer = false in [firecracker] turns it off, and hosts that don't run as root are unchanged.

I verified it in Firecracker nested in a QEMU VM on aarch64: boots_a_sandbox as root passes with both Ubuntu 24.04's passt and Debian 13's, checks that Firecracker runs as a jail's user, and that the sandbox's disk and the images' filesystems are root's again once their VMs stop. CI's root step runs it jailed on x86_64, and runs the stale-jail test as root, where it lends and takes back a disk. Unit tests cover the jail's users, the jailer's arguments and where it's found, the chroot's links and copies, linking only the jail's own sockets, and removing stale jails. The docs (security, architecture, host.toml, ADR 0070's consequences) say what a jailed VM can reach.

Worth confirming

  • Decision: the jailer is on by default wherever the host runs as root; only jailer = false turns it off, and a root host without cgroup v2 must set it to run VMs at all.
  • Decision: the jails' users are bare uids and gids from 1,900,000,000 up, with no entries in /etc/passwd, chosen far from the ranges people, system users and user namespaces take.
  • Decision: passt stays outside the jail, as nobody (passt drops to it itself when started as root), rather than as the jail's user.
  • Assumption: a host runs as root by root installing the host service (its systemd user unit in root's manager, with lingering); nothing else here changes for that.
  • Follow-up: package caches (feat(host): share package caches with Firecracker sandboxes #430) and snapshots (feat(host): resume stopped Firecracker sandboxes where they were #431) don't know about jails yet: a jailed VM's Firecracker can't connect to a cache server's socket that root made, and a snapshot written inside the chroot goes with it when the VM stops. Whichever of these merges after the other needs that integration (or turns caches or snapshots off for jailed VMs).

Refs #345

fctl session


Warning

High risk. It changes how every Firecracker VM starts on hosts that run as root, on by default, and it chowns disks and creates uids, chroots, links and cgroups on the host, so a mistake could stop VMs from booting or weaken the isolation it sets out to add.

What it does. On hosts that run as root, each Firecracker VM now starts through Firecracker's jailer as its own uid and gid in a chroot and cgroup, so that a VM escape no longer lands as the host's user. The jailer comes with the pinned Firecracker or from beside a configured one, and jailer = false in [firecracker] turns it off. The host links the VM's sockets, after checking them, into a root-owned directory beside the chroot that the VM's socket directory leads to, hands writable disks back when a jail ends, picks uids under a lock, and removes stale jails. Since the last review, the stale-jail test also lends a disk to a jail uid when run as root, and CI runs it as root.

On by default. The jailer is on for every host running as root unless jailer = false; it needs cgroup v2 and a data directory not mounted nodev, and package caches and snapshots don't yet work with jailed VMs.

fctl review's first look at 6dca881 · 9 files, +856 −36 · Review agent settings

@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner November 6, 2026 21:31
@fctl-sh fctl-sh Bot changed the title feat(host): run Firecracker VMs through the jailer on hosts that run as root feat(host): run Firecracker VMs through the jailer on root hosts Nov 6, 2026
@fctl-review

This comment has been minimized.

…at the jailer needs

The jail's user owns its chroot, so the host now links Firecracker's sockets out of it by inode, each opened without following a link and checked to be a socket, rather than reaching them through it. Writable disks lent to a jail are noted beside the chroot and given back as the VM stops, and jails of VMs that don't run go before the next VM starts. A jail's uid is picked under a lock that other processes take too.

Kernels and initramfses are put in a jail through links to the files they name, and copied where they're private. The driver isn't ready without cgroup v2, on a nodev filesystem, or without a jailer beside a named Firecracker, which may be named as the release names it.
@fctl-review

This comment has been minimized.

fctl-sh Bot added 2 commits November 6, 2026 21:49
Hard links can't cross filesystems, and the host's socket directory is in /tmp: the links now go in a directory of root's beside the chroot, which the socket directory leads to. The root boot test checks that the sandbox's disk and the images' filesystems are the host's once their VMs stop.
@fctl-sh

fctl-sh Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

On the review's summary finding (a crashed unpack VM's jail and cgroup are never removed): fixed in d3cd28e. Before each VM starts (a sandbox's or an unpack VM's), the driver removes jails that no running VM has and that are older than ten minutes (older than any start): it gives back the disks their jail.json notes, removes the jail's directory (and with it its hard links and its uid's claim) and its cgroup. Test: stale_jails_go.

@kalaspuff
kalaspuff added this pull request to stack #435 November 6, 2026 23:30
@kalaspuff
kalaspuff merged commit 3127408 into main Nov 6, 2026
11 of 13 checks passed
@kalaspuff
kalaspuff deleted the fctl/802-firecracker-jailer branch November 6, 2026 23:32
fctl-sh Bot added a commit that referenced this pull request Nov 6, 2026
#429, this branch's base, was squash-merged into main with #434: the tree is main's with this pull request's own changes applied again, and docs/cli.md's Firecracker paragraph says both what the jailer needs and that the host builds images.
fctl-sh Bot added a commit that referenced this pull request Nov 6, 2026
… a jailed VM's caches in its jail

#429, this branch's base, was squash-merged into main with #434, the jailer: the tree is main's with this pull request's own changes applied again. A jailed VM's Firecracker connects to the cache server from its chroot, as the jail's user, so the server now listens there on a socket given to that user; CI's root step runs the caches test, jailed.
fctl-sh Bot added a commit that referenced this pull request Nov 6, 2026
…ate for jailed VMs

#429, this branch's base, was squash-merged into main with #434, the jailer: the tree is main's with this pull request's own changes applied again. A jailed Firecracker would write its state in its chroot, which goes as the VM stops, and a restore would need the jail made again around it, so a jailed VM stops without saving and boots from its disk, as before; a state saved before the host ran as root goes. The snapshot test runs without the jailer, and the root boot test checks that a jailed stop saves nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant