diff --git a/assets/layers/base.sh b/assets/layers/base.sh index 8ebc6bf0..472a1701 100755 --- a/assets/layers/base.sh +++ b/assets/layers/base.sh @@ -9,8 +9,9 @@ mise_sha256_amd64=6eb1b890e90818417ca34c90dbbd47881917d5cd199f31b63b062ea9c6b18d mise_sha256_arm64_musl=e036eb7bd3ca63e8565497e597967484330a74ff24e9c4c9f2ac41824cbf4090 mise_sha256_amd64_musl=fc5137a3147494e039c3d5fc3d84de354170d7d8dafdb0b5f0b6f3f19d1dd922 # apt_snapshot: the distribution's packages come from its archive as it was then (snapshot.ubuntu.com, -# snapshot.debian.org), so the same image key means the same packages. -apt_snapshot=20261009T000000Z +# snapshot.debian.org), so the same image key means the same packages. It moves with Ubuntu's container +# image (internal/ubuntu), which mustn't be newer. +apt_snapshot=20261026T000000Z export DEBIAN_FRONTEND=noninteractive # Alpine (--from alpine): apk, OpenRC and musl. Its packages come from the release's repositories, diff --git a/docs/content/docs/contributing.md b/docs/content/docs/contributing.md index 6e0e5d2d..51ae1b99 100644 --- a/docs/content/docs/contributing.md +++ b/docs/content/docs/contributing.md @@ -194,7 +194,7 @@ The sections so far: - `docker` (`--backend docker`): the [Docker backend](docker.md), with state under `/tmp/devvm-go-e2e-docker`, on an engine where only what has its sandbox's label is touched, and what hasn't must be as it was at the end. On a Linux engine of the machine's own (on Linux; on macOS in the docker host VM below, from a `devvm` built here for it, its results counted here): doctor, base and a fixture layer built by committing containers, the layer's build reaching the internet and the host's server on every address but not its loopback-only one, a rebuild, `images rm`, a failed script's container kept stopped; a project VM with its CPUs and memory, the folder read-write and what the VM writes yours (uid and gid), its home a volume of its own, the tools' volume read-only even for root, its hostname, no Docker, `devvm size`'s `disk_used`, stop and start keeping its disk; refused in one line, nothing made: network policy, the docker layer, a disk size; ssh for editors', ports' and agent forwarding's emulations ([their checks](design.md#ssh-for-editors-on-docker)): no port published and no sshd listening, pinned host keys of each VM's own, its own key alone, no forwarding out even past a hostile sshd, `devvm ssh` and `code`, `devvm _docker-connect` refusing another devvm's container, a VM started outside devvm without ssh, every port and listed ports through devvm's forwarder, never a port of this machine's programs (on its `127.0.0.1`, `::1` or every address) or another VM's, the agent in ssh sessions alone (a throwaway one standing for yours, devvm's, none), a `--clone` VM's push and fetch; an agent VM in a home of its own whose added and removed folders make its container again from a commit, its disk and home kept, the commit before deleted, rm deleting its commit and volumes; a node VM whose tools are linked from Docker's tools volume, read-only even for root. Then on Docker Desktop: doctor naming it and its file sharing, a build refused in one line with nothing made, base and the shared tools copied from the Linux engine's run (Desktop can't build yet; the same paths give them the same label), and the project, agent and node VMs' checks again, with `TestE2EExecQuoting` in `internal/backend/docker`; at the end everything with the sandbox's label is deleted. - `from`: run with a `docker` that isn't running, so nothing comes from Docker. A node+python+docker+claude VM from `node:24` (Debian 12, in a home of its own) boots, with its base keyed by the registry's digest, its node, python and claude at the locked versions, and the docker layer's Docker from Docker's Debian repository; a node+docker VM from `alpine:3` runs node and pnpm from musl tool images and the docker layer's Docker on OpenRC, with no crashed services; base builds from `ubuntu:26.04`; and the build VM and its temporary folders are gone. -base, the `--from` bases and the shared tool images stay cached between runs, except what a rebuild or gc deletes: every stale image in the sandbox (other selections' bases, whose features differ, among them) and every unused tool image (an earlier `from` run's musl ones); every other VM a run makes is deleted at its end, and its project folders are unlocked and deleted. Each check prints `[n/N]`, how long it took and the time left as the last complete run measured it, and a heartbeat every minute shows the latest output. A check a run has nothing for is counted as `SKIP`: base's features, with base cached. A run with fewer checks than the last complete one fails, as a section ended early. Checks look for devvm's messages with `devvm _msg`, never by their wording. +base, the `--from` bases and the shared tool images stay cached between runs, except what a rebuild or gc deletes: every stale image in the sandbox (other selections' bases, whose features differ, among them) and every unused tool image (an earlier `from` run's musl ones); every other VM a run makes is deleted at its end, and its project folders are unlocked and deleted. Each check prints `[n/N]`, how long it took and the time left as the last complete run measured it, and a heartbeat every minute shows the latest output. A check a run has nothing for is counted as `SKIP`: base's features, with base cached. A run with fewer checks than the last complete one of the same selection (and Docker engines) fails, as a section ended early. Checks look for devvm's messages with `devvm _msg`, never by their wording. [Testing on other hosts](testing.md) covers Linux hosts, x86_64 and the checks to run by hand. diff --git a/docs/content/docs/design.md b/docs/content/docs/design.md index 5c6377dd..1c464a22 100644 --- a/docs/content/docs/design.md +++ b/docs/content/docs/design.md @@ -11,8 +11,7 @@ A backend feature devvm builds from other parts of the backend ([emulated](backe ### Network policy on smolvm -**The guarantee:** as on Lima, a VM with network policy reaches nothing but its own proxy, even as root, and a refused DNS query never leaves the host, but for one narrow channel, a query for `devvm.invalid` (the DNS channel, under Not covered below). Reviewed: the threat check's findings are fixed or listed below, and the end-to-end checks prove the rest. Before that, devvm refused it, and a test build's `DEVVM_UNREVIEWED` let the end-to-end checks through ([testing](testing.md#unreviewed-emulations)). - +**The guarantee:** as on Lima, a VM with network policy reaches nothing but its own proxy, even as root, and a refused DNS query never leaves the host, but for one narrow channel, a query for `devvm.invalid` (the DNS channel, under Not covered below). Reviewed: the threat check's findings are fixed or listed below, and the end-to-end checks prove the rest. **What it's built from**, all set by `Start` while the machine is stopped: - **An allow list of the gateway alone** (`--reset-allow-list --allow-cidr 100.96.0.1/32`): smolvm refuses TCP to any other address, IPv6 included, and UDP but DNS. The gateway is every port of the host's loopback, so the allow list alone isn't enough. @@ -44,12 +43,11 @@ A backend feature devvm builds from other parts of the backend ([emulated](backe ### ssh for editors on smolvm -**The guarantee:** as on Lima, ssh and editors reach a smolvm VM by name, that VM alone (host keys of its own, read through smolvm and pinned), only as the VM's user and only with that VM's own key; and an ssh session devvm's entry makes gives the VM no way out it doesn't already have (with network policy, nothing past its proxy), whatever the VM runs as sshd: the host's ssh asks for nothing that would carry it, and the entry pins the options that could. Reviewed, in two rounds: the threat check's findings are fixed or listed below (the entry's options, a key per VM, no host keys read before sshd runs, ports that never collide, an image without sshd), and the end-to-end checks prove the rest. Before that, devvm refused it, and a test build's `DEVVM_UNREVIEWED` let the end-to-end checks through ([testing](testing.md#unreviewed-emulations)). - +**The guarantee:** as on Lima, ssh and editors reach a smolvm VM by name, that VM alone (host keys of its own, read through smolvm and pinned), only as the VM's user and only with that VM's own key; and an ssh session devvm's entry makes gives the VM no way out it doesn't already have (with network policy, nothing past its proxy), whatever the VM runs as sshd: the host's ssh asks for nothing that would carry it, and the entry pins the options that could. Reviewed, in two rounds: the threat check's findings are fixed or listed below (the entry's options, a key per VM, no host keys read before sshd runs, ports that never collide, an image without sshd), and the end-to-end checks prove the rest. **What it's built from:** - **sshd in base:** `sshd.sh`, as root after base's scripts, installs `openssh-server` from the archive they left (Ubuntu's snapshot: from the live archive, before them, its systemd libraries were newer than the snapshot's packages layers install, Docker's, could match), keeps the snapshot's package lists for layers, and deletes the host keys its package made; `prepare.sh` sets the user's password to `*` (none matches; sshd without PAM refuses a locked `!` account's keys too). Both are in base's key. -- **Only when asked for:** the caller sets `Confinement.SSH` at each start of a project VM when `Require` lets `ssh` through (always, now it's reviewed); builds never ask. Without it the start removes the forward and runs no sshd, `SSH` answers `vm_no_ssh`, and the ssh config skips any backend whose `ssh` isn't usable (`Review.Allowed`). +- **Only when asked for:** the caller sets `Confinement.SSH` at each start of a project VM when `Require` lets `ssh` through (always: it's reviewed); builds never ask. Without it the start removes the forward and runs no sshd, `SSH` answers `vm_no_ssh`, and the ssh config skips any backend whose `ssh` isn't usable (`Review.Allowed`). - **The forward:** `machine update -p PORT:22` while the machine is stopped. `PORT` is `Confinement.SSHPort` (network policy's `ssh_port`), else the one it had while it's free on `127.0.0.1` and `::1`, else a new one, never one of the VM's own forwards: network policy's `ssh_port` avoids every VM's forwards and is picked again when it's one of the VM's, and the backend refuses one that is anyway (`smolvm_ssh_port_forwarded`). smolvm binds it on the host's loopback alone, and forwards reach only servers on all addresses, so sshd listens on `0.0.0.0:22` (IPv4). smolvm forwards at most 64 ports per machine, so a VM's own are at most 63, and port 22 is refused (`smolvm_port_ssh`). - **sshd, after each start** (`services.sh`, as root): every host key deleted and a new ed25519 one made, so no two VMs from one pack share one, nor a VM's starts; devvm's public key as the only authorized key (`/etc/devvm/ssh/authorized_keys`, root's); a config of devvm's own (`/etc/devvm/ssh/sshd_config`, mode 600, `sshd -f`, checked with `sshd -t` first), whatever the image's says: `AllowUsers` the VM's user, `PermitRootLogin no`, `AuthenticationMethods publickey`, passwords and keyboard-interactive off, `AllowTcpForwarding local`, `AllowStreamLocalForwarding local`, `PermitListen none`, `GatewayPorts no`, `X11Forwarding no`, `PermitTunnel no`, `PermitUserEnvironment no`, `AllowAgentForwarding yes`; it listens on IPv4 alone (`ListenAddress 0.0.0.0:22`) and connects local forwards to IPv4 or IPv6 (`AddressFamily any`, for [every port](#every-port-on-smolvm)'s servers on `::1`). A failure stops the VM, but an image without sshd (made before devvm installed one; asked first, with a probe of its own, so no other failure reads as it) starts without ssh, warned (`vm_no_sshd`; a VM made after `devvm rebuild` has it). The record says the start's sshd runs (`ssh_up`, cleared before each start, set once `services.sh` is done), and `SSH` answers only then: a devvm that runs meanwhile can't read, and pin, the host keys this start is about to replace. - **The sessions' environment:** sshd on its own config runs without PAM, so `SetEnv` gives sessions `/etc/environment` (`BASH_ENV`) and the variables `Start` names (the proxy's, `NO_PROXY`, the CA files'), whose values `services.sh` reads from its own environment: the proxy file's (`--secret-file`) and the machine's, never in arguments. Login shells also read `/etc/profile.d`, as devvm's do. @@ -91,12 +89,11 @@ These settings guard against the host's ssh asking for a forward that devvm's en ### Every port on smolvm -**The guarantee:** as on Lima, a VM that forwards every port has each TCP port a server in it listens on, on its loopback or all its addresses, forwarded to the same port on the host's loopback, and only its loopback; and, beyond Lima, never a port a program on the host has on any address when the forward is made, nor one devvm records for a VM. Forwarding gives the VM no way out it doesn't already have (with network policy, nothing past its proxy): every connection starts on the host. Reviewed: the threat check's findings are fixed or listed below (the host key read capped, reports paced, the log limited), and the end-to-end checks prove the rest. Before that, devvm refused it, and a test build's `DEVVM_UNREVIEWED` let the end-to-end checks through ([testing](testing.md#unreviewed-emulations)). - +**The guarantee:** as on Lima, a VM that forwards every port has each TCP port a server in it listens on, on its loopback or all its addresses, forwarded to the same port on the host's loopback, and only its loopback; and, beyond Lima, never a port a program on the host has on any address when the forward is made, nor one devvm records for a VM. Forwarding gives the VM no way out it doesn't already have (with network policy, nothing past its proxy): every connection starts on the host. Reviewed: the threat check's findings are fixed or listed below (the host key read capped, reports paced, the log limited), and the end-to-end checks prove the rest. **What it's built from:** - **None of smolvm's forwards:** a VM forwarding every port is made (or set, while stopped) with no `-p` but its ssh's. smolvm's would need each port at create or update, while the machine is stopped, at most 64 of them, and reach only servers on all addresses. -- **Only when allowed:** the caller requires `ports` and `ports-all` when the VM is made or its ports set (`Review.Require`, warned when let through), and again at each start (`Review.Allowed`, else the refusal): a VM made while it was let through doesn't start once it isn't (it always is, now it's reviewed). The backend then runs a forwarder at each start of a VM whose record says every port (`ports_all`). +- **Only when allowed:** the caller requires `ports` and `ports-all` when the VM is made or its ports set (`Review.Require`, warned when let through), and again at each start (`Review.Allowed`, else the refusal): a VM made while it was let through doesn't start once it isn't (it always is: it's reviewed). The backend then runs a forwarder at each start of a VM whose record says every port (`ports_all`). - **A forwarder per VM, on the host:** `devvm _smolvm-ports` (the forwarder is `vmssh.Forwarder`, which [Docker's ports](#ports-on-docker) use too), started detached by `Start` once `services.sh` ran the VM's sshd ([ssh](#ssh-for-editors-on-smolvm)), after stopping any it had (a pid file, checked against the process's arguments, as the proxy's is). `Start` waits up to 10 s for it to say it forwards; one that doesn't is warned about (`ports_forward_failed`, its log named) and left to keep trying, and the VM runs on. A VM without ssh forwards nothing, warned (`ports_no_ssh`). It ends when the machine's process does (its lifeline, `agent.pid`, the proxy's too: its process gone, or its contents changed by a new start), and `stop` and `Delete` stop it first. - **Reaching the VM:** one ssh connection, a master (`ssh -F none -M -S `), to the VM's sshd's host loopback port, as the VM's user with the VM's own key alone (`IdentitiesOnly`, `IdentityAgent=none`), its host key read through smolvm (`machine exec … cat /etc/ssh/ssh_host_ed25519_key.pub`, as root, at the start; at most 64 KiB of it, for 30 s, as the VM decides what it prints) into a known_hosts file of the forwarder's own and pinned (`HostKeyAlias`, `StrictHostKeyChecking yes`); no configuration of the user's, and nothing forwarded either way (`ClearAllForwardings`, `PermitRemoteOpen none`, no agent, X11 or tunnel, `ProxyCommand none`). Its control socket is in `~/.local/share/devvm/run` (mode 700), named by a hash of the VM's name, as a socket's path is at most 104 characters. A lost connection is made again every 2 s while the lifeline holds, its forwards closed meanwhile. - **What listens:** the master's session runs `ports.sh` (`sh -s`, as the VM's user), which prints the local addresses of the VM's listening TCP sockets (`/proc/net/tcp` and `tcp6`, state `0A`) whenever they change, and every 10 s regardless, so it ends soon after the connection does. The forwarder reads it as untrusted: lines over 128 bytes or a report over 4096 lines end the connection, anything that isn't a hex address and port is skipped, and reports are applied 500 ms apart at least (one that comes sooner waits, and the VM's ssh channel with it), so a VM can't make it bind, dial and read devvm's state at its own pace. Its log, which the VM can make it write to (ports coming and going, the session's stderr), takes 200 writes at once and then one every 10 s, each at most 512 bytes, control characters shown as `?`; a start empties it once it's over 1 MiB. A port's connections go to `127.0.0.1` for a server on all IPv4 addresses or that one, `::1` for one on all IPv6 addresses or that one, another `127.x` address for one there alone; servers on other addresses alone aren't forwarded. @@ -131,8 +128,7 @@ These settings guard against the host's ssh asking for a forward that devvm's en ### SSH agent toggling on smolvm -**The guarantee:** as on Lima, `devvm ssh-agent on`, `devvm` or `off` changes an existing VM's agent from its next start, and every start devvm makes (a launch, `restart`, an export's, `rm`'s check of a `--clone` VM) gives the VM only the agent its choice names: with `devvm`, devvm's own and never yours; with `off`, no agent at all, so the VM, root included, lists no keys, adds none and signs nothing, and reaches no agent of anyone's through smolvm's. A VM started some other way, which may have an agent devvm didn't choose, is stopped when devvm next finds it running. Reviewed: the threat check's one finding, a VM you start yourself, is fixed that way (the lifeline check below); the rest is listed below, and the end-to-end checks prove it. Before that, devvm refused it, and a test build's `DEVVM_UNREVIEWED` let the end-to-end checks through ([testing](testing.md#unreviewed-emulations)). - +**The guarantee:** as on Lima, `devvm ssh-agent on`, `devvm` or `off` changes an existing VM's agent from its next start, and every start devvm makes (a launch, `restart`, an export's, `rm`'s check of a `--clone` VM) gives the VM only the agent its choice names: with `devvm`, devvm's own and never yours; with `off`, no agent at all, so the VM, root included, lists no keys, adds none and signs nothing, and reaches no agent of anyone's through smolvm's. A VM started some other way, which may have an agent devvm didn't choose, is stopped when devvm next finds it running. Reviewed: the threat check's one finding, a VM you start yourself, is fixed that way (the lifeline check below); the rest is listed below, and the end-to-end checks prove it. **What it's built from:** - **Forwarding from the start:** smolvm sets forwarding only at `machine create --ssh-agent` (`machine update` has no option for it). A VM made while `agent-toggle` is let through (`VMSpec.AgentToggle`, from `Review.Require`, warned when unreviewed) is made with it whatever its choice, and its state records that it relies on the emulation (`agent_toggle=on`). The backend's record keeps both: made forwarding (`forwarding`), and the choice being none (`agent_off`), which `SetAgentForwarding` sets on a stopped VM; `Inspect` reports forwarding only when made so and not off. @@ -140,7 +136,7 @@ These settings guard against the host's ssh asking for a forward that devvm's en - **None is a path, not an agent:** `/dev/null` is a device, not a folder, so nothing, root included, can make a socket below it, and no process listens for it. An empty agent of devvm's would hold nothing too, but every VM set to none would share it: a VM could add a key there for another to use, lock it, or have devvm's process sign for keys it put in. With a path, there's nothing to add to, sign with, or share. - **The lifeline check:** after each start, `Start` records the machine's lifeline (`agent.pid`: its process and start time) in the record (`started`; with network policy, `confined` too). `AgentUnchosen` (`backend.AgentStarter`, which Lima doesn't implement: its agent is the VM's config) says a running VM made forwarding may have an agent devvm didn't choose when the lifeline differs or its process is gone. A launch (devvm, `ssh`, `code`, after network policy's self-check, which says more for a VM with it) and an export's or `rm`'s start of a VM it finds running stop it then (`agent_unchosen_stop`, stopped even when interrupted), unless its choice is `on`: your agent is what it'd get anyway. The next devvm starts it as chosen. - **The entry and devvm's connections follow the start,** as on every backend ([Docker's](#ssh-agent-forwarding-on-docker)): a choice changed while the VM runs reaches neither until its next start, as with smolvm's own agent. Here a start is told apart by its lifeline. -- **Only when allowed:** a VM made ready for it (`agent_toggle=on`) doesn't start once the toggle isn't let through (`Review.Allowed`, else the refusal), as with every port (it always is, now it's reviewed). One made without forwarding (by a devvm before it) is refused when turned on (`agent_fixed`), before its state changes. +- **Only when allowed:** a VM made ready for it (`agent_toggle=on`) doesn't start once the toggle isn't let through (`Review.Allowed`, else the refusal), as with every port (it always is: it's reviewed). One made without forwarding (while the toggle wasn't let through) is refused when turned on (`agent_fixed`), before its state changes. **What it relies on:** smolvm reading `SSH_AUTH_SOCK` only at `machine start` and keeping the path for that run, its host side connecting to that path and nothing else, whatever the VM sends; `machine exec` not starting a stopped machine (checked: it fails); the kernel refusing a path below a device; smolvm writing a new `agent.pid` at each start, which the VM can't write; devvm's state and records being on the host, out of the VM's reach (`~/.local/share/devvm`, never mounted). @@ -148,7 +144,7 @@ These settings guard against the host's ssh asking for a forward that devvm's en **Not covered:** -- **Starting the VM yourself, until devvm next looks:** `smolvm machine start --name devvm-…` from your shell (or any smolvm command of yours that starts it) gives a VM made with forwarding the agent your shell names, whatever its choice (checked), and it keeps it until devvm, `ssh`, `code`, an export or `rm` finds it running and stops it; `devvm ls`, a shell or editor you opened before, or nothing at all don't. Before this emulation, a VM set to off was made without forwarding and got no agent however it was started. Only you (or a program of yours on the host) can do it, not the VM. +- **Starting the VM yourself, until devvm next looks:** `smolvm machine start --name devvm-…` from your shell (or any smolvm command of yours that starts it) gives a VM made with forwarding the agent your shell names, whatever its choice (checked), and it keeps it until devvm, `ssh`, `code`, an export or `rm` finds it running and stops it; `devvm ls`, a shell or editor you opened before, or nothing at all don't. Only you (or a program of yours on the host) can do it, not the VM. - The VM has smolvm's agent socket while it runs, and an agent it's given is reachable for that whole time, not only while you're connected (smolvm's native forwarding, with `on` or `devvm`). With `devvm`, the VM can add keys of its own to devvm's agent, remove or lock its keys, as with any forwarded agent; every VM set to `devvm` shares it. - Linux hosts are untested. diff --git a/docs/content/docs/docker.md b/docs/content/docs/docker.md index d81e6fb5..c17e82f2 100644 --- a/docs/content/docs/docker.md +++ b/docs/content/docs/docker.md @@ -50,7 +50,7 @@ Docker's engine is yours (Docker Desktop's especially), so: ## Building images -- `base` is a container from Ubuntu's container image (`ubuntu:26.04`), by the digest its registry has at the time, which its record keeps; with `--from`, from that image by its recorded digest, which may be one only Docker has. Each layer is a container from its parent's image. Each image is the container committed (`docker commit`), its layers shared with its parent's. +- `base` is a container from Ubuntu's container image (`ubuntu:26.04`), by the digest devvm pins with base's package snapshot (`ContainerDigest` in `internal/ubuntu/ubuntu.go`), which is in base's key and its record; with `--from`, from that image by its recorded digest, which may be one only Docker has. Each layer is a container from its parent's image. Each image is the container committed (`docker commit`), its layers shared with its parent's. - Before `assets/layers/base.sh`, devvm adds what Ubuntu's cloud image has and a container lacks: `sudo`, CA certificates, `bash` (on Alpine, OpenRC and ssh's client too) and the VM's user, and after base's scripts `sshd` (without host keys), as on [smolvm](smolvm.md#building-images): the same scripts, in `base`'s key. The user has your name and uid, and on Linux your group's id too, so the files it makes in the project folder are yours; home is `/home/.guest`. - The scripts run as that user, with stand-ins for `systemctl` and `rc-update` while they run: containers run no init system. - Base's CPUs and memory are `base.yaml`'s: 4 CPUs, 8 GiB (half the engine's memory on a small one). diff --git a/docs/content/docs/images.md b/docs/content/docs/images.md index 9cccf799..5ea81da1 100644 --- a/docs/content/docs/images.md +++ b/docs/content/docs/images.md @@ -124,7 +124,7 @@ Images are built in layers and cached, like Docker's. `base` comes first, and ea | Image | Its key hashes | | --- | --- | -| `base` | the backend, `assets/base.yaml`, `assets/layers/base.sh`, the chosen features in order (each name and its script), its rebuild counter, and with `--from`, the image, its digest and the scripts that convert it | +| `base` | the backend, `assets/base.yaml`, `assets/layers/base.sh`, the chosen features in order (each name and its script), its rebuild counter, and with `--from`, the image, its digest and the scripts that convert it; on smolvm and Docker, their scripts for containers and Ubuntu's container image, pinned by digest | | a built-in layer | its parent's key, its name, its script (`assets/layers/.sh`) and its rebuild counter | | a custom layer | its parent's key, its name, its script (`~/.config/devvm/layers/.sh`) and its rebuild counter | diff --git a/docs/content/docs/maintaining.md b/docs/content/docs/maintaining.md index 0a8199e6..7e9c043e 100644 --- a/docs/content/docs/maintaining.md +++ b/docs/content/docs/maintaining.md @@ -7,8 +7,8 @@ For maintainers: version bumps and releases. Run the scripts with mise, which pu ## Updating pinned versions -- `scripts/bump.sh --check` lists every pin against upstream; `scripts/bump.sh [tool...]` rewrites the pins (all tools by default) and prints a summary for the commit message. It writes a value only if it has the shape of a pin (a version, a 64-hex checksum, a commit), since some of the edited files run on the host, and edits nothing unless every value is good. It needs `curl` and `jq`. -- The tools: `apt`, `docker`, `mise`, `rustup`, `crane`, `omb`, `eza`, `tealdeer`. `apt` moves `apt_snapshot` (base's packages) to today; `docker` moves Docker's packages (`assets/layers/docker.sh`), read from its repository for base's Ubuntu release, and its signing key. Packages added to `assets/layers/base.sh` or `assets/features/` need no pin of their own: the snapshot covers them. +- `scripts/bump.sh --check` lists every pin against upstream; `scripts/bump.sh [tool...]` rewrites the pins (all tools by default) and prints a summary for the commit message. It writes a value only if it has the shape of a pin (a version, a 64-hex checksum, an image digest, a commit), since some of the edited files run on the host, and edits nothing unless every value is good. It needs `curl` and `jq`. +- The tools: `apt`, `docker`, `mise`, `rustup`, `crane`, `omb`, `eza`, `tealdeer`. `apt` moves `apt_snapshot` (base's packages) to today, and with it the digest of Ubuntu's container image smolvm's and Docker's `base` start from (`ContainerDigest` in `internal/ubuntu/ubuntu.go`); it refuses an image built after the snapshot, whose packages would be newer than the snapshot's (try the next day); `docker` moves Docker's packages (`assets/layers/docker.sh`), read from its repository for base's Ubuntu release, and its signing key. Packages added to `assets/layers/base.sh` or `assets/features/` need no pin of their own: the snapshot covers them. - `mise` moves base's mise (`assets/layers/base.sh`) and devvm's host mise (`internal/tools/mise.go`) together: the host one writes the lock base's installs from. - The shared tools aren't pinned: holds go in `assets/shared-tools/mise.toml` (`node = "24"` stays on that major). `testdata/mise.lock` is a fixed lock for the tests. - `assets/layers/ubuntu-cloud.gpg` is Ubuntu's cloud image signing key (fingerprint `D2EB44626FDDC30B513D5BB71A5D6C4C7DB87C81`), from keyserver.ubuntu.com. If Ubuntu changes it, base builds stop with `ubuntu_bad_signature`: fetch the new key, check its fingerprint against Ubuntu's announcement, and replace the file (`gpg --export FPR`). diff --git a/docs/content/docs/smolvm.md b/docs/content/docs/smolvm.md index f0f0ca7e..97fc6e27 100644 --- a/docs/content/docs/smolvm.md +++ b/docs/content/docs/smolvm.md @@ -28,7 +28,7 @@ Images aren't machines: each is a pack (`smolvm pack create --from-vm`) in `~/.l ## Building images -- `base` starts from Ubuntu's container image (`ubuntu:26.04`), by the digest its registry has at the time, which its record keeps. With `--from`, from that image by its recorded digest; an image only Docker has is refused (`smolvm_from_registry_only`). +- `base` starts from Ubuntu's container image (`ubuntu:26.04`), by the digest devvm pins with base's package snapshot (`ContainerDigest` in `internal/ubuntu/ubuntu.go`), which is in base's key and its record. With `--from`, from that image by its recorded digest; an image only Docker has is refused (`smolvm_from_registry_only`). - Before `assets/layers/base.sh`, devvm adds what Ubuntu's cloud image has and a container lacks: `sudo`, CA certificates, `bash` (on Alpine, OpenRC and ssh's client too) and the VM's user, and after base's scripts `sshd` (without host keys: each VM makes its own). It's your user name and uid, as on Lima, with its home at `/home/.guest`: the project folder shows as your uid's, and only that user can write it. It has no password that works (`*`). - The scripts run as that user, with stand-ins for `systemctl` and `rc-update` while they run: base's services are enabled the Lima way, and devvm starts them itself (below). The stand-ins are gone before the image is packed. - Builds use smolvm's default network: the internet, not the host's loopback. A pack keeps its build machine's network, CPUs and memory, so devvm sets all three on every VM it makes. diff --git a/internal/backend/backend.go b/internal/backend/backend.go index 4e9c6305..4438259b 100644 --- a/internal/backend/backend.go +++ b/internal/backend/backend.go @@ -110,8 +110,8 @@ type Backend interface { } // KeyFiles is a backend that puts files of its own into base (scripts it -// runs before devvm's), which base's key hashes too: by name, their -// contents. A backend that puts nothing in doesn't implement it. +// runs before devvm's, the image it starts from), which base's key hashes +// too: by name, their contents. A backend that puts nothing in doesn't implement it. type KeyFiles interface { KeyFiles() map[string][]byte } diff --git a/internal/backend/docker/build.go b/internal/backend/docker/build.go index fd9699f0..f76bfffb 100644 --- a/internal/backend/docker/build.go +++ b/internal/backend/docker/build.go @@ -19,12 +19,8 @@ import ( "github.com/w3cj/devvm/internal/ubuntu" ) -// UbuntuImage is the container image base starts from without --from: -// Ubuntu's, of the release Lima's base has. -const UbuntuImage = "docker.io/library/ubuntu:" + ubuntu.Version - // BuildImage builds an image: a container made from its parent's image, -// or for base from Ubuntu's container image (or spec.From's, which Docker +// or for base from Ubuntu's pinned container image (or spec.From's, which Docker // has or pulls), by its digest, prepared as Lima's cloud image comes // (prepare.sh: sudo, CA certificates, the VM's user; after its scripts, // sshd.sh: sshd, without host keys). It mounts nothing from the host and @@ -184,7 +180,7 @@ func (d *Docker) runBuild(ctx context.Context, inst string, spec backend.ImageSp // baseImage is the container image base starts from, pulled when it's a // registry's, and what its record says it started from: spec's (as // recorded: a registry digest, or Docker's own ID for an image only Docker -// has), else Ubuntu's, looked up now. +// has), else Ubuntu's, pinned. func (d *Docker) baseImage(ctx context.Context, f *backend.From) (ref, origin string, err error) { if f != nil { if f.Digest == "" { @@ -202,20 +198,7 @@ func (d *Docker) baseImage(ctx context.Context, f *backend.From) (ref, origin st } return f.Digest, f.Digest, d.pull(ctx, f.Digest) } - digest, err := d.Digest(ctx, UbuntuImage) - switch { - case errors.Is(err, from.ErrUnreachable): - return "", "", msg.FromUnreachable(UbuntuImage, from.ParseRef(UbuntuImage).Host) - case errors.Is(err, from.ErrNotFound): - return "", "", msg.FromNotFound(UbuntuImage, from.ParseRef(UbuntuImage).Host) - case err != nil: - return "", "", err - } - if !from.Valid(digest) { - return "", "", msg.BadFrom(msg.Shown(digest)) - } - ref = strings.TrimSuffix(UbuntuImage, ":"+ubuntu.Version) + "@" + digest - return ref, UbuntuImage + "@" + digest, d.pull(ctx, ref) + return ubuntu.ContainerRef, ubuntu.ContainerOrigin, d.pull(ctx, ubuntu.ContainerRef) } // rootScript runs one of the scripts devvm runs in images as containers diff --git a/internal/backend/docker/docker.go b/internal/backend/docker/docker.go index c46e7d21..50942ff7 100644 --- a/internal/backend/docker/docker.go +++ b/internal/backend/docker/docker.go @@ -42,10 +42,10 @@ import ( "github.com/w3cj/devvm/internal/backend" "github.com/w3cj/devvm/internal/backend/vmssh" - "github.com/w3cj/devvm/internal/from" "github.com/w3cj/devvm/internal/msg" "github.com/w3cj/devvm/internal/paths" "github.com/w3cj/devvm/internal/state" + "github.com/w3cj/devvm/internal/ubuntu" ) // Name is the backend's name. @@ -104,9 +104,6 @@ type Docker struct { // Hostname is the host's name, which a Docker engine on this machine // has too. Hostname func() (string, error) - // Digest looks up a container image's digest (sha256:…) in its - // registry: Ubuntu's, for base. - Digest func(ctx context.Context, ref string) (string, error) // Terminal reports whether devvm's input is a terminal (a shell gets // one then). Terminal func() bool @@ -166,7 +163,7 @@ func New(d paths.Dirs, assets fs.FS, u UI) *Docker { self, _ := os.Executable() return &Docker{ client: client{Runner: logRunner{u.LoggedCmd}, names: names{Data: d.Data}}, Dirs: d, OS: runtime.GOOS, Arch: runtime.GOARCH, Assets: assets, - User: user.Current, Hostname: os.Hostname, Digest: from.NewRegistry().Digest, + User: user.Current, Hostname: os.Hostname, Terminal: u.StdinIsTerminal, SharingFile: sharing, Self: self, Getenv: os.Getenv, LookPath: exec.LookPath, Forwards: newForwards(d, self), Info: u.Info, Warn: u.Warn, @@ -210,9 +207,10 @@ func (d *Docker) NameMax() int { return 0 } func (d *Docker) script(name string) ([]byte, error) { return fs.ReadFile(d.Assets, name) } // KeyFiles are the scripts base's containers run that go into base, which -// smolvm's machines run too; one missing is hashed as empty. +// smolvm's machines run too, one missing hashed as empty, and Ubuntu's +// pinned image. func (d *Docker) KeyFiles() map[string][]byte { - files := map[string][]byte{} + files := map[string][]byte{"ubuntu-image": []byte(ubuntu.ContainerRef)} for _, n := range []string{"container/prepare.sh", "container/shims.sh", "container/sshd.sh"} { files[n], _ = d.script(n) } diff --git a/internal/backend/docker/docker_test.go b/internal/backend/docker/docker_test.go index 138f896d..fd75538e 100644 --- a/internal/backend/docker/docker_test.go +++ b/internal/backend/docker/docker_test.go @@ -17,6 +17,7 @@ import ( "github.com/w3cj/devvm/internal/backend/vmssh" "github.com/w3cj/devvm/internal/msg" "github.com/w3cj/devvm/internal/paths" + "github.com/w3cj/devvm/internal/ubuntu" ) // execRunner runs the commands as they are: here, the docker stub. @@ -59,9 +60,6 @@ func newSandbox(t *testing.T) *sandbox { client: client{Runner: execRunner{}, names: names{Data: d.Data}}, Dirs: d, OS: "linux", Arch: "arm64", Assets: assets.FS, User: func() (*user.User, error) { return &user.User{Username: "u", Uid: "501", Gid: "1000"}, nil }, Hostname: func() (string, error) { return "stub-host", nil }, - Digest: func(context.Context, string) (string, error) { - return "sha256:" + strings.Repeat("ab", 32), nil - }, Terminal: func() bool { return false }, Self: "/devvm", Getenv: func(string) string { return "" }, LookPath: func(c string) (string, error) { return "/bin/" + c, nil }, @@ -334,8 +332,8 @@ func TestBuildBase(t *testing.T) { if err != nil { t.Fatal(err) } - pinned := "docker.io/library/ubuntu@sha256:" + strings.Repeat("ab", 32) - if built.Origin != UbuntuImage+"@sha256:"+strings.Repeat("ab", 32) || built.Libc != "gnu" { + pinned := "docker.io/library/ubuntu@" + ubuntu.ContainerDigest + if built.Origin != "docker.io/library/ubuntu:26.04@"+ubuntu.ContainerDigest || built.Libc != "gnu" { t.Errorf("Built = %+v", built) } inst := s.buildName(baseKey) diff --git a/internal/backend/smolvm/build.go b/internal/backend/smolvm/build.go index d4a89700..ebae94e0 100644 --- a/internal/backend/smolvm/build.go +++ b/internal/backend/smolvm/build.go @@ -22,16 +22,12 @@ import ( "github.com/w3cj/devvm/internal/ubuntu" ) -// UbuntuImage is the container image base starts from without --from: -// Ubuntu's, of the release Lima's base has. -const UbuntuImage = "docker.io/library/ubuntu:" + ubuntu.Version - // dockerDir is a folder on a machine's own disk, not its overlay root, // which Docker's storage needs. const dockerDir = "/var/lib/docker" // BuildImage builds an image's pack. Base is a machine made from Ubuntu's -// container image (or spec.From's), by its digest, prepared as Lima's cloud +// pinned container image (or spec.From's), by its digest, prepared as Lima's cloud // image comes (prepare.sh: sudo, CA certificates, the VM's user; after its // scripts, sshd.sh: sshd, without host keys); a layer // a machine made from its parent's pack. Neither mounts anything from the @@ -105,7 +101,7 @@ func (s *Smolvm) BuildImage(ctx context.Context, spec backend.ImageSpec) (backen } step := msg.CloningImage(image.Parent(spec.Image)) if spec.Parent == "" { - ref, origin, err := s.baseImage(ctx, spec.From) + ref, origin, err := s.baseImage(spec.From) if err != nil { return backend.Built{}, err } @@ -176,9 +172,8 @@ func (s *Smolvm) BuildImage(ctx context.Context, spec backend.ImageSpec) (backen // baseImage is the container image base starts from, by digest, and what // its record says it started from: spec's (as recorded), else Ubuntu's, -// looked up now. One only Docker has is refused: smolvm pulls from -// registries. -func (s *Smolvm) baseImage(ctx context.Context, f *backend.From) (ref, origin string, err error) { +// pinned. One only Docker has is refused: smolvm pulls from registries. +func (s *Smolvm) baseImage(f *backend.From) (ref, origin string, err error) { if f != nil { if f.Digest == "" { return "", "", msg.NoDigest(f.Ref) @@ -191,20 +186,7 @@ func (s *Smolvm) baseImage(ctx context.Context, f *backend.From) (ref, origin st } return f.Digest, f.Digest, nil } - digest, err := s.Digest(ctx, UbuntuImage) - switch { - case errors.Is(err, from.ErrUnreachable): - return "", "", msg.FromUnreachable(UbuntuImage, from.ParseRef(UbuntuImage).Host) - case errors.Is(err, from.ErrNotFound): - return "", "", msg.FromNotFound(UbuntuImage, from.ParseRef(UbuntuImage).Host) - case err != nil: - return "", "", err - } - if !from.Valid(digest) { - return "", "", msg.BadFrom(msg.Shown(digest)) - } - ref = strings.TrimSuffix(UbuntuImage, ":"+ubuntu.Version) + "@" + digest - return ref, UbuntuImage + "@" + digest, nil + return ubuntu.ContainerRef, ubuntu.ContainerOrigin, nil } // rootScript runs one of devvm's scripts for images run as containers diff --git a/internal/backend/smolvm/smolvm.go b/internal/backend/smolvm/smolvm.go index 10ad5304..90819db3 100644 --- a/internal/backend/smolvm/smolvm.go +++ b/internal/backend/smolvm/smolvm.go @@ -37,11 +37,11 @@ import ( "github.com/w3cj/devvm/internal/backend" "github.com/w3cj/devvm/internal/backend/vmssh" - "github.com/w3cj/devvm/internal/from" "github.com/w3cj/devvm/internal/msg" "github.com/w3cj/devvm/internal/paths" "github.com/w3cj/devvm/internal/platform" "github.com/w3cj/devvm/internal/state" + "github.com/w3cj/devvm/internal/ubuntu" ) // Name is the backend's name. @@ -77,9 +77,6 @@ type Smolvm struct { User func() (*user.User, error) // Memory returns the host's memory in bytes. Memory func() (uint64, error) - // Digest looks up a container image's digest (sha256:…) in its - // registry: Ubuntu's, for base. - Digest func(ctx context.Context, ref string) (string, error) // KVM is Linux's KVM device: /dev/kvm, unless DEVVM_KVM is set. KVM string // Terminal reports whether devvm's input is a terminal (a shell gets @@ -133,7 +130,7 @@ func New(d paths.Dirs, assets fs.FS, u UI) *Smolvm { return &Smolvm{ Dirs: d, Runner: logRunner{u.LoggedCmd}, OS: runtime.GOOS, Arch: runtime.GOARCH, Assets: assets, Getenv: os.Getenv, User: user.Current, Memory: platform.Memory, - Digest: from.NewRegistry().Digest, KVM: kvm, + KVM: kvm, Terminal: u.StdinIsTerminal, FreePort: freePort, PortFree: platform.PortFree, Info: u.Info, Warn: u.Warn, @@ -185,10 +182,10 @@ func (s *Smolvm) containerScript(name string) ([]byte, error) { return fs.ReadFile(s.Assets, "container/"+name) } -// KeyFiles are devvm's scripts for smolvm that go into base; one missing -// is hashed as empty. +// KeyFiles are devvm's scripts for smolvm that go into base, one missing +// hashed as empty, and Ubuntu's pinned image. func (s *Smolvm) KeyFiles() map[string][]byte { - files := map[string][]byte{} + files := map[string][]byte{"ubuntu-image": []byte(ubuntu.ContainerRef)} for _, n := range []string{"prepare.sh", "shims.sh", "sshd.sh"} { files["container/"+n], _ = s.containerScript(n) } diff --git a/internal/backend/smolvm/smolvm_test.go b/internal/backend/smolvm/smolvm_test.go index a5856051..560e177a 100644 --- a/internal/backend/smolvm/smolvm_test.go +++ b/internal/backend/smolvm/smolvm_test.go @@ -18,6 +18,7 @@ import ( "github.com/w3cj/devvm/internal/backend/vmssh" "github.com/w3cj/devvm/internal/msg" "github.com/w3cj/devvm/internal/paths" + "github.com/w3cj/devvm/internal/ubuntu" ) // execRunner runs the commands as they are: here, the smolvm stub. @@ -72,10 +73,7 @@ func newSandbox(t *testing.T) sandbox { Getenv: func(string) string { return "" }, User: func() (*user.User, error) { return &user.User{Username: "u", Uid: "501"}, nil }, Memory: func() (uint64, error) { return 64 << 30, nil }, - Digest: func(context.Context, string) (string, error) { - return "sha256:" + strings.Repeat("ab", 32), nil - }, - KVM: "/dev/kvm", Terminal: func() bool { return false }, + KVM: "/dev/kvm", Terminal: func() bool { return false }, FreePort: func(context.Context) (int, error) { return 61022, nil }, PortFree: func(context.Context, int) bool { return true }, Info: func(msg.M) {}, Warn: func(msg.M) {}, WithSteps: testUI{}.WithSteps, AddCleanup: testUI{}.AddCleanup, Interrupted: testUI{}.Interrupted, @@ -194,14 +192,15 @@ func TestCaps(t *testing.T) { } // Tool images are uncompressed, named by plain.sh; base's key has -// prepare.sh, shims.sh and sshd.sh. +// prepare.sh, shims.sh, sshd.sh and Ubuntu's pinned image. func TestFormatAndKeyFiles(t *testing.T) { s := newSandbox(t) if f := s.ToolFormat(); !strings.HasPrefix(f, "plain-") || len(f) != len("plain-")+12 { t.Errorf("ToolFormat = %q", f) } kf := s.KeyFiles() - if len(kf) != 3 || len(kf["container/prepare.sh"]) == 0 || len(kf["container/shims.sh"]) == 0 || len(kf["container/sshd.sh"]) == 0 { + if len(kf) != 4 || len(kf["container/prepare.sh"]) == 0 || len(kf["container/shims.sh"]) == 0 || len(kf["container/sshd.sh"]) == 0 || + string(kf["ubuntu-image"]) != ubuntu.ContainerRef { t.Errorf("KeyFiles = %v", slices.Collect(func(yield func(string) bool) { for k := range kf { if !yield(k) { @@ -702,7 +701,7 @@ func TestStartConfined(t *testing.T) { } } -// Base: a machine from Ubuntu's container image by digest, prepared, its +// Base: a machine from Ubuntu's pinned container image, prepared, its // scripts run between the stand-ins, packed, then deleted. func TestBuildBase(t *testing.T) { s := newSandbox(t) @@ -713,15 +712,14 @@ func TestBuildBase(t *testing.T) { if err != nil { t.Fatal(err) } - digest := "sha256:" + strings.Repeat("ab", 32) - if built.Libc != "gnu" || built.Origin != UbuntuImage+"@"+digest { + if built.Libc != "gnu" || built.Origin != "docker.io/library/ubuntu:26.04@"+ubuntu.ContainerDigest { t.Errorf("Built = %+v", built) } inst := "devvm-img-0123456789ab" got := s.calls(t) want := []string{ "smolvm machine create --name " + inst + " --label devvm.data=" + s.Dirs.Data + - " --cpus 4 --mem 8192 --storage 100 -v /var/lib/docker --net --image docker.io/library/ubuntu@" + digest, + " --cpus 4 --mem 8192 --storage 100 -v /var/lib/docker --net --image docker.io/library/ubuntu@" + ubuntu.ContainerDigest, "smolvm machine start --name " + inst, "smolvm machine exec --name " + inst + " -i -- sh -s --", "smolvm machine exec --name " + inst + " -i -- sh -s -- u 501", diff --git a/internal/ubuntu/ubuntu.go b/internal/ubuntu/ubuntu.go index 112c533b..5b498308 100644 --- a/internal/ubuntu/ubuntu.go +++ b/internal/ubuntu/ubuntu.go @@ -1,4 +1,5 @@ -// Package ubuntu finds Ubuntu's cloud image for base: the newest dated +// Package ubuntu pins Ubuntu's container image and finds Ubuntu's cloud +// image for base. The cloud image is Lima's: the newest dated // release of the series with an image for the host, and the image's // checksum from that release's SHA256SUMS. When gpgv is installed, // SHA256SUMS must be signed by Ubuntu's cloud image key, pinned in devvm's @@ -39,8 +40,26 @@ const ( // Keyring is Ubuntu's cloud image signing key, by its path in devvm's // own files. Keyring = "layers/ubuntu-cloud.gpg" + // ContainerRepo is Ubuntu's container image, which smolvm's and + // Docker's base start from without --from: Version's, by + // ContainerDigest. + ContainerRepo = "docker.io/library/ubuntu" ) +// ContainerDigest pins ContainerRepo's image: its index's digest, every +// platform's. scripts/bump.sh moves it with layers/base.sh's package +// snapshot, to an image built before the snapshot: one with newer packages +// than the snapshot has leaves apt unable to install what depends on their +// exact versions. +const ContainerDigest = "sha256:19fcd1bf268f02b60aca3bd30bd8a6d9a11759a430e32921833e65f16d87348a" + +// ContainerRef is the pinned image by its digest, as it's pulled. +const ContainerRef = ContainerRepo + "@" + ContainerDigest + +// ContainerOrigin is how base's record names the pinned image: its tag and +// digest. +const ContainerOrigin = ContainerRepo + ":" + Version + "@" + ContainerDigest + const ( timeout = 60 * time.Second // per request, body included maxBody = 4 << 20 // the listing and SHA256SUMS are a few KB diff --git a/scripts/bump.sh b/scripts/bump.sh index 71693132..a8cd7607 100755 --- a/scripts/bump.sh +++ b/scripts/bump.sh @@ -1,9 +1,11 @@ #!/bin/bash # Update the versions and checksums pinned in assets/ (layers/base.sh, layers/docker.sh, features/*.sh, -# shared-tools/build.sh, oci/build.sh) and internal/tools/mise.go (devvm's host mise). +# shared-tools/build.sh, oci/build.sh), internal/tools/mise.go (devvm's host mise) and +# internal/ubuntu/ubuntu.go (Ubuntu's container image). # scripts/bump.sh --check show current and latest for every pin; change nothing # scripts/bump.sh [tool...] update the given tools (default: all) and print a summary # Tools: apt docker mise rustup crane omb eza tealdeer +# apt: base's package snapshot, and Ubuntu's container image smolvm's and Docker's base start from # mise: base's, and the one devvm runs on the host to resolve the shared tools' versions # The shared tools themselves (node, claude, ...) aren't pinned: devvm resolves them per user. # Needs curl and jq. Checksums come from upstream's published sums where there are any; otherwise @@ -29,16 +31,20 @@ gh_head() { fetch "https://api.github.com/repos/$1/commits/${2:-master}" | jq -r sha_of() { fetch -o "$tmp/dl" "$1"; shasum -a 256 "$tmp/dl" | cut -c1-64; rm -f "$tmp/dl"; } # get FILE VAR / set_var FILE VAR VALUE: a `VAR=value` line in a pinned script (a trailing comment -# stays); in a .go file, the quoted value of `const VAR = "…"` or of a map entry `"VAR": "…",`. +# stays); in a .go file, the quoted value of `const VAR = "…"` (get_const) or of a map entry +# `"VAR": "…",`. get() { sed -n "s/^$2=\([^ ]*\).*/\1/p" "$root/$1"; } +get_const() { sed -n "s/^const $2 = \"\(.*\)\"$/\1/p" "$root/$1"; } # valid VAR VALUE: VALUE comes from upstream and lands in a script that runs (some on the host), so -# only the shape a pin can have: a checksum, a commit, a snapshot date or a version. Else exit. +# only the shape a pin can have: a checksum, a commit, an image digest, a snapshot date or a version. +# Else exit. valid() { local re='^[0-9A-Za-z][0-9A-Za-z.+~_-]*$' case $1 in *_sha256*) re='^[0-9a-f]{64}$' ;; *_commit) re='^[0-9a-f]{40}$' ;; - apt_snapshot) re='^[0-9]{8}T[0-9]{6}Z$' ;; + *_digest) re='^sha256:[0-9a-f]{64}$' ;; + apt_snapshot|*_built) re='^[0-9]{8}T[0-9]{6}Z$' ;; esac [[ $2 =~ $re ]] || { printf 'bump: upstream gave %s an unexpected value: %q\n' "$1" "$2" >&2; exit 1; } } @@ -83,12 +89,48 @@ pin3() { # pin3 FILE PREFIX VERSION SHA_ARM64 SHA_AMD64 set_var "$1" "${2}_sha256_amd64" "$5" } -# The package snapshot base builds from: today's (UTC). +# ubuntu_image sets ubuntu_digest, the digest of Ubuntu's container image (Docker Hub's ubuntu:26.04: its +# index, hashed here from what the registry sent), and ubuntu_built, when the newest of its linux/arm64 +# and linux/amd64 images was built (their org.opencontainers.image.created, as YYYYMMDDTHHMMSSZ). +ubuntu_image() { + local hub=https://registry-1.docker.io/v2/library/ubuntu auth a m c t + auth="Authorization: Bearer $(fetch "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/ubuntu:pull" | jq -r .token)" + fetch -H "$auth" -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json' \ + "$hub/manifests/26.04" > "$tmp/ubuntu-index" + ubuntu_digest=sha256:$(shasum -a 256 "$tmp/ubuntu-index" | cut -c1-64) + ubuntu_built="" + for a in arm64 amd64; do + m=$(jq -r --arg a "$a" '[.manifests[] | select(.platform.os == "linux" and .platform.architecture == $a)][0].digest // ""' "$tmp/ubuntu-index") + valid ubuntu_digest "$m" + c=$(fetch -H "$auth" -H 'Accept: application/vnd.oci.image.manifest.v1+json' "$hub/manifests/$m" | + jq -r '.annotations["org.opencontainers.image.created"] // ""') + # 2026-10-25T10:30:32.309136+00:00 -> 20261025T103032Z; UTC only. + t=$c + if [[ $c =~ ^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]+)?(Z|\+00:00)$ ]]; then + t=${BASH_REMATCH[1]}${BASH_REMATCH[2]}${BASH_REMATCH[3]}T${BASH_REMATCH[4]}${BASH_REMATCH[5]}${BASH_REMATCH[6]}Z + fi + valid ubuntu_built "$t" + if [[ $t > $ubuntu_built ]]; then ubuntu_built=$t; fi + done +} + +# The package snapshot base builds from, today's (UTC), and Ubuntu's container image smolvm's and +# Docker's base start from, by digest. They move together, and only to an image built before the +# snapshot: apt can't install what depends on the exact version of a package newer than the snapshot's. bump_apt() { - local f=assets/layers/base.sh cur new + local f=assets/layers/base.sh g=internal/ubuntu/ubuntu.go cur new img want=false cur=$(get $f apt_snapshot); new=$(date -u +%Y%m%dT000000Z) - report apt "$cur" "$new" || return 0 + img=$(get_const $g ContainerDigest) + ubuntu_image + if report apt "$cur" "$new"; then want=true; fi + if report ubuntu "${img:7:12}" "${ubuntu_digest:7:12}"; then want=true; fi + $want || return 0 + if [[ ! $ubuntu_built < $new ]]; then + echo "bump: Ubuntu's image was built at $ubuntu_built, after today's snapshot $new: bump apt tomorrow" >&2 + exit 1 + fi set_var $f apt_snapshot "$new" + set_var $g ContainerDigest "$ubuntu_digest" ubuntu_digest } # Docker's packages: the newest of each in its repository for base's Ubuntu release, and its signing key. diff --git a/testdata/script/bump.txtar b/testdata/script/bump.txtar index bd661f60..c042c13e 100644 --- a/testdata/script/bump.txtar +++ b/testdata/script/bump.txtar @@ -19,6 +19,32 @@ cmp stdout mise-base.want exec grep -E 'miseVersion =|"(macos|linux)-' repo/internal/tools/mise.go cmp stdout mise-go.want +# apt moves base's snapshot to today and Ubuntu's container image to the +# digest of the index the registry sent, built before the snapshot. +exec repo/scripts/bump.sh apt +stdout '^ ubuntu +19fcd1bf268f +-> 8186ab583383$' +exec grep '^apt_snapshot=' repo/assets/layers/base.sh +stdout '^apt_snapshot=[0-9]{8}T000000Z$' +exec grep '^const ContainerDigest = ' repo/internal/ubuntu/ubuntu.go +stdout '^const ContainerDigest = "sha256:8186ab5833835533fd62c92e6a51bb4e3a194c74406f64f10befc8a7cd388c91"$' + +# An image built after the snapshot, or one whose build time isn't one, is +# refused, and nothing is edited. +exec bash repo.sh +cp repo/assets/layers/base.sh base.before +cp repo/internal/ubuntu/ubuntu.go ubuntu.before +cp ubuntu-future up/ubuntu-amd64 +! exec repo/scripts/bump.sh apt +stderr '^bump: Ubuntu''s image was built at 29990101T000000Z, after today''s snapshot ' +cmp repo/assets/layers/base.sh base.before +cmp repo/internal/ubuntu/ubuntu.go ubuntu.before +cp ubuntu-hostile up/ubuntu-amd64 +! exec repo/scripts/bump.sh apt +stderr '^bump: upstream gave ubuntu_built an unexpected value: ' +cmp repo/assets/layers/base.sh base.before +cmp repo/internal/ubuntu/ubuntu.go ubuntu.before +! exists pwned + # Upstream values that aren't a version or a checksum are refused, and # nothing is edited: a command for a checksum, one in a version, and a # missing asset (an empty checksum). @@ -63,25 +89,44 @@ stderr '^bump: unknown tool ''nope''' # A copy of the files bump.sh edits, and upstream's good answers. set -eu rm -rf repo up -mkdir -p repo/scripts repo/assets/oci repo/assets/layers repo/internal/tools up +mkdir -p repo/scripts repo/assets/oci repo/assets/layers repo/internal/tools repo/internal/ubuntu up cp "$DEVVM_REPO/scripts/bump.sh" repo/scripts/ cp "$DEVVM_REPO/assets/oci/build.sh" repo/assets/oci/ cp "$DEVVM_REPO/assets/layers/base.sh" repo/assets/layers/ cp "$DEVVM_REPO/internal/tools/mise.go" repo/internal/tools/ +cp "$DEVVM_REPO/internal/ubuntu/ubuntu.go" repo/internal/ubuntu/ cp latest-good up/crane-latest cp sums-good up/crane-sums cp mise-latest up/mise-latest cp mise-sums up/mise-sums +cp ubuntu-index up/ubuntu-index +cp ubuntu-arm64 up/ubuntu-arm64 +cp ubuntu-amd64 up/ubuntu-amd64 -- bin/curl -- #!/bin/bash -# Answers crane's and mise's releases from $WORK/up/; anything else fails. +# Answers crane's and mise's releases and Ubuntu's container image from +# $WORK/up/; anything else fails. for a in "$@"; do case $a in */go-containerregistry/releases/latest) cat "$WORK/up/crane-latest"; exit ;; */go-containerregistry/*/checksums.txt) cat "$WORK/up/crane-sums"; exit ;; */jdx/mise/releases/latest) cat "$WORK/up/mise-latest"; exit ;; */jdx/mise/*/SHASUMS256.txt) cat "$WORK/up/mise-sums"; exit ;; + https://auth.docker.io/token*) echo '{"token":"t"}'; exit ;; + */library/ubuntu/manifests/26.04) cat "$WORK/up/ubuntu-index"; exit ;; + */library/ubuntu/manifests/sha256:aaaa*) cat "$WORK/up/ubuntu-arm64"; exit ;; + */library/ubuntu/manifests/sha256:bbbb*) cat "$WORK/up/ubuntu-amd64"; exit ;; esac; done exit 22 +-- ubuntu-index -- +{"manifests":[{"digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","platform":{"architecture":"arm64","os":"linux"}},{"digest":"sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","platform":{"architecture":"amd64","os":"linux"}}]} +-- ubuntu-arm64 -- +{"annotations":{"org.opencontainers.image.created":"2000-01-02T03:04:05.309136+00:00"}} +-- ubuntu-amd64 -- +{"annotations":{"org.opencontainers.image.created":"2000-01-02T03:04:06Z"}} +-- ubuntu-future -- +{"annotations":{"org.opencontainers.image.created":"2999-01-01T00:00:00Z"}} +-- ubuntu-hostile -- +{"annotations":{"org.opencontainers.image.created":"$(touch pwned)"}} -- latest-good -- {"tag_name":"v9.9.9"} -- latest-hostile -- diff --git a/tests/e2e.sh b/tests/e2e.sh index 349d0b2a..7f74974a 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -120,6 +120,8 @@ fi if want from; then for f in "$root"/assets/features/*.sh; do basename "$f" .sh; done > "$XDG_CONFIG_HOME/devvm/base-features" else : > "$XDG_CONFIG_HOME/devvm/base-features"; fi D=$src/devvm +# The digest of Ubuntu's container image smolvm's and Docker's base start from, as devvm pins it. +ubuntu_pin=$(sed -n 's/^const ContainerDigest = "\(sha256:[0-9a-f]\{64\}\)"$/\1/p' "$root/internal/ubuntu/ubuntu.go") images=$XDG_DATA_HOME/devvm/images # the image records, one per key layers=$XDG_CONFIG_HOME/devvm/layers vms=$XDG_DATA_HOME/devvm/vms # the VMs' state, one per VM @@ -236,7 +238,9 @@ trap 'exit 130' INT TERM # Progress: each result shows [n/N], how long it took (since the previous check, so builds count), # and the time left as the previous run measured it ($work/timings: "labelseconds"). A # heartbeat every minute says what's happening during long steps. -timings=$work/timings-$(tr ' ' '-' <<<"$sel") # per selection: they run different checks +# Per selection and Docker engines: they run different checks (on macOS, the Linux engine's are timed by +# its own run, in the docker host VM). +timings=$work/timings-$(tr ' ' '-' <<<"$sel${engines:+ $engines}") : > "$timings.new" total=$(wc -l 2>/dev/null < "$timings" | tr -d ' '); [[ ${total:-0} -gt 0 ]] || total="?" started=$SECONDS ncheck=0 @@ -943,7 +947,8 @@ fi if want from; then section "--from" # Registry images need no Docker: these run with a docker that's installed but not running (it -# logs what devvm asked it, which may only be whether it has the image). +# logs what devvm asked it, which may only be whether it has the image, and, as each launch asks +# every backend, which VMs of devvm's it has). mkdir -p "$work/nodocker"; : > "$work/docker-calls" printf '#!/bin/sh\necho "docker $*" >> "%s"\necho "Cannot connect to the Docker daemon" >&2; exit 1\n' \ "$work/docker-calls" > "$work/nodocker/docker" @@ -984,7 +989,8 @@ check "no crashed services" in_vm "$vm" '[[ -z "$(sudo rc-status --crashed 2>/de # Ubuntu's image has empty package lists, where apt 3.2 needs a second update to reach the snapshot. check "base builds from ubuntu:26.04" nd quiet "$D" --from ubuntu:26.04 build base -check "none of them needed Docker" bash -c "! grep -v '^docker image inspect ' '$work/docker-calls'" +check "none of them needed Docker" bash -c "! grep -v -e '^docker image inspect ' \ + -e '^docker container ls -a -q --no-trunc --filter label=devvm\.data=$XDG_DATA_HOME/devvm --filter label=devvm\.kind=vm$' '$work/docker-calls'" check "and the build VM and its temporary folders are gone" bash -c " ! limactl list -q 2>/dev/null | grep -qx devvm-oci-build && ! ls -d \"\${TMPDIR:-/tmp}\"/devvm-oci.* 2>/dev/null" # An image only Docker has (built, never pushed) isn't checked: making one would change Docker's images. @@ -1011,9 +1017,11 @@ export -f smol_pid # forward is TSI, where the VM asks this machine's resolver itself; any forward, or an allow list, is # virtio-net, where it asks smolvm's (the gateway, 100.96.0.1). design.md's DNS detection rests on it. smol_nameserver() { SMOLVM_USAGE=0 smolvm machine exec --name "$1" -- awk '$1 == "nameserver" { print $2; exit }' /etc/resolv.conf building_image image=base key=\([0-9a-f]*\)$/\1/p' "$work/la [[ -n $kb ]] || kb=$(for k in "$XDG_DATA_HOME"/devvm/smolvm/images/*; do k=$(basename "$k"); grep -qx name=base "$images/$k" 2>/dev/null && grep -qx from= "$images/$k" && echo "$k"; done | head -1) packs=$XDG_DATA_HOME/devvm/smolvm/images -check "base is a pack, recorded with Ubuntu's container image by digest; its build machine is gone" bash -c " - [[ -n '$kb' && -f '$packs/$kb/image.smolmachine' ]] && grep -qx libc=gnu '$images/$kb' && - grep -qE '^digest=docker\.io/library/ubuntu:[0-9.]+@sha256:[0-9a-f]{64}$' '$images/$kb' && [[ -z \$(smol_status devvm-img-$kb) ]]" +check "base is a pack, recorded with Ubuntu's container image by its pinned digest; its build machine is gone" bash -c " + [[ -n '$kb' && -n '$ubuntu_pin' && -f '$packs/$kb/image.smolmachine' ]] && grep -qx libc=gnu '$images/$kb' && + grep -qE '^digest=docker\.io/library/ubuntu:[0-9.]+@$ubuntu_pin$' '$images/$kb' && [[ -z \$(smol_status devvm-img-$kb) ]]" fixture=$layers/e2esmol.sh token=e2e-smolvm-ran-$$-$(date +%s) printf '#!/bin/bash\necho %s\necho fixture | sudo tee /etc/e2e-fixture\n' "$token" > "$fixture" @@ -2427,8 +2435,10 @@ docker_emulated() { # docker_linux: the checks on this machine's engine, a Linux one. docker_linux() { local others_before kb fixture token kf kx rc - # alpine:3, which docker_ssh builds a base from, pulled first: Docker keeps the image devvm pulls. + # alpine:3, which docker_ssh builds a base from, and Ubuntu's pinned image, which base starts from, + # pulled first: Docker keeps the images devvm pulls. docker image pull -q alpine:3 >/dev/null 2>&1 + docker image pull -q "docker.io/library/ubuntu@$ubuntu_pin" >/dev/null 2>&1 others_before=$(d_others) section "docker: shared tool versions" check "the shared tools resolve to upstream's newest" quiet "$D" _refresh-tools @@ -2441,9 +2451,9 @@ docker_linux() { check "build base" quiet env DEVVM_MESSAGES=names "$D" "${B[@]}" build base kb=$(sed -n 's/^==> building_image image=base key=\([0-9a-f]*\)$/\1/p' "$work/last.log") [[ -n $kb ]] || kb=$(for k in $(keys_of base); do grep -qx from= "$images/$k" && d_img "devvm-$dns:$k" && echo "$k"; done | head -1) - check "base is an image of devvm's, recorded with Ubuntu's container image by digest; its build container is gone" bash -c " - [[ -n '$kb' ]] && d_img 'devvm-$dns:$kb' && grep -qx libc=gnu '$images/$kb' && - grep -qE '^digest=docker\.io/library/ubuntu:[0-9.]+@sha256:[0-9a-f]{64}$' '$images/$kb' && [[ -z \$(d_state devvm-img-$kb-$dns) ]]" + check "base is an image of devvm's, recorded with Ubuntu's container image by its pinned digest; its build container is gone" bash -c " + [[ -n '$kb' && -n '$ubuntu_pin' ]] && d_img 'devvm-$dns:$kb' && grep -qx libc=gnu '$images/$kb' && + grep -qE '^digest=docker\.io/library/ubuntu:[0-9.]+@$ubuntu_pin$' '$images/$kb' && [[ -z \$(d_state devvm-img-$kb-$dns) ]]" # Build confinement: servers on this machine, on its loopback and on every address, and a layer that # tries both through the build container's gateway. python3 -m http.server -b 127.0.0.1 47190 >/dev/null 2>&1 & d_servers+=($!)