chroot.dev: an OpenBSD VM over ssh in under a second

ssh chroot.dev new -n web -w gives you an OpenBSD VM that answers ssh in about 600 ms. The whole interface is commands over ssh(1). It runs on my OpenBSD port to Firecracker, and it's open now as a beta, by invitation, with a 14-day trial.

The recording is real time against the live service. It creates a VM, starts httpd(8) in it, serves it over HTTPS, copies the running VM and removes both.

Why I wanted a disposable OpenBSD machine

Getting an OpenBSD machine today means a long-lived VM, a cloud image or QEMU on your own box. openbsd.amsterdam does the long-lived VM well, on OpenBSD's excellent vmm(4)/vmd(8), and if that is what you need, go there. I have VMs there and the service is very good.

What I kept missing while working on the port was a machine I could treat like a process: create it from a script, break it, copy it before the risky step, throw it away. With the kernel booting in ~30 ms, there was no reason for a new VM to take longer than the ssh handshake.

What a session looks like

$ ssh chroot.dev new -n web -w
web 10.201.0.6
ssh in 621 ms
$ ssh vm+web@chroot.run
web$ uname -a
OpenBSD web 8.0 MICROVM#10 amd64

You log in as puffy, in group wheel, with doas(1) and no password. Your account keys are installed at boot and root can't log in over ssh.

Each VM also gets https://NAME.chroot.run with a valid certificate. It is private by default: ssh chroot.dev browser prints a one-time link that logs your browser in. share picks the port behind the proxy (80 by default) and who gets in:

$ ssh chroot.dev share set-public web
$ curl https://web.chroot.run
hi g33ks =]

Every command accepts --json, and the same commands run over HTTPS with a scoped token, so a script never has to parse a table:

$ ssh chroot.dev ls --json | jq -r '.[].name'
web

Copying a running VM, memory included

You spent an hour getting a VM right: packages, configs, a service running. Now you want to try something that might break it, like a new pf.conf(5), pkg_add -u or a database migration. A disk snapshot gives you the files back, but the copy still has to boot and every service has to come up again.

That's why cp is the part I like most. A running VM is copied with its memory, so the copy resumes with the same processes instead of booting:

$ ssh chroot.dev cp web web2 -w
web2 10.201.0.10
ssh in 478 ms
$ ssh vm+web2@chroot.run pgrep -l httpd
53705 httpd
91719 httpd
8703 httpd
61260 httpd
76122 httpd

Nobody started httpd in web2. It came along in the memory snapshot. Break web2 as much as you want; web is still where you left it.

How new and cp are this fast

new doesn't boot anything. Each image has a Firecracker snapshot of a guest that already booted and is waiting for its identity. Creating a VM restores that snapshot with the VM's own tap device, writes the identity (hostname, network, host keys to generate, your ssh keys) into Firecracker's MMDS, and resumes it. A small agent in the guest reads MMDS and applies it. The disk is a btrfs subvolume snapshot of the image, about 20 ms.

cp pauses the source, takes a full snapshot of memory, device state and disks, and resumes the source. The copy is restored from that snapshot with a new identity in MMDS. The guest notices it was cloned through the VM generation ID counter (/dev/vmgenid), and the agent applies the new host key, hostname and address with the VM up, dropping the TCP connections it inherited from the source.

The path a connection takes:

you --ssh/https--> edge VPS, São Paulo --VPN--> host
                   forwards 22/80/443          lobby: ssh commands,
                   keeps the client IP         vm+NAME@ proxy, HTTPS proxy
                                               Firecracker microVMs

The edge only forwards. The lobby on the host takes the commands, proxies vm+NAME@chroot.run to the right VM and terminates HTTPS with a *.chroot.run certificate. Outbound traffic from the VMs leaves through the edge, never from my home connection.

What is rough, on purpose

After the beta

Three things are next, in no fixed order. Feedback from the beta decides which one comes first.

Getting an invitation

Invitations go out by hand, in small batches. Ask at contact@chroot.dev and you get a one-time code. The account starts on a 14-day trial; the plans are in billing(7). The manual starts at intro(1), the current state is at status.chroot.dev, and the channel is #chroot.dev on Libera.Chat.

If you try it, I want to hear what broke and what you expected new to do that it didn't.