Seal /etc: read-only root with /etc and /usr, state on /var

The root filesystem (/etc and /usr) is now one read-only erofs partition behind dm-verity,
updated A/B as a whole, so /etc can no longer drift from the image (stale CA certificates,
frozen Fedora defaults). All state lives on a new /var partition, mounted by /etc/fstab.

What used to be written to /etc at runtime:
- machine ID: from the VM's firmware UUID (systemd.machine_id=firmware); /etc/machine-id is
  empty, so no boot counts as the first.
- root password: gitea-runner-setup writes a shadow file to /var/lib/shadow, which
  etc-shadow.mount puts over /etc/shadow.
- hostname and runner.env: runner.env moves to /var/lib/gitea-runner and holds the runner's
  name; gitea-runner.service sets it as the (transient) hostname, and DHCP no longer does.

Hosts installed before this change must be reinstalled: updates can't change the partition
layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snrGfdvwU7pMNBiDpHv
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-14 12:12:10 +01:00
1 parent c2ec9ddb29
commit b0a49de3e6
25 files changed
+96 -63

No files matched your search

+2 -2
View File
@@ -28,8 +28,8 @@ jobs:
- name: Compress
working-directory: mkosi.output
run: |
zstd -q --rm -T0 -19 git-runner_*.usr-*.raw
sha256sum git-runner_*.efi git-runner_*.usr-*.raw.zst > SHA256SUMS
zstd -q --rm -T0 -19 git-runner_*.root-*.raw
sha256sum git-runner_*.efi git-runner_*.root-*.raw.zst > SHA256SUMS
- name: Find the release
run: |
release=$(curl -fsS -H "$AUTH" "$API/tags/latest") ||
+4 -4
View File
@@ -5,13 +5,13 @@ A [Gitea Actions](https://docs.gitea.com/usage/actions/overview) runner packaged
- **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 into a second /usr partition (A/B) and reboot into them daily at about 04:10, after letting running jobs finish.
- **Read-only /usr:** systemd-boot starts a UKI that mounts /usr from a read-only erofs partition, checked by dm-verity. /etc and /var live on the root partition, which updates keep.
- **Self-updating:** images are rebuilt weekly and on every push. Hosts download updates with systemd-sysupdate into a second root partition (A/B) and reboot into them daily at about 04:10, after letting running jobs finish.
- **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.
## Install
Download [the disk image](https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/git-runner.qcow2) (built weekly by the `os` workflow), resize it to the disk size you want (the root partition grows to fill it) and boot it with UEFI. The console asks 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/Job79/git-runner-mkosi/releases/download/latest/git-runner.qcow2) (built weekly by the `os` workflow), resize it to the disk size you want (/var grows to fill it) and boot it with UEFI. The console asks for a root password, hostname, Gitea URL, registration token and number of parallel jobs; the runner then registers itself.
## Images
@@ -28,7 +28,7 @@ Download [the disk image](https://git.plabble.org/Job79/git-runner-mkosi/release
mkosi build
```
`mkosi.output/` then holds the disk image (`git-runner_<version>.raw`), and the UKI and /usr partitions that the `os` workflow publishes as an update. To boot the disk image (needs `qemu-kvm-core edk2-ovmf`):
`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 (needs `qemu-kvm-core edk2-ovmf`):
```sh
qemu-img convert -O qcow2 mkosi.output/git-runner_<version>.raw test.qcow2 && qemu-img resize test.qcow2 40G
+8 -6
View File
@@ -1,6 +1,8 @@
# git-runner: a Fedora VM image that runs the Gitea Actions runner, built with mkosi.
# mkosi.extra/ is copied to /, mkosi.repart/ defines the disk, mkosi.prepare adds the runner,
# mkosi.images/job/ is the job image.
# The root filesystem, /etc included, is read-only and replaced whole by updates; all state
# lives on /var.
[Config]
Dependencies=job
@@ -13,7 +15,7 @@ Release=45
Format=disk
ImageId=git-runner
OutputDirectory=mkosi.output
# The UKI and /usr partitions are published as updates (systemd-sysupdate).
# The UKI and root partitions are published as updates (systemd-sysupdate).
SplitArtifacts=uki,partitions
[Content]
@@ -47,13 +49,14 @@ WithDocs=no
Locale=C.UTF-8
# The UKI's file name in the ESP, as systemd-sysupdate names the ones it installs.
UnifiedKernelImageFormat=%i_%v
# A writable root, the console on screen and serial port, no systemd-firstboot questions
# (gitea-runner-setup asks its own), and KSPP hardening (the last four).
# The console on screen and serial port, the machine ID from the VM's firmware (/etc is read-only;
# mkosi.extra/etc/machine-id is empty, so no boot counts as the first), no systemd-firstboot
# questions (gitea-runner-setup asks its own), and KSPP hardening (the last four).
KernelCommandLine=
rw
console=tty0
console=ttyS0,115200n8
quiet
systemd.machine_id=firmware
systemd.firstboot=no
slab_nomerge
init_on_alloc=1
@@ -90,8 +93,7 @@ KernelModules=
ipvlan
# - System.map only for debugging the kernel
# - udev hwdb hardware names and quirks, nothing a VM needs
# - homed, userdbd, nsresourced unused services; removing their units also stops them
# on hosts installed before (/etc keeps them enabled)
# - homed, userdbd, nsresourced unused services
RemoveFiles=
/usr/lib/modules/*/System.map
/usr/lib/udev/hwdb.bin
+2
View File
@@ -0,0 +1,2 @@
# /var, the only writable partition (mkosi.repart/30-var.conf). Grows to fill its partition at boot.
PARTLABEL=var /var ext4 x-systemd.growfs 0 2
View File
Whitespace-only changes.
+1 -1
View File
@@ -1,7 +1,7 @@
# The runner's configuration (gitea-runner.service).
# Every option: `gitea-runner config generate`.
runner:
# Parallel jobs, asked at first boot (stored in /etc/gitea-runner/runner.env).
# Parallel jobs, asked at first boot (stored in /var/lib/gitea-runner/runner.env).
capacity: ${GITEA_RUNNER_CAPACITY}
# On stop (before an update reboot), take no new jobs and give running ones this long to finish.
shutdown_timeout: 30m
@@ -1,4 +0,0 @@
# Grow the root partition to fill the disk at boot (systemd-repart); systemd-growfs then grows
# its filesystem (GrowFileSystem= in mkosi.repart/30-root.conf).
[Partition]
Type=root
+4
View File
@@ -0,0 +1,4 @@
# Grow the /var partition to fill the disk at boot (systemd-repart); x-systemd.growfs in /etc/fstab
# then grows its filesystem.
[Partition]
Type=var
@@ -6,3 +6,7 @@ Kind=!*
[Network]
DHCP=yes
[DHCPv4]
# The hostname is the runner's name (gitea-runner.service), not the DHCP server's.
UseHostname=no
@@ -4,6 +4,7 @@ enable systemd-resolved.service
enable nftables.service
enable podman.socket
enable gitea-runner-setup.service
enable etc-shadow.mount
enable gitea-runner.service
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
@@ -0,0 +1,14 @@
# The root password. /etc is read-only, so gitea-runner-setup writes the shadow file to /var and
# this mounts it over /etc/shadow.
[Unit]
Description=Root password from /var
ConditionPathExists=/var/lib/shadow/etc/shadow
RequiresMountsFor=/var
[Mount]
What=/var/lib/shadow/etc/shadow
Where=/etc/shadow
Options=bind
[Install]
WantedBy=local-fs.target
@@ -1,7 +1,7 @@
# First boot: asks for the root password and the runner's registration on the console (tty1).
[Unit]
Description=Gitea runner first-boot setup
ConditionPathExists=!/etc/gitea-runner/runner.env
ConditionPathExists=!/var/lib/gitea-runner/runner.env
Before=getty@tty1.service kmsconvt@tty1.service
[Service]
@@ -11,8 +11,10 @@ Requires=podman.socket
# never get the socket (see config.yaml).
User=gitea-runner
WorkingDirectory=/var/lib/gitea-runner
EnvironmentFile=/etc/gitea-runner/runner.env
EnvironmentFile=/var/lib/gitea-runner/runner.env
Environment=DOCKER_HOST=unix:///run/podman/podman.sock
# The hostname is the runner's name. /etc is read-only, so it is set on every start (as root: +).
ExecStartPre=+/usr/bin/hostnamectl hostname --transient ${GITEA_RUNNER_NAME}
# Register once; the result is kept in .runner.
ExecStartPre=/bin/sh -c '[ -f .runner ] || exec gitea-runner register --no-interactive --config /usr/lib/gitea-runner/config.yaml --instance "$GITEA_INSTANCE_URL"'
ExecStart=/usr/bin/gitea-runner daemon --config /usr/lib/gitea-runner/config.yaml
@@ -1,4 +1,4 @@
# Updates /usr: writes the next version to the unused /usr partition.
# Updates the root filesystem: writes the next version to the unused root partition.
# Verify=no: releases are unsigned (no secrets in the repo); SHA256SUMS still checks each download.
[Transfer]
ProtectVersion=%A
@@ -7,12 +7,12 @@ Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/
MatchPattern=git-runner_@v.usr-%a.@u.raw.zst
MatchPattern=git-runner_@v.root-%a.@u.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v
MatchPartitionType=usr
MatchPartitionType=root
PartitionFlags=0
ReadOnly=1
@@ -1,4 +1,4 @@
# Updates the dm-verity hashes of /usr, next to 10-usr.transfer (which explains Verify=no).
# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=no).
[Transfer]
ProtectVersion=%A
Verify=no
@@ -6,12 +6,12 @@ Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/
MatchPattern=git-runner_@v.usr-%a-verity.@u.raw.zst
MatchPattern=git-runner_@v.root-%a-verity.@u.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v_verity
MatchPartitionType=usr-verity
MatchPartitionType=root-verity
PartitionFlags=0
ReadOnly=1
@@ -1,4 +1,4 @@
# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-usr.transfer.
# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-root.transfer.
[Transfer]
ProtectVersion=%A
Verify=no
+9 -4
View File
@@ -1,5 +1,7 @@
#!/bin/bash
# First boot: ask for the root password and the runner's registration.
# First boot: asks for the root password and the runner's registration on the console (tty1).
# /etc is read-only, so the answers go to /var: the password to /var/lib/shadow (etc-shadow.mount
# puts it over /etc/shadow), the rest to the runner's runner.env.
set -euo pipefail
echo "== Gitea runner setup =="
@@ -9,15 +11,18 @@ while :; do
[[ -n $pw && $pw == "$pw2" ]] && break
echo "Passwords do not match, try again."
done
echo "root:$pw" | chpasswd
install -d -m 0700 /var/lib/shadow/etc
cp /etc/passwd /etc/shadow /var/lib/shadow/etc/
echo "root:$pw" | chpasswd --prefix /var/lib/shadow
systemctl start etc-shadow.mount
read -rp "Hostname (also the runner name): " name
read -rp "Gitea URL (e.g. https://gitea.example.com): " url
read -rp "Runner registration token: " token
read -rp "Parallel jobs [1]: " capacity
[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1
hostnamectl hostname "$name"
install -D -m 0640 -g gitea-runner /dev/stdin /etc/gitea-runner/runner.env <<ENV
install -D -m 0640 -g gitea-runner /dev/stdin /var/lib/gitea-runner/runner.env <<ENV
GITEA_RUNNER_NAME=$name
GITEA_INSTANCE_URL=$url
GITEA_RUNNER_REGISTRATION_TOKEN=$token
GITEA_RUNNER_CAPACITY=$capacity
+15
View File
@@ -0,0 +1,15 @@
# The root filesystem, slot A: /etc and /usr, read-only erofs protected by dm-verity (roothash= in
# the UKI). Updates replace it whole. /var, the state, is its own partition (30-var.conf).
[Partition]
Type=root
Label=%M_%A
Format=erofs
Compression=zstd
CopyFiles=/
ExcludeFilesTarget=/var/
Verity=data
VerityMatchKey=root
SizeMinBytes=1G
SizeMaxBytes=1G
# The file name holds the partition UUID, which roothash= finds the root by; updates keep it (@u in sysupdate.d).
SplitName=%t.%U
-13
View File
@@ -1,13 +0,0 @@
# /usr, slot A: read-only erofs, protected by dm-verity (usrhash= in the UKI).
[Partition]
Type=usr
Label=%M_%A
Format=erofs
Compression=zstd
CopyFiles=/usr:/
Verity=data
VerityMatchKey=usr
SizeMinBytes=1G
SizeMaxBytes=1G
# The file name holds the partition UUID, which usrhash= finds /usr by; updates keep it (@u in sysupdate.d).
SplitName=%t.%U
@@ -1,9 +1,9 @@
# dm-verity hashes of /usr, slot A.
# dm-verity hashes of the root filesystem, slot A.
[Partition]
Type=usr-verity
Type=root-verity
Label=%M_%A_verity
Verity=hash
VerityMatchKey=usr
VerityMatchKey=root
SizeMinBytes=64M
SizeMaxBytes=64M
SplitName=%t.%U
+7
View File
@@ -0,0 +1,7 @@
# The root filesystem, slot B: empty until systemd-sysupdate writes the next version.
[Partition]
Type=root
Label=_empty
SizeMinBytes=1G
SizeMaxBytes=1G
SplitName=-
-7
View File
@@ -1,7 +0,0 @@
# /usr, slot B: empty until systemd-sysupdate writes the next version.
[Partition]
Type=usr
Label=_empty
SizeMinBytes=1G
SizeMaxBytes=1G
SplitName=-
@@ -1,6 +1,6 @@
# dm-verity hashes of /usr, slot B.
# dm-verity hashes of the root filesystem, slot B.
[Partition]
Type=usr-verity
Type=root-verity
Label=_empty
SizeMinBytes=64M
SizeMaxBytes=64M
-8
View File
@@ -1,8 +0,0 @@
# The root filesystem: /etc and /var, kept across updates. Grows to fill the disk at boot.
[Partition]
Type=root
Format=ext4
CopyFiles=/
ExcludeFilesTarget=/usr/
Minimize=guess
GrowFileSystem=yes
+9
View File
@@ -0,0 +1,9 @@
# /var: the state that updates keep (the runner's registration, the root password, logs, base
# images). Mounted by /etc/fstab, which also grows it to fill the disk at boot.
[Partition]
Type=var
Label=var
Format=ext4
CopyFiles=/var:/
Minimize=guess
SplitName=-