Smaller image: fewer kernel modules and files, unused services removed, oomd for jobs
- Kernel modules: all but hardware drivers, plus the VM and podman network drivers. - Removed: System.map, the udev hwdb, and the homed/userdbd/nsresourced units. - Job image: no translations (Locale=C.UTF-8). - systemd-oomd kills the job container that runs the VM out of memory. - gitea-runner waits for first-boot setup instead of restarting every 10s. - Tighter comments in the sysctl config; Verify=no explained in the transfers. /usr: 367 -> 307 MB, update download 317 -> 260 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V27snrGfdvwU7pMNBiDpHv
This commit is contained in:
9 files changed
+64
-21
No files matched your search
@@ -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.
|
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.
|
- **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.
|
- **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.
|
- **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.
|
- **Hardened:** a firewall that drops all incoming traffic, and KSPP sysctls and kernel arguments.
|
||||||
|
|||||||
+31
@@ -68,3 +68,34 @@ KernelInitrdModules=
|
|||||||
dm-verity
|
dm-verity
|
||||||
erofs
|
erofs
|
||||||
ext4
|
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.*
|
||||||
@@ -1,31 +1,31 @@
|
|||||||
# Hardening, mostly the KSPP recommendations that Talos also sets by default.
|
# Kernel hardening, mostly the KSPP recommendations (Talos sets these too), and one limit raised
|
||||||
# Left out on purpose: user.max_user_namespaces=0 breaks podman in jobs, and kernel.modules_disabled=1
|
# for containers. Left out on purpose: user.max_user_namespaces=0 breaks podman in jobs, and
|
||||||
# breaks loading the network modules podman needs.
|
# 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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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_fifos = 2
|
||||||
fs.protected_regular = 2
|
fs.protected_regular = 2
|
||||||
# A process may only ptrace its own descendants (gdb ./prog works, gdb -p <other pid> doesn't).
|
# ptrace only on your own descendants.
|
||||||
kernel.yama.ptrace_scope = 1
|
kernel.yama.ptrace_scope = 1
|
||||||
|
|
||||||
# Performance: Fedora allows 128 inotify instances per user. Many containers (file watchers,
|
# Containers (file watchers, systemd in containers) run out of Fedora's 128 inotify instances
|
||||||
# systemd inside containers) run out of those; 8192 is common on Kubernetes nodes.
|
# per user; 8192 is common on Kubernetes nodes.
|
||||||
fs.inotify.max_user_instances = 8192
|
fs.inotify.max_user_instances = 8192
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Gitea Actions runner
|
Description=Gitea Actions runner
|
||||||
Wants=network-online.target gitea-runner-images.service
|
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
|
Requires=podman.socket
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
# Updates /usr: writes the next version to the unused /usr partition.
|
# 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]
|
[Transfer]
|
||||||
ProtectVersion=%A
|
ProtectVersion=%A
|
||||||
Verify=no
|
Verify=no
|
||||||
|
|||||||
@@ -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]
|
[Transfer]
|
||||||
ProtectVersion=%A
|
ProtectVersion=%A
|
||||||
Verify=no
|
Verify=no
|
||||||
|
|||||||
@@ -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]
|
[Transfer]
|
||||||
ProtectVersion=%A
|
ProtectVersion=%A
|
||||||
Verify=no
|
Verify=no
|
||||||
|
|||||||
@@ -23,3 +23,5 @@ Packages=
|
|||||||
zstd
|
zstd
|
||||||
findutils
|
findutils
|
||||||
WithDocs=no
|
WithDocs=no
|
||||||
|
# Also installs no translations; jobs that need them can install glibc-langpack-*.
|
||||||
|
Locale=C.UTF-8
|
||||||
Reference in new issue
Block a user