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
+23
-18
@@ -1,29 +1,29 @@
|
|||||||
# git-runner OS image
|
# os.yml builds the OS image and publishes it as version "latest". VMs fetch
|
||||||
|
# the built images as updates (mkosi.extra/usr/lib/sysupdate.d). It runs on
|
||||||
|
# every push, weekly for package updates, and by hand for critical CVEs.
|
||||||
#
|
#
|
||||||
# Builds the OS image, with the job image inside, and publishes it as version "latest" of the
|
# Required values:
|
||||||
# generic package git-runner, where runners fetch their updates (mkosi.extra/usr/lib/sysupdate.d).
|
# - SECUREBOOT_KEY repository secret: the private key of mkosi.crt, written
|
||||||
# Runs on every push, weekly for Fedora updates, and by hand, on our own job image: if a change
|
# to mkosi.key.
|
||||||
# breaks it, build the fix locally (see README.md).
|
# - SIGNING_KEY repository secret: the armored private gpg key whose
|
||||||
|
# public half is mkosi.extra/usr/lib/systemd/
|
||||||
|
# import-pubring.pgp, which systemd-sysupdate checks.
|
||||||
name: os
|
name: os
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 2 * * 0" # weekly (Sunday), picks up Fedora updates
|
- cron: "0 2 * * 0"
|
||||||
workflow_dispatch: # run by hand, e.g. for a CVE
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
os:
|
os:
|
||||||
runs-on: linux
|
runs-on: linux
|
||||||
env:
|
|
||||||
PKG: ${{ github.server_url }}/api/packages/${{ github.repository_owner }}/generic/git-runner/latest
|
|
||||||
AUTH: "Authorization: token ${{ github.token }}"
|
|
||||||
steps:
|
steps:
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
run: dnf install -yq mkosi sbsigntools
|
run: dnf install -yq mkosi git-core zstd qemu-img
|
||||||
- name: Check out
|
- name: Check out
|
||||||
uses: builtin:checkout
|
uses: builtin:checkout
|
||||||
# Signs systemd-boot and the UKI for Secure Boot (mkosi.conf, [Validation]).
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
KEY: ${{ secrets.SECUREBOOT_KEY }}
|
KEY: ${{ secrets.SECUREBOOT_KEY }}
|
||||||
@@ -33,10 +33,10 @@ jobs:
|
|||||||
- name: Compress
|
- name: Compress
|
||||||
working-directory: mkosi.output
|
working-directory: mkosi.output
|
||||||
run: |
|
run: |
|
||||||
zstd -q --rm -T0 -19 git-runner_*.root-*.raw
|
zstd -q --rm -9 runneros_*.usr-*.raw
|
||||||
qemu-img convert -c -O qcow2 "$(basename git-runner_*.efi .efi).raw" git-runner.qcow2
|
- name: Checksum
|
||||||
sha256sum git-runner_*.efi git-runner_*.root-*.raw.zst > SHA256SUMS
|
working-directory: mkosi.output
|
||||||
# Signs SHA256SUMS with the key whose public half is mkosi.extra/usr/lib/systemd/import-pubring.pgp.
|
run: sha256sum runneros_*.efi runneros_*.usr-*.raw.zst > SHA256SUMS
|
||||||
- name: Sign
|
- name: Sign
|
||||||
working-directory: mkosi.output
|
working-directory: mkosi.output
|
||||||
env:
|
env:
|
||||||
@@ -45,11 +45,16 @@ jobs:
|
|||||||
export GNUPGHOME=$(mktemp -d)
|
export GNUPGHOME=$(mktemp -d)
|
||||||
gpg -q --batch --import <<< "$KEY"
|
gpg -q --batch --import <<< "$KEY"
|
||||||
gpg -q --batch -o SHA256SUMS.gpg --detach-sign SHA256SUMS
|
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: Build qcow2
|
||||||
|
working-directory: mkosi.output
|
||||||
|
run: qemu-img convert -c -O qcow2 "$(basename runneros_*.efi .efi).raw" runneros.qcow2
|
||||||
- name: Publish
|
- name: Publish
|
||||||
working-directory: mkosi.output
|
working-directory: mkosi.output
|
||||||
|
env:
|
||||||
|
PKG: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/runneros/latest
|
||||||
|
AUTH: "Authorization: token ${{ gitea.token }}"
|
||||||
run: |
|
run: |
|
||||||
curl -fsS -H "$AUTH" -X DELETE "$PKG" || true
|
curl -fsS -H "$AUTH" -X DELETE "$PKG" || true
|
||||||
for f in git-runner_*.efi git-runner_*.root-*.raw.zst git-runner.qcow2 SHA256SUMS.gpg SHA256SUMS; do
|
for f in runneros_*.efi runneros_*.usr-*.raw.zst runneros.qcow2 runneros_*.manifest SHA256SUMS.gpg SHA256SUMS; do
|
||||||
curl -fsS -o /dev/null -H "$AUTH" --upload-file "$f" "$PKG/$f"
|
curl -fsS -o /dev/null -H "$AUTH" --upload-file "$f" "$PKG/$f"
|
||||||
done
|
done
|
||||||
+4
-3
@@ -1,4 +1,5 @@
|
|||||||
# Build outputs.
|
|
||||||
mkosi.output/
|
|
||||||
# The Secure Boot private key (the SECUREBOOT_KEY secret); mkosi.crt is its certificate.
|
|
||||||
mkosi.key
|
mkosi.key
|
||||||
|
mkosi.output/
|
||||||
|
mkosi.cache/
|
||||||
|
mkosi.local.conf
|
||||||
|
mkosi.credentials/
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
# Agent notes
|
||||||
|
|
||||||
|
How to build and test this image as a coding agent. Follow [Style](#style) for
|
||||||
|
every change.
|
||||||
|
|
||||||
|
## Style
|
||||||
|
|
||||||
|
- Keep it simple. Prefer fewer files and fewer lines. Delete what isn't
|
||||||
|
needed. Write plain English in short sentences.
|
||||||
|
- Follow the defaults and conventions of each tool and language. Only set an
|
||||||
|
option when the default doesn't work.
|
||||||
|
- Each fact lives in one place. Elsewhere, refer to it instead of repeating it.
|
||||||
|
- Divide code and config into parts (files, directories, sections) that each
|
||||||
|
stand on their own: reading one part alone tells you what it does and why.
|
||||||
|
- Name each part for what it does. A part without a good name holds things
|
||||||
|
that don't belong together.
|
||||||
|
- A little copying beats a little dependency. Repeat a small piece rather than
|
||||||
|
share it or pull it in from elsewhere.
|
||||||
|
|
||||||
|
### File header
|
||||||
|
|
||||||
|
A file starts with a header, after the shebang if there is one. Leave it out
|
||||||
|
when the name already says it all, as with `.gitignore`. A part made of
|
||||||
|
many files, like a package, needs it in only one file. For example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/bin/bash
|
||||||
|
# mkosi.version prints the build time in UTC (YYYYMMDDhhmm) and the git
|
||||||
|
# commit. Every build gets a higher version than the one before, which is how
|
||||||
|
# systemd-sysupdate tells that an update is newer. The commit tells which
|
||||||
|
# source an image was built from.
|
||||||
|
```
|
||||||
|
|
||||||
|
- The first sentence starts with the name of the part the file is, and says
|
||||||
|
what it does. That is the name the language or tool uses for it, such as a
|
||||||
|
file name or a package name.
|
||||||
|
- The rest says why, naming the files it works with by path.
|
||||||
|
|
||||||
|
Files that can't hold comments (JSON, `subuid`, `machine-id`) are explained in
|
||||||
|
the file that uses them.
|
||||||
|
|
||||||
|
### Comments
|
||||||
|
|
||||||
|
- Explain why, not what. Leave out comments that only repeat the code. Try to
|
||||||
|
write clean code instead of comments.
|
||||||
|
- Write full sentences that start with the name of what they describe:
|
||||||
|
`# ManifestFormat lists the packages and versions in the image.` or
|
||||||
|
`# link prints the tmpfiles line for /etc/$1.`
|
||||||
|
- Put a comment right above the line or block it is about. A short note on
|
||||||
|
one line may go at the end of that line, as a full sentence too.
|
||||||
|
- Separate paragraphs and lists with a line holding only the comment
|
||||||
|
character.
|
||||||
|
- Wrap comments at 80 columns.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
`mkosi vm` boots the image in qemu. It needs systemd on the host, so run mkosi
|
||||||
|
in a privileged podman container that boots systemd:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
podman build -t mkosi-vm - <<'END'
|
||||||
|
FROM registry.fedoraproject.org/fedora:45
|
||||||
|
RUN dnf install -y mkosi git-core qemu-system-x86-core edk2-ovmf swtpm-tools \
|
||||||
|
virtiofsd openssl
|
||||||
|
CMD ["/sbin/init"]
|
||||||
|
END
|
||||||
|
podman run -d --name mkosi --privileged --systemd=always -v <repo>:/repo \
|
||||||
|
-v mkosi-cache:/root/.cache/mkosi -v mkosi-work:/var/tmp -w /repo mkosi-vm
|
||||||
|
podman exec mkosi mkdir -p mkosi.cache
|
||||||
|
podman exec -d -t mkosi sh -c 'mkosi -i -f --kernel-command-line-extra="\
|
||||||
|
console=ttyS0 systemd.journald.forward_to_console=1" vm -- \
|
||||||
|
-serial chardev:console > mkosi.output/vm.log 2>&1'
|
||||||
|
```
|
||||||
|
|
||||||
|
- Only CI has `mkosi.key`. For a test key, make one as in
|
||||||
|
[README.md](README.md#development) and point mkosi.local.conf at it:
|
||||||
|
`SecureBootKey=`, `SignExpectedPcrKey=` and `VerityKey=`, and their
|
||||||
|
`*Certificate=`, in `[Validation]`.
|
||||||
|
- To register the test VM, register on the host with
|
||||||
|
`gitea-runner register --no-interactive --instance <url> --token <token>`
|
||||||
|
and pass the `.runner` it writes as a tmpfiles.extra credential:
|
||||||
|
`printf 'f~ /var/lib/gitea-runner/.runner 0600 - - - %s' "$(base64 -w0
|
||||||
|
.runner)" > mkosi.credentials/tmpfiles.extra`. mkosi passes each file in
|
||||||
|
mkosi.credentials/ as a credential of its name. The runner then shows up in
|
||||||
|
Gitea, and its jobs show whether it works.
|
||||||
|
- `mkosi -i` keeps the image with its packages installed in `mkosi.cache/`.
|
||||||
|
Rebuilds start from it and skip installing packages.
|
||||||
|
- The volume `mkosi-work` keeps mkosi's workspace in /var/tmp off overlayfs.
|
||||||
|
When mkosi copies files with SELinux labels to overlayfs, it drops all
|
||||||
|
xattrs, such as file capabilities.
|
||||||
|
- `mkosi vm` needs a terminal, hence `-d -t`. Its console goes to the log.
|
||||||
|
- The console of `mkosi vm` is hvc0, which the kernel can only use once the
|
||||||
|
initrd loads its driver. `console=ttyS0` also sends the kernel log to the
|
||||||
|
serial port, and `-serial chardev:console` sends that port to the same log.
|
||||||
|
The log then shows early errors too, such as a panic or an initrd that
|
||||||
|
can't find /usr. `systemd.journald.forward_to_console=1` adds the journal,
|
||||||
|
as the image has no sshd. Arguments after `--` go to qemu.
|
||||||
|
|
||||||
|
`mkosi.version` gives each run a new version, so `mkosi vm` without `-f` fails
|
||||||
|
with "has not been built yet". To boot an existing build again, pin its version
|
||||||
|
from `mkosi.output/runneros_<version>.raw`:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkosi --image-version 202611221555.0569bce vm
|
||||||
|
```
|
||||||
@@ -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.
|
- **Read-only OS:** `/usr` is read-only. Secure Boot verifies the UKI (kernel,
|
||||||
- **Stateless:** container storage is wiped on every boot.
|
initrd and command line), which holds the dm-verity hash that verifies
|
||||||
- **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.
|
`/usr`.
|
||||||
- **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.
|
- **Encrypted with a TPM:** everything that isn't read-only, such as `/etc`
|
||||||
- **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.
|
and `/var`, is encrypted. The TPM unlocks it only for correctly signed UKIs.
|
||||||
- **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.
|
- **Jobs in containers:** each job runs in its own privileged container on
|
||||||
- **Hardened:** a firewall that drops all incoming traffic, and KSPP sysctls and kernel arguments.
|
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
|
## 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 |
|
It registers under the hostname, `runneros-` and four hex digits, and starts.
|
||||||
|---|---|
|
|
||||||
| `linux` | Our job image (`mkosi.images/job/`): git, Node.js, dnf and podman (also as `docker`) |
|
To start over, run `systemctl start factory-reset.target` as root. It reboots
|
||||||
| `fedora` | Plain Fedora |
|
and wipes the root partition (`/etc` and `/var`), and the VM sets itself up as
|
||||||
|
at first boot.
|
||||||
|
|
||||||
## Development
|
## 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
|
```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 (`runneros_<version>.raw`) and the
|
||||||
|
UKI and /usr partitions that make up an update. To boot a test VM, see
|
||||||
`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):
|
[AGENTS.md](AGENTS.md#testing).
|
||||||
|
|
||||||
```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
|
|
||||||
```
|
|
||||||
+79
-81
@@ -1,88 +1,87 @@
|
|||||||
# git-runner: a Fedora VM image that runs the Gitea Actions runner, built with mkosi.
|
# mkosi.conf builds runneros, a Fedora VM image that runs a Gitea Actions
|
||||||
# mkosi.extra/ is copied to /, mkosi.repart/ defines the disk, mkosi.prepare adds the runner,
|
# runner. The image holds a read-only /usr. The root filesystem, which holds
|
||||||
# mkosi.images/job/ is the job image.
|
# the state, is made at first boot.
|
||||||
# The root filesystem, /etc included, is read-only and replaced whole by updates; all state
|
#
|
||||||
# lives on /var.
|
# The other parts of the build:
|
||||||
|
# - mkosi.extra/ is copied to /.
|
||||||
[Config]
|
# - mkosi.repart/ defines the disk image: the ESP and the /usr partitions.
|
||||||
Dependencies=job
|
# - mkosi.extra/usr/lib/repart.d/ makes the root partition at first boot.
|
||||||
|
# - mkosi.prepare installs the runner, which Fedora doesn't package.
|
||||||
|
# - mkosi.finalize keeps /etc in /usr/share/factory/etc.
|
||||||
|
# - mkosi.version gives each build its version.
|
||||||
|
|
||||||
[Distribution]
|
[Distribution]
|
||||||
Distribution=fedora
|
Distribution=fedora
|
||||||
Release=45
|
Release=45
|
||||||
|
|
||||||
[Output]
|
[Output]
|
||||||
Format=disk
|
# Output writes runneros_<version>.* to mkosi.output/. The UKI and /usr
|
||||||
ImageId=git-runner
|
# partitions are split into the files of an update.
|
||||||
|
ImageId=runneros
|
||||||
OutputDirectory=mkosi.output
|
OutputDirectory=mkosi.output
|
||||||
# The UKI and root partitions are published as updates (systemd-sysupdate).
|
|
||||||
SplitArtifacts=uki,partitions
|
SplitArtifacts=uki,partitions
|
||||||
|
ManifestFormat=json
|
||||||
|
|
||||||
[Content]
|
[Content]
|
||||||
Bootable=yes
|
# Content sets what goes into the image:
|
||||||
# The job image (mkosi.images/job/); gitea-runner-images.service loads it at boot.
|
# - Hostname is runneros- and four hex digits of the machine ID. It is also
|
||||||
ExtraTrees=%O/job:/usr/lib/gitea-runner/job-image
|
# the name the runner registers with.
|
||||||
Bootloader=systemd-boot
|
# - WithDocs leaves out man pages. The image has no man to read them.
|
||||||
# - kernel-core no drivers or firmware beyond what VMs need
|
# - Packages lists the packages installed into the image.
|
||||||
# - systemd-container, gnupg2 systemd-pull, which systemd-sysupdate downloads with, and gpg,
|
# - UnifiedKernelImageFormat names the UKI runneros_<version>.efi, which
|
||||||
# which it checks their signature with
|
# matches the MatchPattern= of mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer.
|
||||||
# - systemd-boot-unsigned the bootloader
|
# - KernelCommandLine:
|
||||||
# - util-linux, shadow-utils console login and the first-boot setup
|
# - rw has the initrd mount the root filesystem writable. It finds it by its
|
||||||
# - podman, git-core the runner's jobs; git fetches actions
|
# partition type (mkosi.extra/usr/lib/repart.d/50-root.conf).
|
||||||
# - nftables-services the firewall
|
# - The image policy only accepts an encrypted root filesystem (or none, at
|
||||||
# - zram-generator-defaults compressed swap in RAM
|
# first boot) and a verity-checked /usr. Otherwise someone with the disk
|
||||||
Packages=
|
# could swap in a plain root filesystem. Our UKI would boot it, and their
|
||||||
kernel-core
|
# code could unseal the key of the real one.
|
||||||
systemd
|
# - The root btrfs keeps one copy of its metadata instead of two (DUP,
|
||||||
dbus-broker
|
# mkfs.btrfs's default). On a VM disk a second copy adds little.
|
||||||
systemd-udev
|
# - The mount rate limit is raised from 5, which holds back mounts at boot
|
||||||
systemd-networkd
|
# and delays / and /usr by up to a second each.
|
||||||
systemd-resolved
|
# - KernelInitrdModules are what the initrd needs to find the disks of a VM,
|
||||||
systemd-container
|
# mount /usr and unlock the root filesystem. The kernel has virtio_blk,
|
||||||
gnupg2
|
# sd_mod, the TPM drivers and btrfs built in.
|
||||||
systemd-boot-unsigned
|
# - KernelModules keeps all modules but the hardware drivers, then adds back
|
||||||
util-linux
|
# the drivers a VM needs (disks, network, screen) and those of podman's
|
||||||
shadow-utils
|
# networks (veth, tun). The last matching line wins. Keyboard, USB and a
|
||||||
podman
|
# basic screen are built into the kernel.
|
||||||
git-core
|
# - RemoveFiles drops System.map, which is only for debugging the kernel, and
|
||||||
nftables-services
|
# the udev hwdb, which holds hardware names and quirks a VM doesn't need.
|
||||||
zram-generator-defaults
|
# Without hwdb.d, systemd-hwdb-update can't build it again at boot.
|
||||||
|
Hostname=runneros-????
|
||||||
WithDocs=no
|
WithDocs=no
|
||||||
Locale=C.UTF-8
|
Packages=
|
||||||
# The UKI's file name in the ESP, as systemd-sysupdate names the ones it installs.
|
kernel-core # Unlike kernel, this has no extra drivers.
|
||||||
|
systemd # The init and service manager is PID 1.
|
||||||
|
dbus-broker # D-Bus serves systemd and podman.
|
||||||
|
systemd-udev # Udev, sysupdate, repart, cryptsetup are here.
|
||||||
|
systemd-networkd # DHCP runs on every network card.
|
||||||
|
systemd-resolved # DNS names are resolved here.
|
||||||
|
systemd-container # Sysupdate needs its systemd-pull and gnupg2.
|
||||||
|
systemd-boot-unsigned # mkosi signs this boot loader.
|
||||||
|
util-linux # The console login needs its login.
|
||||||
|
systemd-pam # Logins get a session.
|
||||||
|
zram-generator-defaults # Swap is compressed in RAM.
|
||||||
|
podman # The runner runs its jobs in containers.
|
||||||
|
curl
|
||||||
|
procps-ng
|
||||||
|
iproute
|
||||||
UnifiedKernelImageFormat=%i_%v
|
UnifiedKernelImageFormat=%i_%v
|
||||||
# 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), freeing memory unused for an hour (damon_reclaim, in
|
|
||||||
# µs; the watermarks make it run whatever memory is free), so the host can take it back
|
|
||||||
# (virtio-balloon free page reporting), and KSPP hardening (the last four).
|
|
||||||
KernelCommandLine=
|
KernelCommandLine=
|
||||||
console=tty0
|
|
||||||
console=ttyS0,115200n8
|
|
||||||
quiet
|
quiet
|
||||||
systemd.machine_id=firmware
|
rw
|
||||||
systemd.firstboot=no
|
systemd.image_policy=root=encrypted+absent:usr=verity:esp=unprotected
|
||||||
damon_reclaim.enabled=Y
|
systemd.setenv=SYSTEMD_REPART_MKFS_OPTIONS_BTRFS=--metadata=single
|
||||||
damon_reclaim.min_age=3600000000
|
SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50
|
||||||
damon_reclaim.wmarks_high=1000
|
|
||||||
damon_reclaim.wmarks_mid=999
|
|
||||||
damon_reclaim.wmarks_low=0
|
|
||||||
slab_nomerge
|
|
||||||
init_on_alloc=1
|
|
||||||
randomize_kstack_offset=on
|
|
||||||
page_alloc.shuffle=1
|
|
||||||
# Kernel modules in the initrd: only what finds and mounts the disks of a VM.
|
|
||||||
KernelInitrdModules=
|
KernelInitrdModules=
|
||||||
virtio_blk
|
|
||||||
virtio_scsi
|
virtio_scsi
|
||||||
sd_mod
|
|
||||||
nvme
|
nvme
|
||||||
dm-verity
|
dm-verity
|
||||||
|
dm-crypt
|
||||||
erofs
|
erofs
|
||||||
xfs
|
|
||||||
# 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=
|
KernelModules=
|
||||||
/*
|
/*
|
||||||
-/drivers/*
|
-/drivers/*
|
||||||
@@ -91,31 +90,30 @@ KernelModules=
|
|||||||
/drivers/md/*
|
/drivers/md/*
|
||||||
nvme
|
nvme
|
||||||
virtio_scsi
|
virtio_scsi
|
||||||
sd_mod
|
|
||||||
virtio_net
|
virtio_net
|
||||||
qemu_fw_cfg
|
qemu_fw_cfg
|
||||||
bochs
|
bochs
|
||||||
virtio-gpu
|
virtio-gpu
|
||||||
veth
|
veth
|
||||||
tun
|
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
|
|
||||||
RemoveFiles=
|
RemoveFiles=
|
||||||
/usr/lib/modules/*/System.map
|
/usr/lib/modules/*/System.map
|
||||||
/usr/lib/udev/hwdb.bin
|
/usr/lib/udev/hwdb.bin
|
||||||
/usr/lib/udev/hwdb.d
|
/usr/lib/udev/hwdb.d
|
||||||
/usr/lib/systemd/system/systemd-homed*
|
|
||||||
/usr/lib/systemd/system/systemd-userdbd.*
|
|
||||||
/usr/lib/systemd/system/systemd-nsresourced.*
|
|
||||||
|
|
||||||
[Validation]
|
[Validation]
|
||||||
# Signs systemd-boot and the UKI for Secure Boot, and puts our keys on the ESP, where systemd-boot
|
# Validation signs the boot chain with mkosi.key, so the TPM unlocks the root
|
||||||
# enrolls them at first boot if the firmware is in setup mode (no keys enrolled; in Proxmox, an EFI
|
# filesystem only for our UKIs.
|
||||||
# disk without pre-enrolled keys). mkosi.crt is the certificate; mkosi.key, its private key, is the
|
|
||||||
# SECUREBOOT_KEY secret of this repository, which the os workflow writes to mkosi.key.
|
|
||||||
SecureBoot=yes
|
SecureBoot=yes
|
||||||
SecureBootKey=mkosi.key
|
SignExpectedPcr=yes
|
||||||
SecureBootCertificate=mkosi.crt
|
|
||||||
|
[Runtime]
|
||||||
|
# Runtime sets up the test VM of mkosi vm. Each run boots a fresh copy, with
|
||||||
|
# root password root and no first boot questions. It has enough memory and
|
||||||
|
# disk to build this image in a job.
|
||||||
|
Ephemeral=yes
|
||||||
|
CPUs=4
|
||||||
|
RAM=6G
|
||||||
|
RuntimeSize=40G
|
||||||
|
Credentials=passwd.plaintext-password.root=root
|
||||||
|
KernelCommandLineExtra=systemd.firstboot=no
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# /var, the only writable partition (mkosi.repart/30-var.conf). Grows to fill its partition at boot.
|
|
||||||
PARTLABEL=var /var xfs x-systemd.growfs 0 0
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# config.yaml configures the runner (gitea-runner.service). It lists only what
|
||||||
|
# differs from the defaults, which `gitea-runner config generate` prints.
|
||||||
|
#
|
||||||
|
# The image links it into /etc read-only
|
||||||
|
# (mkosi.extra/usr/lib/tmpfiles.d/factory-etc.conf). To change it on one
|
||||||
|
# machine, replace the link with a copy. Updates then no longer change it.
|
||||||
|
runner:
|
||||||
|
# file is where `gitea-runner register` keeps the registration, wherever it
|
||||||
|
# runs. gitea-runner.path starts the runner once it is there.
|
||||||
|
file: /var/lib/gitea-runner/.runner
|
||||||
|
# shutdown_timeout lets running jobs finish when the runner stops, as it
|
||||||
|
# does before an update reboots the machine.
|
||||||
|
shutdown_timeout: 1h
|
||||||
|
labels:
|
||||||
|
- linux:docker://quay.io/fedora/fedora:45
|
||||||
|
container:
|
||||||
|
# privileged lets jobs build OS images, as this repository's own workflow
|
||||||
|
# does. A job can then take over the machine, so only run jobs you trust.
|
||||||
|
privileged: true
|
||||||
|
# docker_host "-" keeps podman's socket out of the jobs.
|
||||||
|
docker_host: "-"
|
||||||
|
# options gives each job a /var/tmp volume. On the container's overlayfs,
|
||||||
|
# mkosi loses the xattrs of the files it copies, such as file capabilities.
|
||||||
|
options: --volume /var/tmp
|
||||||
Whitespace-only changes.
@@ -1,33 +0,0 @@
|
|||||||
# The runner's configuration (gitea-runner.service).
|
|
||||||
# Every option: `gitea-runner config generate`.
|
|
||||||
runner:
|
|
||||||
# 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
|
|
||||||
envs:
|
|
||||||
# podman in jobs: the job's own storage plus the shared base images (see volumes below).
|
|
||||||
CONTAINERS_STORAGE_CONF: /usr/lib/gitea-runner/job/storage.conf
|
|
||||||
labels:
|
|
||||||
# Our job image (mkosi.images/job), loaded from /usr at boot by gitea-runner-images.service.
|
|
||||||
- "linux:docker://localhost/git-runner-job:latest"
|
|
||||||
# Plain Fedora.
|
|
||||||
- "fedora:docker://quay.io/fedora/fedora:45"
|
|
||||||
container:
|
|
||||||
# Jobs build OS images, which needs root: they run privileged on root's podman.
|
|
||||||
privileged: true
|
|
||||||
# podman can't keep its storage, or build contexts, on the job's own overlay root.
|
|
||||||
options: --volume /var/lib/containers --volume /var/tmp
|
|
||||||
# Jobs run their own podman, never the runner's.
|
|
||||||
docker_host: "-"
|
|
||||||
volumes:
|
|
||||||
# Base images, pulled at boot by gitea-runner-images.service; podman in jobs uses them read-only.
|
|
||||||
- /var/lib/containers/base-images:/var/lib/base-images:ro
|
|
||||||
# podman storage settings for jobs (see the file).
|
|
||||||
- /usr/lib/gitea-runner/job:/usr/lib/gitea-runner/job:ro
|
|
||||||
# Images are pulled when missing: our job image never is, fedora once per boot.
|
|
||||||
force_pull: false
|
|
||||||
cache:
|
|
||||||
# Jobs reach the cache on the host through their bridge; the firewall allows this port.
|
|
||||||
host: host.containers.internal
|
|
||||||
port: 8088
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# Firewall: drop all incoming traffic except replies, loopback, ICMP and DHCPv6.
|
|
||||||
# Loaded by nftables.service. Jobs live on podman bridges (podman*): they may reach the
|
|
||||||
# internet, DNS on their bridge, and the runner's cache server (config.yaml), nothing else here.
|
|
||||||
destroy table inet firewall
|
|
||||||
table inet firewall {
|
|
||||||
chain input {
|
|
||||||
type filter hook input priority filter; policy drop;
|
|
||||||
ct state established,related accept
|
|
||||||
ct state invalid drop
|
|
||||||
iif lo accept
|
|
||||||
meta l4proto { icmp, ipv6-icmp } accept
|
|
||||||
ip6 saddr fe80::/10 udp dport 546 accept
|
|
||||||
iifname "podman*" meta l4proto { tcp, udp } th dport 53 accept
|
|
||||||
iifname "podman*" tcp dport 8088 accept
|
|
||||||
}
|
|
||||||
chain forward {
|
|
||||||
type filter hook forward priority filter; policy drop;
|
|
||||||
ct state established,related accept
|
|
||||||
ct state invalid drop
|
|
||||||
iifname "podman*" accept
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# podman storage in jobs (CONTAINERS_STORAGE_CONF). The job's own images go to the /var/lib/containers
|
|
||||||
# volume; the base images the host pulls at boot are shared read-only, so jobs don't download them.
|
|
||||||
[storage]
|
|
||||||
driver = "overlay"
|
|
||||||
graphroot = "/var/lib/containers/storage"
|
|
||||||
runroot = "/run/containers/storage"
|
|
||||||
|
|
||||||
[storage.options]
|
|
||||||
additionalimagestores = ["/var/lib/base-images"]
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# 50-root.conf makes the root filesystem at first boot, in the free space after
|
||||||
|
# /usr, and grows it with the disk. It holds all state: /etc and /var.
|
||||||
|
#
|
||||||
|
# The key is in the TPM, sealed to the signed PCR 11 policy of our UKIs
|
||||||
|
# (SignExpectedPcr= in mkosi.conf).
|
||||||
|
[Partition]
|
||||||
|
Type=root
|
||||||
|
Format=btrfs
|
||||||
|
Encrypt=tpm2
|
||||||
|
FactoryReset=yes
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# 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
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
# 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 (they help exploits bypass KASLR), even from root.
|
|
||||||
kernel.kptr_restrict = 2
|
|
||||||
# Only root may read the kernel log; it leaks addresses.
|
|
||||||
kernel.dmesg_restrict = 1
|
|
||||||
# No perf events for non-root users.
|
|
||||||
kernel.perf_event_paranoid = 3
|
|
||||||
# Harden the BPF JIT against JIT spraying.
|
|
||||||
net.core.bpf_jit_harden = 2
|
|
||||||
# No BPF for non-root users, and no switching it back on at runtime.
|
|
||||||
kernel.unprivileged_bpf_disabled = 1
|
|
||||||
# No kexec: no booting another kernel past Secure Boot.
|
|
||||||
kernel.kexec_load_disabled = 1
|
|
||||||
# No core dumps of setuid programs; they can hold secrets.
|
|
||||||
fs.suid_dumpable = 0
|
|
||||||
# No loading TTY line disciplines on demand; old ones had exploitable bugs.
|
|
||||||
dev.tty.ldisc_autoload = 0
|
|
||||||
# userfaultfd only for root; it makes kernel race exploits reliable.
|
|
||||||
vm.unprivileged_userfaultfd = 0
|
|
||||||
# No opening FIFOs and files owned by others in sticky directories like /tmp.
|
|
||||||
fs.protected_fifos = 2
|
|
||||||
fs.protected_regular = 2
|
|
||||||
# ptrace only on your own descendants.
|
|
||||||
kernel.yama.ptrace_scope = 1
|
|
||||||
|
|
||||||
# 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
|
|
||||||
@@ -1,12 +1,8 @@
|
|||||||
# DHCP on the real network cards. Kind=!* skips virtual links like the veths of podman's bridges,
|
# 80-dhcp.network turns on DHCP on the real network cards. Kind=!* skips
|
||||||
# which netavark manages.
|
# virtual links such as those of containers.
|
||||||
[Match]
|
[Match]
|
||||||
Type=ether
|
Type=ether
|
||||||
Kind=!*
|
Kind=!*
|
||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
DHCP=yes
|
DHCP=yes
|
||||||
|
|
||||||
[DHCPv4]
|
|
||||||
# The hostname is the runner's name (gitea-runner.service), not the DHCP server's.
|
|
||||||
UseHostname=no
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# Services enabled in the image (mkosi runs systemctl preset-all). Fedora disables getty@.service, the
|
|
||||||
# login on the screen (tty1, and tty2-6 through its autovt@ alias); this file sorts first, so it wins.
|
|
||||||
enable systemd-networkd.service
|
|
||||||
enable systemd-resolved.service
|
|
||||||
enable nftables.service
|
|
||||||
enable podman.socket
|
|
||||||
enable getty@.service
|
|
||||||
enable gitea-runner-setup@.service tty1 ttyS0
|
|
||||||
enable etc-shadow.mount
|
|
||||||
enable gitea-runner.service
|
|
||||||
enable systemd-sysupdate-update.timer
|
|
||||||
enable systemd-sysupdate-reboot.timer
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
# 50-runneros.preset enables the services of the image. PID 1 applies it at
|
||||||
|
# first boot, so a change reaches existing machines only after a factory reset.
|
||||||
|
# It sorts before Fedora's presets, so it wins where they disagree.
|
||||||
|
|
||||||
|
# systemd-networkd is disabled by Fedora, which uses NetworkManager.
|
||||||
|
enable systemd-networkd.service
|
||||||
|
|
||||||
|
# gitea-runner.path starts the runner once it is registered.
|
||||||
|
enable gitea-runner.path
|
||||||
|
disable gitea-runner.service
|
||||||
|
|
||||||
|
# getty@.service is the login on the screen, which Fedora disables.
|
||||||
|
enable getty@.service
|
||||||
|
enable systemd-sysupdate-update.timer
|
||||||
|
enable systemd-sysupdate-reboot.timer
|
||||||
|
|
||||||
|
# authselect-apply-changes fails, because /etc/authselect is on read-only /usr.
|
||||||
|
disable authselect-apply-changes.service
|
||||||
|
|
||||||
|
# systemd-homed, systemd-userdbd and systemd-nsresourced are unused here.
|
||||||
|
disable systemd-homed.service
|
||||||
|
disable systemd-homed-activate.service
|
||||||
|
disable systemd-userdbd.socket
|
||||||
|
disable systemd-nsresourced.socket
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# 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,18 +0,0 @@
|
|||||||
# Before the runner starts: loads our job image from /usr into podman's storage (wiped at every
|
|
||||||
# boot), and pulls the base images that jobs share read-only (see /usr/lib/gitea-runner/config.yaml),
|
|
||||||
# so no job uses them while they change. Hosts reboot to update, so this runs about as often as
|
|
||||||
# there are updates.
|
|
||||||
[Unit]
|
|
||||||
Description=Images for Gitea Actions jobs
|
|
||||||
Wants=network-online.target
|
|
||||||
After=network-online.target
|
|
||||||
Before=gitea-runner.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
Environment=IMAGES=/var/lib/containers/base-images
|
|
||||||
ExecStart=/bin/sh -c 'podman tag "$(podman pull -q oci:/usr/lib/gitea-runner/job-image)" localhost/git-runner-job:latest'
|
|
||||||
# Without network the runner still starts, with the images it has.
|
|
||||||
ExecStart=-/usr/bin/podman --root ${IMAGES} --runroot /run/containers/base-images pull -q --policy newer quay.io/fedora/fedora:45
|
|
||||||
ExecStart=/usr/bin/podman --root ${IMAGES} --runroot /run/containers/base-images image prune -f
|
|
||||||
TimeoutStartSec=30min
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# First boot: asks for the root password and the runner's registration, on the screen (tty1) and
|
|
||||||
# the serial console (ttyS0) at once; whichever is answered first stops the other.
|
|
||||||
[Unit]
|
|
||||||
Description=Gitea runner first-boot setup on %I
|
|
||||||
ConditionPathExists=!/var/lib/gitea-runner/runner.env
|
|
||||||
Before=getty@%i.service serial-getty@%i.service kmsconvt@%i.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/usr/libexec/gitea-runner-setup
|
|
||||||
StandardInput=tty
|
|
||||||
StandardOutput=tty
|
|
||||||
TTYPath=/dev/%I
|
|
||||||
TTYReset=yes
|
|
||||||
TTYVHangup=yes
|
|
||||||
# Answering on one console stops the setup on the other (SIGTERM), which is no failure.
|
|
||||||
SuccessExitStatus=SIGTERM
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# gitea-runner.path starts the runner once it is registered, so a new machine
|
||||||
|
# waits for `gitea-runner -c /etc/gitea-runner/config.yaml register`.
|
||||||
|
[Unit]
|
||||||
|
Description=Start the Gitea runner once registered
|
||||||
|
|
||||||
|
[Path]
|
||||||
|
PathExists=/var/lib/gitea-runner/.runner
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -1,28 +1,20 @@
|
|||||||
# The Gitea Actions runner. Registers itself on its first start.
|
# gitea-runner.service runs the Gitea Actions runner, which runs each job in a
|
||||||
|
# container on root's podman. gitea-runner.path starts it once it is
|
||||||
|
# registered. It runs as root: whoever has podman's socket is root anyway.
|
||||||
|
#
|
||||||
|
# TimeoutStopSec is a bit longer than runner.shutdown_timeout in
|
||||||
|
# /etc/gitea-runner/config.yaml, so running jobs can finish on stop.
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Gitea Actions runner
|
Description=Gitea Actions runner
|
||||||
Wants=network-online.target gitea-runner-images.service
|
Wants=network-online.target
|
||||||
# gitea-runner-setup writes runner.env on first boot.
|
After=network-online.target podman.socket
|
||||||
After=network-online.target podman.socket gitea-runner-images.service
|
|
||||||
After=gitea-runner-setup@tty1.service gitea-runner-setup@ttyS0.service
|
|
||||||
Requires=podman.socket
|
Requires=podman.socket
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
# Runs as root: it drives root's podman, which is root access anyway. The jobs it starts never
|
# HOME holds the cache of actions/cache, next to the registration.
|
||||||
# get the socket (see config.yaml).
|
|
||||||
WorkingDirectory=/var/lib/gitea-runner
|
|
||||||
EnvironmentFile=/var/lib/gitea-runner/runner.env
|
|
||||||
Environment=HOME=/var/lib/gitea-runner
|
Environment=HOME=/var/lib/gitea-runner
|
||||||
Environment=DOCKER_HOST=unix:///run/podman/podman.sock
|
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.
|
ExecStart=/usr/bin/gitea-runner -c /etc/gitea-runner/config.yaml daemon
|
||||||
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
|
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
# A bit longer than runner.shutdown_timeout, so running jobs can finish on stop.
|
|
||||||
TimeoutStopSec=35min
|
|
||||||
RestartSec=10s
|
RestartSec=10s
|
||||||
|
TimeoutStopSec=65min
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
# 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,6 +0,0 @@
|
|||||||
# Load our firewall (/usr/lib/gitea-runner/firewall.nft) instead of /etc/sysconfig/nftables.conf.
|
|
||||||
[Service]
|
|
||||||
ExecStart=
|
|
||||||
ExecStart=/usr/sbin/nft -f /usr/lib/gitea-runner/firewall.nft
|
|
||||||
ExecReload=
|
|
||||||
ExecReload=/usr/sbin/nft -f /usr/lib/gitea-runner/firewall.nft
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
# Daily at about 04:10, reboot into a downloaded update. Stop the runner first: it takes no new
|
# drain.conf stops the runner before an update reboots the machine, so running
|
||||||
# jobs and lets running ones finish (runner.shutdown_timeout).
|
# jobs can finish first (TimeoutStopSec= of gitea-runner.service). A plain
|
||||||
|
# reboot would stop the job containers at the same time as the runner.
|
||||||
[Service]
|
[Service]
|
||||||
ExecStartPre=/bin/sh -c '/usr/lib/systemd/systemd-sysupdate pending || exit 0; systemctl stop gitea-runner'
|
ExecStartPre=/bin/sh -c '/usr/lib/systemd/systemd-sysupdate pending || exit 0; systemctl stop gitea-runner.service'
|
||||||
TimeoutStartSec=40min
|
TimeoutStartSec=70min
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# Updates the root filesystem: writes the next version to the unused root partition.
|
|
||||||
# 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=yes
|
|
||||||
|
|
||||||
[Source]
|
|
||||||
Type=url-file
|
|
||||||
Path=https://git.plabble.org/api/packages/Job79/generic/git-runner/latest/
|
|
||||||
MatchPattern=git-runner_@v.root-%a.@u.raw.zst
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
Type=partition
|
|
||||||
Path=auto
|
|
||||||
MatchPattern=git-runner_@v
|
|
||||||
MatchPartitionType=root
|
|
||||||
PartitionFlags=0
|
|
||||||
ReadOnly=1
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# 10-usr.transfer writes the next version of /usr to the inactive /usr
|
||||||
|
# partition.
|
||||||
|
#
|
||||||
|
# systemd-sysupdate requires SHA256SUMS.gpg to be signed by a key in
|
||||||
|
# /usr/lib/systemd/import-pubring.pgp, and SHA256SUMS checks each download.
|
||||||
|
[Transfer]
|
||||||
|
ProtectVersion=%A
|
||||||
|
|
||||||
|
[Source]
|
||||||
|
Type=url-file
|
||||||
|
Path=https://git.plabble.org/api/packages/Job79/generic/runneros/latest/
|
||||||
|
MatchPattern=runneros_@v.usr-%a.@u.raw.zst
|
||||||
|
|
||||||
|
[Target]
|
||||||
|
Type=partition
|
||||||
|
Path=auto
|
||||||
|
MatchPattern=runneros_@v
|
||||||
|
MatchPartitionType=usr
|
||||||
|
PartitionFlags=0
|
||||||
|
ReadOnly=1
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=yes).
|
|
||||||
[Transfer]
|
|
||||||
ProtectVersion=%A
|
|
||||||
Verify=yes
|
|
||||||
|
|
||||||
[Source]
|
|
||||||
Type=url-file
|
|
||||||
Path=https://git.plabble.org/api/packages/Job79/generic/git-runner/latest/
|
|
||||||
MatchPattern=git-runner_@v.root-%a-verity.@u.raw.zst
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
Type=partition
|
|
||||||
Path=auto
|
|
||||||
MatchPattern=git-runner_@v_verity
|
|
||||||
MatchPartitionType=root-verity
|
|
||||||
PartitionFlags=0
|
|
||||||
ReadOnly=1
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# 11-usr-verity.transfer writes the dm-verity hashes that go with
|
||||||
|
# 10-usr.transfer, which explains how downloads are checked.
|
||||||
|
[Transfer]
|
||||||
|
ProtectVersion=%A
|
||||||
|
|
||||||
|
[Source]
|
||||||
|
Type=url-file
|
||||||
|
Path=https://git.plabble.org/api/packages/Job79/generic/runneros/latest/
|
||||||
|
MatchPattern=runneros_@v.usr-%a-verity.@u.raw.zst
|
||||||
|
|
||||||
|
[Target]
|
||||||
|
Type=partition
|
||||||
|
Path=auto
|
||||||
|
MatchPattern=runneros_@v_verity
|
||||||
|
MatchPartitionType=usr-verity
|
||||||
|
PartitionFlags=0
|
||||||
|
ReadOnly=1
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
# Installs the next UKI, which systemd-boot boots by default. Verify=yes: see 10-root.transfer.
|
# 20-uki.transfer installs the next UKI, which systemd-boot then boots by
|
||||||
|
# default. For how downloads are checked, see 10-usr.transfer.
|
||||||
|
#
|
||||||
|
# The new UKI gets three tries (boot counting: the +@l-@d in its name).
|
||||||
|
# systemd-bless-boot marks it good once a boot reaches boot-complete.target.
|
||||||
|
# If no boot does, systemd-boot goes back to the previous UKI, and with it to
|
||||||
|
# the previous /usr partition, because each UKI holds its usr hash.
|
||||||
[Transfer]
|
[Transfer]
|
||||||
ProtectVersion=%A
|
ProtectVersion=%A
|
||||||
Verify=yes
|
|
||||||
|
|
||||||
[Source]
|
[Source]
|
||||||
Type=url-file
|
Type=url-file
|
||||||
Path=https://git.plabble.org/api/packages/Job79/generic/git-runner/latest/
|
Path=https://git.plabble.org/api/packages/Job79/generic/runneros/latest/
|
||||||
MatchPattern=git-runner_@v.efi
|
MatchPattern=runneros_@v.efi
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
Type=regular-file
|
Type=regular-file
|
||||||
Path=/EFI/Linux
|
Path=/EFI/Linux
|
||||||
PathRelativeTo=boot
|
PathRelativeTo=boot
|
||||||
MatchPattern=git-runner_@v.efi
|
MatchPattern=runneros_@v+@l-@d.efi runneros_@v+@l.efi runneros_@v.efi
|
||||||
Mode=0444
|
TriesLeft=3
|
||||||
|
TriesDone=0
|
||||||
InstancesMax=2
|
InstancesMax=2
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# factory-etc.conf links what the image needs from /usr/share/factory/etc
|
||||||
|
# (mkosi.finalize) into the empty /etc at boot, so updates to /usr take effect
|
||||||
|
# in /etc too. The rest of the factory is unused package config. /etc itself
|
||||||
|
# holds what the machine writes: passwd, shadow, group, machine-id, ld.so.cache,
|
||||||
|
# /etc/systemd and the networks of podman (/etc/containers/networks). Podman
|
||||||
|
# reads its own config from /usr/share/containers. systemd's own etc.conf sets
|
||||||
|
# up os-release, nsswitch.conf and pam.d.
|
||||||
|
#
|
||||||
|
# /etc/systemd is filled from the presets at first boot, by PID 1.
|
||||||
|
|
||||||
|
# gitea-runner holds the config of the runner.
|
||||||
|
L /etc/gitea-runner
|
||||||
|
|
||||||
|
# authselect holds the PAM files that /etc/pam.d links to.
|
||||||
|
L /etc/authselect
|
||||||
|
L /etc/security
|
||||||
|
L /etc/environment
|
||||||
|
L /etc/login.defs
|
||||||
|
L /etc/shells
|
||||||
|
|
||||||
|
# pki and ssl hold the CA certificates, and crypto-policies the TLS settings.
|
||||||
|
L /etc/pki
|
||||||
|
L /etc/ssl
|
||||||
|
L /etc/crypto-policies
|
||||||
|
L /etc/bashrc
|
||||||
|
L /etc/profile
|
||||||
|
L /etc/profile.d
|
||||||
|
L /etc/protocols
|
||||||
|
L /etc/services
|
||||||
|
L /etc/hostname
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# The runner's directories, and a clean container storage on every boot.
|
# gitea-runner.conf makes the state directory of the runner, which holds its
|
||||||
# State: holds the registration (.runner) and the actions cache.
|
# registration (/etc/gitea-runner/config.yaml).
|
||||||
d /var/lib/gitea-runner 0700 root root -
|
d /var/lib/gitea-runner 0700
|
||||||
# Wipe all job containers, volumes and images on every boot. The shared base images
|
|
||||||
# (/var/lib/containers/base-images) stay; gitea-runner-images.service updates them.
|
# The storage of root's podman is wiped at every boot, so images and leftovers
|
||||||
|
# of jobs don't pile up. Jobs pull their images again.
|
||||||
R /var/lib/containers/storage
|
R /var/lib/containers/storage
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# First boot: asks for the root password and the runner's registration, on the screen (tty1) and the
|
|
||||||
# serial console (ttyS0) at once (gitea-runner-setup@.service).
|
|
||||||
# /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 =="
|
|
||||||
|
|
||||||
while :; do
|
|
||||||
read -rsp "Root password: " pw; echo
|
|
||||||
read -rsp "Again: " pw2; echo
|
|
||||||
[[ -n $pw && $pw == "$pw2" ]] && break
|
|
||||||
echo "Passwords do not match, try again."
|
|
||||||
done
|
|
||||||
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
|
|
||||||
install -D -m 0600 /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
|
|
||||||
ENV
|
|
||||||
echo "Done. The runner registers itself within a few seconds."
|
|
||||||
# Stop the setup on the other console, which then shows its login.
|
|
||||||
systemctl --no-block stop "gitea-runner-setup@*.service"
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# podman keeps network definitions in /etc/containers/networks, which is read-only here. Jobs
|
|
||||||
# create a network each, so keep them in /run: gone at reboot, like the rest of the job state.
|
|
||||||
[network]
|
|
||||||
network_config_dir = "/run/containers/networks"
|
|
||||||
Executable
+8
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# mkosi.finalize keeps the /etc that the packages and mkosi.extra/etc made in
|
||||||
|
# /usr/share/factory/etc, because the image ships only /usr. At boot,
|
||||||
|
# mkosi.extra/usr/lib/tmpfiles.d/factory-etc.conf links from it what /etc needs.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cp -a --no-target-directory --update=none "$BUILDROOT/etc" \
|
||||||
|
"$BUILDROOT/usr/share/factory/etc"
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# The job image (runs-on: linux), an OCI image that the OS ships in /usr/lib/gitea-runner/job-image.
|
|
||||||
# Just what common actions need, and podman (also as docker) to build images.
|
|
||||||
#
|
|
||||||
# - dnf5 jobs can install more
|
|
||||||
# - git-core openssh-clients checkout
|
|
||||||
# - nodejs26 JavaScript actions
|
|
||||||
# - podman images
|
|
||||||
# - tar gzip zstd findutils cache and artifact actions
|
|
||||||
[Output]
|
|
||||||
Format=oci
|
|
||||||
Output=job
|
|
||||||
|
|
||||||
[Content]
|
|
||||||
Packages=
|
|
||||||
dnf5
|
|
||||||
git-core
|
|
||||||
openssh-clients
|
|
||||||
nodejs26
|
|
||||||
podman
|
|
||||||
tar
|
|
||||||
gzip
|
|
||||||
zstd
|
|
||||||
findutils
|
|
||||||
WithDocs=no
|
|
||||||
# Also installs no translations; jobs that need them can install glibc-langpack-*.
|
|
||||||
Locale=C.UTF-8
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
podman
|
|
||||||
+12
-9
@@ -1,11 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Installs the Gitea runner from gitea.com.
|
# mkosi.prepare installs the Gitea runner from its releases on gitea.com, as
|
||||||
set -eu
|
# /usr/bin/gitea-runner. Fedora doesn't package it. The checksum file comes
|
||||||
v=5.4.1
|
# from the same release, so it catches a broken download, not a bad release.
|
||||||
f=gitea-runner-$v-linux-amd64.xz
|
set -euo pipefail
|
||||||
|
version=6.0.1
|
||||||
|
file=gitea-runner-$version-linux-amd64.xz
|
||||||
|
|
||||||
cd "$(mktemp -d)"
|
cd "$(mktemp -d)"
|
||||||
curl -fsSLO "https://gitea.com/gitea/runner/releases/download/v$v/$f"
|
curl -fsSLO "https://gitea.com/gitea/runner/releases/download/v$version/$file"
|
||||||
curl -fsSLO "https://gitea.com/gitea/runner/releases/download/v$v/$f.sha256"
|
curl -fsSLO "https://gitea.com/gitea/runner/releases/download/v$version/$file.sha256"
|
||||||
sha256sum -c "$f.sha256"
|
sha256sum -c --quiet "$file.sha256"
|
||||||
xz -dc "$f" > "$BUILDROOT/usr/bin/gitea-runner"
|
xz -dc "$file" > "$BUILDROOT/usr/bin/gitea-runner"
|
||||||
chmod 755 "$BUILDROOT/usr/bin/gitea-runner"
|
chmod 755 "$BUILDROOT/usr/bin/gitea-runner"
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
# EFI system partition: systemd-boot and the UKIs (two versions at most).
|
# 00-esp.conf defines the EFI system partition. It holds systemd-boot and the
|
||||||
|
# UKIs, two versions at most.
|
||||||
[Partition]
|
[Partition]
|
||||||
Type=esp
|
Type=esp
|
||||||
Format=vfat
|
Format=vfat
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
# 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
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# 10-usr.conf defines /usr in slot A: the OS as read-only erofs, protected by
|
||||||
|
# dm-verity (usrhash= in the UKI). Updates replace it whole. The image holds
|
||||||
|
# nothing else but the ESP: the initrd makes the root filesystem, with /etc
|
||||||
|
# and /var, at first boot (mkosi.extra/usr/lib/repart.d/50-root.conf).
|
||||||
|
[Partition]
|
||||||
|
Type=usr
|
||||||
|
Label=%M_%A
|
||||||
|
Format=erofs
|
||||||
|
Compression=lz4hc
|
||||||
|
CopyFiles=/usr:/
|
||||||
|
Verity=data
|
||||||
|
VerityMatchKey=usr
|
||||||
|
SizeMinBytes=1G
|
||||||
|
SizeMaxBytes=1G
|
||||||
|
# SplitName holds the partition UUID (%U): usrhash= finds /usr by it, and
|
||||||
|
# updates keep it (@u in mkosi.extra/usr/lib/sysupdate.d).
|
||||||
|
SplitName=%t.%U
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# dm-verity hashes of the root filesystem, slot A.
|
|
||||||
[Partition]
|
|
||||||
Type=root-verity
|
|
||||||
Label=%M_%A_verity
|
|
||||||
Verity=hash
|
|
||||||
VerityMatchKey=root
|
|
||||||
SizeMinBytes=64M
|
|
||||||
SizeMaxBytes=64M
|
|
||||||
SplitName=%t.%U
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# 11-usr-verity.conf holds the dm-verity hashes of /usr in 10-usr.conf.
|
||||||
|
[Partition]
|
||||||
|
Type=usr-verity
|
||||||
|
Label=%M_%A_verity
|
||||||
|
Verity=hash
|
||||||
|
VerityMatchKey=usr
|
||||||
|
SizeMinBytes=16M
|
||||||
|
SizeMaxBytes=16M
|
||||||
|
SplitName=%t.%U
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# The root filesystem, slot B: empty until systemd-sysupdate writes the next version.
|
|
||||||
[Partition]
|
|
||||||
Type=root
|
|
||||||
Label=_empty
|
|
||||||
SizeMinBytes=1G
|
|
||||||
SizeMaxBytes=1G
|
|
||||||
SplitName=-
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# 20-usr-b.conf defines /usr in slot B. It stays empty until systemd-sysupdate
|
||||||
|
# writes the next version to it.
|
||||||
|
[Partition]
|
||||||
|
Type=usr
|
||||||
|
Label=_empty
|
||||||
|
SizeMinBytes=1G
|
||||||
|
SizeMaxBytes=1G
|
||||||
|
SplitName=-
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# dm-verity hashes of the root filesystem, slot B.
|
|
||||||
[Partition]
|
|
||||||
Type=root-verity
|
|
||||||
Label=_empty
|
|
||||||
SizeMinBytes=64M
|
|
||||||
SizeMaxBytes=64M
|
|
||||||
SplitName=-
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
# 21-usr-verity-b.conf holds the dm-verity hashes for 20-usr-b.conf, empty
|
||||||
|
# until the next update.
|
||||||
|
[Partition]
|
||||||
|
Type=usr-verity
|
||||||
|
Label=_empty
|
||||||
|
SizeMinBytes=16M
|
||||||
|
SizeMaxBytes=16M
|
||||||
|
SplitName=-
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# /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=xfs
|
|
||||||
CopyFiles=/var:/
|
|
||||||
Minimize=guess
|
|
||||||
SplitName=-
|
|
||||||
+8
-3
@@ -1,3 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# The image version: the build time, so every build is newer than the last.
|
# mkosi.version prints the build time in UTC (YYYYMMDDhhmm) and the git
|
||||||
date -u +%Y%m%d%H%M
|
# commit. Every build gets a higher version than the one before, which is how
|
||||||
|
# systemd-sysupdate tells that an update is newer. The commit tells which
|
||||||
|
# source an image was built from.
|
||||||
|
set -euo pipefail
|
||||||
|
commit=$(git rev-parse --short HEAD)
|
||||||
|
echo "$(date -u +%Y%m%d%H%M).$commit"
|
||||||
Reference in new issue
Block a user