diff --git a/README.md b/README.md index 73687d4..2d67759 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ 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. -- **Small:** Fedora with podman, networking and zram swap, for VMs only: no firmware or drivers for real hardware, no package manager or sshd. +- **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. +- **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. - **Hardened:** a firewall that drops all incoming traffic, and KSPP sysctls and kernel arguments. diff --git a/mkosi.conf b/mkosi.conf index fbb50f4..d6cd3c3 100644 --- a/mkosi.conf +++ b/mkosi.conf @@ -68,3 +68,34 @@ KernelInitrdModules= dm-verity erofs ext4 +# Kernel modules in the image: all but the hardware drivers, then the drivers of a VM (disks, +# network, screen) and of podman's networks. The last matching line wins. Keyboard, USB and a +# basic screen are built into the kernel. +KernelModules= + /* + -/drivers/* + /drivers/virtio/* + /drivers/block/* + /drivers/md/* + nvme + virtio_scsi + sd_mod + virtio_net + qemu_fw_cfg + bochs + virtio-gpu + veth + tun + macvlan + 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) +RemoveFiles= + /usr/lib/modules/*/System.map + /usr/lib/udev/hwdb.bin + /usr/lib/udev/hwdb.d + /usr/lib/systemd/system/systemd-homed* + /usr/lib/systemd/system/systemd-userdbd.* + /usr/lib/systemd/system/systemd-nsresourced.* diff --git a/mkosi.extra/usr/lib/sysctl.d/50-git-runner.conf b/mkosi.extra/usr/lib/sysctl.d/50-git-runner.conf index 64067fc..d448292 100644 --- a/mkosi.extra/usr/lib/sysctl.d/50-git-runner.conf +++ b/mkosi.extra/usr/lib/sysctl.d/50-git-runner.conf @@ -1,31 +1,31 @@ -# Hardening, mostly the KSPP recommendations that Talos also sets by default. -# Left out on purpose: user.max_user_namespaces=0 breaks podman in jobs, and kernel.modules_disabled=1 -# breaks loading the network modules podman needs. +# Kernel hardening, mostly the KSPP recommendations (Talos sets these too), and one limit raised +# for containers. Left out on purpose: user.max_user_namespaces=0 breaks podman in jobs, and +# kernel.modules_disabled=1 breaks loading the network modules podman needs. -# Hide kernel addresses in /proc and logs, even from root; they help exploits bypass KASLR. +# Hide kernel addresses (they help exploits bypass KASLR), even from root. kernel.kptr_restrict = 2 -# Only root may read the kernel log (it leaks addresses and hardware details). +# Only root may read the kernel log; it leaks addresses. kernel.dmesg_restrict = 1 -# No perf events for non-root users. Upstream kernels treat 3 like 2 (the strictest they know). +# No perf events for non-root users. kernel.perf_event_paranoid = 3 -# Harden the BPF JIT against JIT spraying, for every user. Small cost when BPF is used. +# Harden the BPF JIT against JIT spraying. net.core.bpf_jit_harden = 2 -# No BPF for non-root users, and it can't be switched back on at runtime (Fedora's default 2 can). +# No BPF for non-root users, and no switching it back on at runtime. kernel.unprivileged_bpf_disabled = 1 -# No kexec: nobody can boot another kernel without going through Secure Boot. +# No kexec: no booting another kernel past Secure Boot. kernel.kexec_load_disabled = 1 -# No core dumps of setuid programs; they can contain secrets. +# No core dumps of setuid programs; they can hold secrets. fs.suid_dumpable = 0 -# Don't load TTY line disciplines on demand; old ones have had exploitable bugs. +# No loading TTY line disciplines on demand; old ones had exploitable bugs. dev.tty.ldisc_autoload = 0 -# userfaultfd only for root; it is used to make kernel race exploits reliable. +# userfaultfd only for root; it makes kernel race exploits reliable. vm.unprivileged_userfaultfd = 0 -# Don't open FIFOs and regular files owned by someone else in sticky directories like /tmp. +# No opening FIFOs and files owned by others in sticky directories like /tmp. fs.protected_fifos = 2 fs.protected_regular = 2 -# A process may only ptrace its own descendants (gdb ./prog works, gdb -p doesn't). +# ptrace only on your own descendants. kernel.yama.ptrace_scope = 1 -# Performance: Fedora allows 128 inotify instances per user. Many containers (file watchers, -# systemd inside containers) run out of those; 8192 is common on Kubernetes nodes. +# Containers (file watchers, systemd in containers) run out of Fedora's 128 inotify instances +# per user; 8192 is common on Kubernetes nodes. fs.inotify.max_user_instances = 8192 diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service index 1d07be0..a155a55 100644 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service @@ -2,7 +2,8 @@ [Unit] Description=Gitea Actions runner Wants=network-online.target gitea-runner-images.service -After=network-online.target podman.socket gitea-runner-images.service +# gitea-runner-setup writes runner.env on first boot. +After=network-online.target podman.socket gitea-runner-images.service gitea-runner-setup.service Requires=podman.socket [Service] diff --git a/mkosi.extra/usr/lib/systemd/system/machine.slice.d/50-oomd.conf b/mkosi.extra/usr/lib/systemd/system/machine.slice.d/50-oomd.conf new file mode 100644 index 0000000..fb14de3 --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/machine.slice.d/50-oomd.conf @@ -0,0 +1,8 @@ +# systemd-oomd for job containers, which podman runs in this slice: when jobs run the VM out of +# memory, kill the job container responsible, before the VM thrashes on zram swap or the kernel's +# OOM killer picks the runner or podman. +[Slice] +# Memory pressure above 60% for 30s: kill the container reclaiming the most memory. +ManagedOOMMemoryPressure=kill +# Swap over 90% full: kill the container using the most swap. +ManagedOOMSwap=kill diff --git a/mkosi.extra/usr/lib/sysupdate.d/10-usr.transfer b/mkosi.extra/usr/lib/sysupdate.d/10-usr.transfer index 3b0d46b..0c5a562 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/10-usr.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/10-usr.transfer @@ -1,4 +1,5 @@ # Updates /usr: writes the next version to the unused /usr partition. +# Verify=no: releases are unsigned (no secrets in the repo); SHA256SUMS still checks each download. [Transfer] ProtectVersion=%A Verify=no diff --git a/mkosi.extra/usr/lib/sysupdate.d/11-usr-verity.transfer b/mkosi.extra/usr/lib/sysupdate.d/11-usr-verity.transfer index f24db6b..f91a799 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/11-usr-verity.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/11-usr-verity.transfer @@ -1,4 +1,4 @@ -# Updates the dm-verity hashes of /usr, next to 10-usr.transfer. +# Updates the dm-verity hashes of /usr, next to 10-usr.transfer (which explains Verify=no). [Transfer] ProtectVersion=%A Verify=no diff --git a/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer b/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer index 2b5d805..cba382f 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer @@ -1,4 +1,4 @@ -# Installs the next UKI, which systemd-boot boots by default. +# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-usr.transfer. [Transfer] ProtectVersion=%A Verify=no diff --git a/mkosi.images/job/mkosi.conf b/mkosi.images/job/mkosi.conf index 5d4389f..6cca6b5 100644 --- a/mkosi.images/job/mkosi.conf +++ b/mkosi.images/job/mkosi.conf @@ -23,3 +23,5 @@ Packages= zstd findutils WithDocs=no +# Also installs no translations; jobs that need them can install glibc-langpack-*. +Locale=C.UTF-8