diff --git a/.gitea/workflows/os.yml b/.gitea/workflows/os.yml index b6c2487..84b2e43 100644 --- a/.gitea/workflows/os.yml +++ b/.gitea/workflows/os.yml @@ -31,11 +31,20 @@ jobs: zstd -q --rm -T0 -19 git-runner_*.root-*.raw qemu-img convert -c -O qcow2 "$(basename git-runner_*.efi .efi).raw" git-runner.qcow2 sha256sum git-runner_*.efi git-runner_*.root-*.raw.zst > SHA256SUMS + # Signs SHA256SUMS with the key whose public half is mkosi.extra/usr/lib/systemd/import-pubring.pgp. + - name: Sign + working-directory: mkosi.output + env: + KEY: ${{ secrets.SIGNING_KEY }} + run: | + export GNUPGHOME=$(mktemp -d) + gpg -q --batch --import <<< "$KEY" + gpg -q --batch -o SHA256SUMS.gpg --detach-sign SHA256SUMS # Replaces the previous version. SHA256SUMS goes last: until it's there, runners find no update. - name: Publish working-directory: mkosi.output run: | curl -fsS -H "$AUTH" -X DELETE "$PKG" || true - for f in $(awk '{print $2}' SHA256SUMS) git-runner.qcow2 SHA256SUMS; do + for f in git-runner_*.efi git-runner_*.root-*.raw.zst git-runner.qcow2 SHA256SUMS.gpg SHA256SUMS; do curl -fsS -o /dev/null -H "$AUTH" --upload-file "$f" "$PKG/$f" done diff --git a/README.md b/README.md index c7b15fd..13ba6f3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ 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 root 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, 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. - **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. diff --git a/mkosi.conf b/mkosi.conf index 076a46b..72a6b2b 100644 --- a/mkosi.conf +++ b/mkosi.conf @@ -24,7 +24,8 @@ Bootable=yes ExtraTrees=%O/job:/usr/lib/gitea-runner/job-image Bootloader=systemd-boot # - kernel-core no drivers or firmware beyond what VMs need -# - systemd-container systemd-pull, which systemd-sysupdate downloads with +# - systemd-container, gnupg2 systemd-pull, which systemd-sysupdate downloads with, and gpg, +# which it checks their signature with # - systemd-boot-unsigned the bootloader # - util-linux, shadow-utils console login and the first-boot setup # - podman, git-core the runner's jobs; git fetches actions @@ -38,6 +39,7 @@ Packages= systemd-networkd systemd-resolved systemd-container + gnupg2 systemd-boot-unsigned util-linux shadow-utils diff --git a/mkosi.extra/usr/lib/systemd/import-pubring.pgp b/mkosi.extra/usr/lib/systemd/import-pubring.pgp new file mode 100644 index 0000000..ab0c59e Binary files /dev/null and b/mkosi.extra/usr/lib/systemd/import-pubring.pgp differ diff --git a/mkosi.extra/usr/lib/sysupdate.d/10-root.transfer b/mkosi.extra/usr/lib/sysupdate.d/10-root.transfer index 090985d..c81c20a 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/10-root.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/10-root.transfer @@ -1,8 +1,9 @@ # Updates the root filesystem: writes the next version to the unused root partition. -# Verify=no: updates are unsigned (no secrets in the repo); SHA256SUMS still checks each download. +# Verify=yes: SHA256SUMS.gpg must be signed by a key in /usr/lib/systemd/import-pubring.pgp, and +# SHA256SUMS checks each download. [Transfer] ProtectVersion=%A -Verify=no +Verify=yes [Source] Type=url-file diff --git a/mkosi.extra/usr/lib/sysupdate.d/11-root-verity.transfer b/mkosi.extra/usr/lib/sysupdate.d/11-root-verity.transfer index 6b75396..3366bb5 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/11-root-verity.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/11-root-verity.transfer @@ -1,7 +1,7 @@ -# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=no). +# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=yes). [Transfer] ProtectVersion=%A -Verify=no +Verify=yes [Source] Type=url-file diff --git a/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer b/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer index e6fccf1..9ef5bdd 100644 --- a/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer +++ b/mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer @@ -1,7 +1,7 @@ -# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-root.transfer. +# Installs the next UKI, which systemd-boot boots by default. Verify=yes: see 10-root.transfer. [Transfer] ProtectVersion=%A -Verify=no +Verify=yes [Source] Type=url-file