Start again from agentos: a read-only, verity-checked /usr with A/B updates, and a TPM-encrypted btrfs root made at first boot that holds /etc and /var. On top of that the runner: gitea-runner from gitea.com, a path unit that starts it once registered, and a drain before update reboots. Jobs run in plain Fedora on root's podman. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0569bce676
commit
0733ff55f3
49 files changed
+492
-509
No files matched your search
@@ -1,42 +1,52 @@
|
||||
# git-runner-mkosi
|
||||
# runneros
|
||||
|
||||
A [Gitea Actions](https://docs.gitea.com/usage/actions/overview) runner packaged as a minimal Fedora VM image, built with [mkosi](https://github.com/systemd/mkosi). It builds and publishes its own OS image, and keeps itself up to date.
|
||||
A VM that runs a [Gitea Actions](https://docs.gitea.com/usage/actions/overview)
|
||||
runner. It is a minimal Fedora image built with
|
||||
[mkosi](https://github.com/systemd/mkosi), and it builds and publishes its own
|
||||
image.
|
||||
|
||||
- **Small:** Fedora with podman, networking and zram swap, for VMs only: no firmware or drivers for real hardware, no package manager or sshd. About 300 MB of RAM idle; boots in 512 MB.
|
||||
- **Stateless:** container storage is wiped on every boot.
|
||||
- **Isolated jobs:** each job runs in a container of its own (privileged, so it can build OS images), with its own podman; jobs never get the runner's podman. The job image ships with the OS, and common base images are shared read-only, so jobs don't download them. A job that runs the VM out of memory is killed (systemd-oomd); the runner keeps running.
|
||||
- **Self-updating:** images are rebuilt weekly and on every push. Hosts download updates with systemd-sysupdate, check their signature (the key is the `SIGNING_KEY` secret of this repository), and write them into a second root partition (A/B) and reboot into them daily at about 04:10, after letting running jobs finish.
|
||||
- **Secure Boot:** systemd-boot and the UKIs are signed with our own key (`mkosi.crt`; the private key is the `SECUREBOOT_KEY` secret of this repository). systemd-boot enrolls it at first boot if the VM's firmware has no keys yet; the firmware then boots nothing else.
|
||||
- **Read-only system:** systemd-boot starts a UKI that mounts the root filesystem, /etc and /usr included, from a read-only erofs partition checked by dm-verity. Updates replace it whole, so nothing drifts. All state (the runner registration, the root password, logs) lives on /var, its own partition.
|
||||
- **Hardened:** a firewall that drops all incoming traffic, and KSPP sysctls and kernel arguments.
|
||||
- **Read-only OS:** `/usr` is read-only. Secure Boot verifies the UKI (kernel,
|
||||
initrd and command line), which holds the dm-verity hash that verifies
|
||||
`/usr`.
|
||||
- **Encrypted with a TPM:** everything that isn't read-only, such as `/etc`
|
||||
and `/var`, is encrypted. The TPM unlocks it only for correctly signed UKIs.
|
||||
- **Jobs in containers:** each job runs in its own privileged container on
|
||||
root's podman, by default in plain Fedora (`runs-on: linux`). Privileged
|
||||
jobs can build OS images, but can also take over the VM, so only use it for
|
||||
repositories you trust. Container storage is wiped at every boot.
|
||||
- **Self-updating:** the image rebuilds weekly. The VM lets running jobs finish
|
||||
before it reboots into an update, and a bad update rolls back by itself.
|
||||
|
||||
## Install
|
||||
|
||||
Download [the disk image](https://git.plabble.org/api/packages/Job79/generic/git-runner/latest/git-runner.qcow2) (built by the `os` workflow), resize it to the disk size you want (/var grows to fill it) and boot it with UEFI in Secure Boot setup mode (no keys enrolled; in Proxmox, add the EFI disk with "Pre-Enroll keys" unchecked), so it enrolls our key. The screen and the serial console ask for a root password, hostname, Gitea URL, registration token and number of parallel jobs; the runner then registers itself.
|
||||
Download [the disk image](https://git.plabble.org/api/packages/Job79/generic/runneros/latest/runneros.qcow2),
|
||||
resize it to the disk size you want and boot it with UEFI and a TPM. At first
|
||||
boot, the screen offers a recovery key for the encrypted disk and asks for a
|
||||
root password. Then log in as root and register the runner with a token from
|
||||
Gitea's runner settings:
|
||||
|
||||
## Images
|
||||
```sh
|
||||
gitea-runner -c /etc/gitea-runner/config.yaml register
|
||||
```
|
||||
|
||||
| `runs-on` | Image |
|
||||
|---|---|
|
||||
| `linux` | Our job image (`mkosi.images/job/`): git, Node.js, dnf and podman (also as `docker`) |
|
||||
| `fedora` | Plain Fedora |
|
||||
It registers under the hostname, `runneros-` and four hex digits, and starts.
|
||||
|
||||
To start over, run `systemctl start factory-reset.target` as root. It reboots
|
||||
and wipes the root partition (`/etc` and `/var`), and the VM sets itself up as
|
||||
at first boot.
|
||||
|
||||
## Development
|
||||
|
||||
`mkosi.conf` defines the OS (`mkosi.extra/` is copied to `/`, `mkosi.repart/` is the disk layout), `mkosi.images/job/` the job image.
|
||||
`mkosi build` signs with `mkosi.key`, the private key of `mkosi.crt`, which
|
||||
only CI has (the `SECUREBOOT_KEY` secret). Local builds sign with a test key
|
||||
instead:
|
||||
|
||||
```sh
|
||||
mkosi build
|
||||
openssl req -new -x509 -newkey rsa:2048 -nodes -subj /CN=test \
|
||||
-keyout ~/test.key -out ~/test.crt
|
||||
mkosi --secure-boot-key ~/test.key --secure-boot-certificate ~/test.crt build
|
||||
```
|
||||
|
||||
The build signs with `mkosi.key`: the `SECUREBOOT_KEY` secret, or for a local test a key of your own (`mkosi genkey` writes `mkosi.key` and `mkosi.crt`; don't commit them).
|
||||
|
||||
`mkosi.output/` then holds the disk image (`git-runner_<version>.raw`), and the UKI and root partitions that the `os` workflow publishes as an update. To boot the disk image with Secure Boot (needs `qemu-kvm-core edk2-ovmf`; `OVMF_VARS.fd` has no keys, so it enrolls ours):
|
||||
|
||||
```sh
|
||||
qemu-img convert -O qcow2 mkosi.output/git-runner_<version>.raw test.qcow2 && qemu-img resize test.qcow2 40G
|
||||
cp /usr/share/edk2/ovmf/OVMF_VARS.fd vars.fd
|
||||
qemu-kvm -m 8G -smp 4 -cpu host -nic user,model=virtio-net-pci -drive file=test.qcow2,if=virtio -device virtio-balloon-pci,free-page-reporting=on \
|
||||
-machine q35,smm=on -global driver=cfi.pflash01,property=secure,value=on \
|
||||
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd -drive if=pflash,format=raw,file=vars.fd
|
||||
```
|
||||
`mkosi.output/` then holds the disk image (`runneros_<version>.raw`) and the
|
||||
UKI and /usr partitions that make up an update. To boot a test VM, see
|
||||
[AGENTS.md](AGENTS.md#testing).
|
||||
Reference in new issue
Block a user