40 Commits
Author SHA1 Message Date
Job79 bd98edbf3e Merge pull request 'Fix what a real install showed' (#3) from first-boot-fixes into main
os / os (push) Waiting to run
Reviewed-on: #3
2026-11-23 19:52:44 +00:00
Job79 0d54f59ff6 Merge pull request 'Run podman in jobs' (#2) from podman-in-jobs into main
os / os (push) Waiting to run
Reviewed-on: #2
2026-11-23 19:52:17 +00:00
Job79andClaude Opus 5.5 57dd1afd2f README: the factory reset asks to clear the TPM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:40:01 +00:00
Job79andClaude Opus 5.5 3b10f60fab Fix what a real install showed
- systemd-sysusers failed after an update: the image has no login.defs,
  so its factory link pointed at itself. The link goes.
- The first boot had another hostname than later boots, because
  /etc/hostname only exists once tmpfiles links it. The first boot is
  when the runner registers, under that name. The kernel command line
  now sets the hostname, which PID 1 has from the start.
- The README promised a recovery key that doesn't exist. The disk only
  unlocks with the TPM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:36:47 +00:00
Job79andClaude Opus 5.5 52b4cea73e Run podman in jobs
The job image gets podman, and each job a volume for /var/lib/containers,
so podman inside the job keeps its storage off the container's overlayfs.
Tested by building Job79/devcontainer's two images in a job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 19:08:19 +00:00
Job79 6ebddf18ce Merge pull request 'Ask for the registration and capacity at first boot' (#1) from first-boot-setup into main
os / os (push) Successful in 4m6s
Reviewed-on: #1
2026-11-23 18:58:25 +00:00
Job79andClaude Opus 5.5 018f15172d Ask for the registration and capacity at first boot
gitea-runner-setup asks on the console for the number of parallel jobs,
the Gitea URL and a registration token, and registers the runner. It runs
until the runner is registered, and logins wait for it, as for
systemd-firstboot. The capacity goes to a drop-in of gitea-runner.service,
which passes it to the config as CAPACITY, so the config stays read-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:57:23 +00:00
Job79andClaude Opus 5.5 094ee671d7 os.yml: Publish with the PACKAGE_TOKEN secret
os / os (push) Successful in 3m59s
Gitea gives the job token at most read access to a user's packages, so
publishing needs a token of the owner. The permissions block didn't help
and goes; the default lets actions/checkout read the repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:41:17 +00:00
Job79andClaude Opus 5.5 1c906b9b68 os.yml: Check out with actions/checkout
os / os (push) Failing after 2m28s
The job image has Node.js 26, so the standard action works.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:32:37 +00:00
Job79andClaude Opus 5.5 edc55ca97c os.yml: pass the clone's auth header through env
os / os (push) Failing after 2m5s
A plain YAML scalar can't hold ": ".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:31:14 +00:00
Job79andClaude Opus 5.5 676a9978f8 os.yml: check out with one git clone
os.yml (push) Invalid workflow file
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:30:40 +00:00
Job79andClaude Opus 5.5 d76d28ef8a Sign local builds with mkosi -f genkey
os / os (push) Failing after 2m14s
It replaces mkosi.crt for local tests, without openssl or a
mkosi.local.conf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:28:04 +00:00
Job79andClaude Opus 5.5 d1c7c55700 Run jobs in our own job image
os / os (push) Failing after 2m42s
mkosi.images/job/ builds an OCI image with git, Node.js 26 and dnf, and
the OS ships it in /usr, so it is signed and updated with the OS.
gitea-runner.service loads it at boot instead of pulling Fedora, and
JavaScript actions work without installing Node.js in each job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:48:04 +00:00
Job79andClaude Opus 5.5 460bdbe380 os.yml: check out with git again
os / os (push) Failing after 1m37s
actions/checkout needs Node.js in every job and fetches the action from
GitHub. Four lines of git need neither.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:40:58 +00:00
Job79andClaude Opus 5.5 821065c428 os.yml: use Node.js 26 for actions/checkout
os / os (push) Failing after 1m49s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:27:42 +00:00
Job79andClaude Opus 5.5 e2a74d4e16 Check out with actions/checkout, pull the job image at boot
os / os (push) Failing after 2m11s
gitea-runner clones the actions that jobs use with git, so the image
needs git-core. With it and Node.js in the job, actions/checkout works,
which replaces the hand-written git fetch. gitea-runner.service pulls the
image of the linux label before it starts, so the first job after a
boot doesn't wait 27 seconds for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:05:14 +00:00
Job79andClaude Opus 5.5 a0bfce38da os.yml: say that gitea-runner 6 removed builtin:checkout
os / os (push) Canceled after 1m20s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:01:03 +00:00
Job79andClaude Opus 5.5 6a32e00431 Docs: sign local builds with a test key in mkosi.local.conf
os / os (push) Failing after 1m34s
mkosi genkey won't replace mkosi.crt, and the key options on the command
line miss the PCR and verity keys. mkosi already pulls in zstd and
qemu-img, so the workflow doesn't install them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:07:31 +00:00
Job79andClaude Opus 5.5 b5aa2d7a59 os.yml: keep read access for the checkout
os / os (push) Failing after 1m35s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:02:59 +00:00
Job79andClaude Opus 5.5 95e0420207 os.yml: let the job token publish the package
os / os (push) Failing after 20s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:02:18 +00:00
Job79andClaude Opus 5.5 e2a873f883 os.yml: check out with git
os / os (push) Failing after 1m33s
gitea-runner 6 has no builtin:checkout, and plain Fedora has no Node.js
for actions/checkout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 16:00:25 +00:00
Job79andClaude Opus 5.5 0733ff55f3 Rewrite on the layout of agentos
os / os (push) Failing after 29s
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>
2026-11-22 15:59:36 +00:00
Job79andClaude Opus 5.5 0569bce676 Secure Boot
mkosi signs systemd-boot and the UKI with our own key (mkosi.crt; the private
key is the SECUREBOOT_KEY secret, which the os workflow writes to mkosi.key)
and puts the keys on the ESP. systemd-boot enrolls them at first boot if the
firmware is in setup mode: in Proxmox, an EFI disk without pre-enrolled keys.
Hosts installed before this keep their unsigned systemd-boot (updates don't
replace it), so they boot as before, without Secure Boot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:43:54 +01:00
Job79andClaude Opus 5.5 f3dfbb4f78 Give memory unused for an hour back to the host
damon_reclaim pages out memory that hasn't been touched for an hour, whatever
memory is free, so virtio-balloon free page reporting can return it to the
host. The test VM in the README gets a balloon device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:43:54 +01:00
Job79andClaude Opus 5.5 92a21ae607 Sign updates
The os workflow signs SHA256SUMS with the SIGNING_KEY secret and publishes
SHA256SUMS.gpg next to it. systemd-sysupdate now verifies it (Verify=yes)
against import-pubring.pgp, so hosts only install updates we built.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:43:54 +01:00
Job79andClaude Opus 5.5 607987ebbd Build the OS on our own job image
The os workflow now runs on linux, our job image, instead of plain Fedora; it
already has git, so only mkosi is installed. If a change breaks the job image,
build the fix locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 22:43:54 +01:00
Job79andClaude Opus 5.5 7df16dce11 Make /var xfs
xfs has no fsck to run at boot (it replays its log on mount), so the fstab pass
is 0. Existing runners keep their ext4 /var, which this fstab no longer mounts:
reinstall them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:52:13 +01:00
Job79andClaude Opus 5.5 cd8dfd52f8 Publish updates as a generic package
Each build replaces version "latest" of the generic package git-runner: one
delete and one upload per file, with no release ids or pruning. Updates are no
longer atomic: while a build uploads, runners find no update and retry later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:25:35 +01:00
Job79andClaude Opus 5.5 29ac7278a1 Publish each build as its own release
Gitea serves releases/download/latest/ from the newest published release, so
instead of replacing assets in a fixed "latest" release, each build uploads to
a draft and publishes it, then removes all but the newest 3 releases. The qcow2
is now published on every build, as latest only looks at the newest release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:22:07 +01:00
Job79andClaude Opus 5.5 5bb84ade05 Drop skopeo from the job image
Nothing uses it, and podman doesn't need it; jobs that do can dnf install it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 16:22:07 +01:00
Job79andClaude Opus 5.5 5f2a5c2b23 First-boot setup on the serial console too
The setup asked only on the screen (tty1); it now also asks on the serial console (ttyS0), so a
VM can be set up from a serial terminal or a script. Whichever console is answered first stops
the setup on the other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snprgiQMRMB6RRDNjCX
2026-11-14 12:21:50 +00:00
Job79andClaude Opus 5.5 fd1ef420cd Enable the login on the screen
Fedora's presets disable getty@.service, so after first-boot setup the screen showed no login,
on tty1 or any other VT (autovt@ is its alias); only the serial console had one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snprgiQMRMB6RRDNjCX
2026-11-14 11:52:50 +00:00
Job79andClaude Opus 5.5 5512061b2e podman: keep network definitions in /run, as /etc is read-only
Jobs failed to start: podman creates a network per job and writes its definition to
/etc/containers/networks, read-only since /etc was sealed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snprgiQMRMB6RRDNjCX
2026-11-14 11:48:02 +00:00
Job79andClaude Opus 5.5 042583be77 gitea-runner.service: set HOME, which User= used to set
Without a user, the service has no HOME, and the runner needs it for its cache directory:
registration failed with "cache.dir is unset and the user home directory could not be
determined".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snprgiQMRMB6RRDNjCX
2026-11-14 11:47:15 +00:00
Job79andClaude Opus 5.5 cdc4a84658 Run the runner as root; shorten the workflow
The gitea-runner user had root's podman socket, which is root access anyway, so it bought no
isolation. Run it as root and drop the user, the podman.socket drop-in and the /run/podman
permission workaround.

The workflow publishes in one step with small helpers, and filters assets with awk, which,
unlike grep, does not fail the step when nothing matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snor4EJUATK7VoiKne6
2026-11-14 11:26:52 +00:00
Job79andClaude Opus 5.5 b0a49de3e6 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
2026-11-14 12:12:10 +01:00
Job79andClaude Opus 5.5 c2ec9ddb29 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
2026-11-14 11:55:48 +01:00
Job79andClaude Opus 5.5 97355554f4 mkosi.conf: say where the job image goes
os / os (push) Successful in 4m0s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 23:44:10 +01:00
Job79andClaude Opus 5.5 7b26dd92d1 README: boot the image with qemu; explain the kernel command line
os / os (push) Successful in 3m43s
mkosi vm needs systemd on the host and shows only the serial console,
while the first-boot setup runs on the screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 23:36:54 +01:00
Job79andClaude Opus 5.5 dfa5d69b44 No repo secrets: unsigned image, updates as release assets, job image built by mkosi
os / os (push) Successful in 3m51s
The workflow's own token can't write packages and repo secrets can't be
set, so: build unsigned, publish the sysupdate files as assets of the
"latest" release, and build the job image with mkosi and ship it in /usr
instead of pushing it to a registry. Partition UUIDs are now part of the
update file names, so updated /usr partitions keep the UUIDs usrhash=
expects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 23:21:42 +01:00
42 changed files with 575 additions and 381 deletions

No files matched your search

-28
View File
@@ -1,28 +0,0 @@
# git-runner job image
#
# Builds the job image (job/) and pushes it to this Gitea's registry.
# Runs on every push, weekly for Fedora updates, and by hand.
name: job
on:
push:
branches: [main]
schedule:
- cron: "0 2 * * 0" # weekly (Sunday), picks up Fedora updates
workflow_dispatch: # run by hand, e.g. for a CVE
jobs:
job:
runs-on: fedora
env:
IMAGE: git.plabble.org/job79/git-runner-mkosi-job:latest
steps:
- name: Install tools
run: dnf install -yq git-core podman
- name: Check out
uses: builtin:checkout
- name: Build
run: podman build -t "$IMAGE" job
- name: Log in to the registry
run: podman login -u "${{ github.repository_owner }}" --password-stdin git.plabble.org <<<"${{ secrets.GITHUB_TOKEN }}"
- name: Push
run: podman push --compression-format=zstd:chunked "$IMAGE"
+39 -35
View File
@@ -1,58 +1,62 @@
# 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 mkosi, signed for Secure Boot, and publishes it in this Gitea's generic # Required values:
# package registry, where runners fetch their updates (mkosi.extra/usr/lib/sysupdate.d): # - SECUREBOOT_KEY repository secret: the private key of mkosi.crt, written
# https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/ # to mkosi.key.
# Runs on every push, weekly for Fedora updates, and by hand. The weekly and manual runs also # - SIGNING_KEY repository secret: the armored private gpg key whose
# publish the disk image for new installs (git-runner.qcow2 in the same place). # public half is mkosi.extra/usr/lib/systemd/
# # import-pubring.pgp, which systemd-sysupdate checks.
# Secrets: # - PACKAGE_TOKEN repository secret: a token of the package owner with only
# - SECUREBOOT_KEY the private key for mkosi.crt # write:package. The job token can't write packages.
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: fedora runs-on: linux
env:
PACKAGE: https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest
AUTH: ${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }}
steps: steps:
- name: Install tools - name: Install tools
run: dnf install -yq git-core mkosi jq run: dnf install -yq mkosi
- name: Check out - name: Check out
uses: builtin:checkout uses: actions/checkout@v7
- name: Build - name: Build
env: env:
SECUREBOOT_KEY: ${{ secrets.SECUREBOOT_KEY }} KEY: ${{ secrets.SECUREBOOT_KEY }}
run: | run: |
(umask 077; printenv SECUREBOOT_KEY > mkosi.key) (umask 077 && printf '%s\n' "$KEY" > mkosi.key)
mkosi --secure-boot=yes build mkosi build
- name: Compress - name: Compress
working-directory: mkosi.output working-directory: mkosi.output
run: | run: |
zstd -q --rm -T0 -19 git-runner_*.usr-*.raw zstd -q --rm -9 runneros_*.usr-*.raw
sha256sum git-runner_*.efi git-runner_*.usr-*.raw.zst > SHA256SUMS - name: Checksum
- name: Publish the update
working-directory: mkosi.output working-directory: mkosi.output
run: | run: sha256sum runneros_*.efi runneros_*.usr-*.raw.zst > SHA256SUMS
for f in $(awk '{print $2}' SHA256SUMS); do curl -fsS -u "$AUTH" --upload-file "$f" "$PACKAGE/$f"; done - name: Sign
curl -fsS -u "$AUTH" -X DELETE "$PACKAGE/SHA256SUMS" || true
curl -fsS -u "$AUTH" --upload-file SHA256SUMS "$PACKAGE/SHA256SUMS"
- name: Remove older versions
working-directory: mkosi.output working-directory: mkosi.output
env:
KEY: ${{ secrets.SIGNING_KEY }}
run: | run: |
curl -fsS -u "$AUTH" https://git.plabble.org/api/v1/packages/job79/generic/git-runner-mkosi/latest/files | jq -r '.[].name' | grep '^git-runner_' | export GNUPGHOME=$(mktemp -d)
grep -vxFf <(awk '{print $2}' SHA256SUMS) | while read -r f; do curl -fsS -u "$AUTH" -X DELETE "$PACKAGE/$f"; done gpg -q --batch --import <<< "$KEY"
- name: Publish the disk image gpg -q --batch -o SHA256SUMS.gpg --detach-sign SHA256SUMS
if: github.event_name != 'push' - name: Build qcow2
working-directory: mkosi.output working-directory: mkosi.output
run: qemu-img convert -c -O qcow2 "$(basename runneros_*.efi .efi).raw" runneros.qcow2
- name: Publish
working-directory: mkosi.output
env:
PKG: ${{ gitea.server_url }}/api/packages/${{ gitea.repository_owner }}/generic/runneros/latest
AUTH: "Authorization: token ${{ secrets.PACKAGE_TOKEN }}"
run: | run: |
qemu-img convert -c -O qcow2 "$(basename git-runner_*.efi .efi).raw" git-runner.qcow2 curl -fsS -H "$AUTH" -X DELETE "$PKG" || true
curl -fsS -u "$AUTH" -X DELETE "$PACKAGE/git-runner.qcow2" || true for f in runneros_*.efi runneros_*.usr-*.raw.zst runneros.qcow2 runneros_*.manifest SHA256SUMS.gpg SHA256SUMS; do
curl -fsS -u "$AUTH" --upload-file git-runner.qcow2 "$PACKAGE/git-runner.qcow2" curl -fsS -o /dev/null -H "$AUTH" --upload-file "$f" "$PKG/$f"
done
+3 -2
View File
@@ -1,3 +1,4 @@
# Build outputs, and the Secure Boot key for local signed builds.
mkosi.output/
mkosi.key mkosi.key
mkosi.output/
mkosi.cache/
mkosi.credentials/
+102
View File
@@ -0,0 +1,102 @@
# 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 mkosi -f genkey # Run this once. Don't commit mkosi.crt.
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'
```
- 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
```
+47
View File
@@ -0,0 +1,47 @@
# runneros
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.
- **Read-only OS:** `/usr` is read-only. Secure Boot verifies the UKI (kernel,
initrd and command line), which holds the dm-verity hash that verifies
`/usr`.
- **Encrypted with a TPM:** everything that isn't read-only, such as `/etc`
and `/var`, is encrypted. The TPM unlocks it only for correctly signed UKIs.
There is no recovery key: if the TPM is lost, reinstall.
- **Jobs in containers:** each job runs in its own privileged container on
root's podman. Jobs with `runs-on: linux` run in our job image: Fedora with
git, Node.js 26, podman and dnf, built with the OS and shipped in `/usr`.
Privileged jobs can build OS and container 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
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 asks for a timezone and a root password. Then it asks how many jobs to run at once, the Gitea URL and a
registration token from Gitea's runner settings. It registers under the
hostname, `runneros-` and four hex digits, and starts.
To change the number of parallel jobs later, run `systemctl edit
gitea-runner` and set `Environment=CAPACITY=<jobs>` under `[Service]`.
To start over, run `systemctl start factory-reset.target` as root. It reboots,
the firmware asks to clear the TPM (press F12), and it wipes the root partition
(`/etc` and `/var`). The VM then sets itself up as at first boot.
## Development
```sh
mkosi -f genkey # This replaces mkosi.crt for local tests. Don't commit it.
mkosi build
```
`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
[AGENTS.md](AGENTS.md#testing).
-18
View File
@@ -1,18 +0,0 @@
# git-runner job image
#
# The default image for jobs (`runs-on: linux`), built and pushed by the job
# workflow. It is kept small: just what common actions need. Jobs run their
# own podman (`docker` is an alias); the runner gives it the shared base
# images, see mkosi.extra/usr/lib/gitea-runner/config.yaml.
#
# Includes:
# - git-core openssh-clients checkout
# - nodejs26 JavaScript actions
# - podman skopeo images
# - tar gzip zstd findutils cache and artifact actions
FROM quay.io/fedora/fedora-minimal:45
RUN dnf -y install --setopt=install_weak_deps=False \
git-core nodejs26 podman skopeo tar gzip zstd findutils openssh-clients \
&& dnf clean all \
&& ln -s podman /usr/bin/docker
+110 -43
View File
@@ -1,62 +1,129 @@
# 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
# the state, is made at first boot.
#
# The other parts of the build:
# - mkosi.extra/ is copied to /.
# - mkosi.repart/ defines the disk image: the ESP and the /usr partitions.
# - 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.
# - mkosi.images/job/ builds the job image.
[Config]
# Dependencies builds the job image first, so ExtraTrees= can copy it in.
Dependencies=job
[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 /usr 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:
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 systemd-pull, which systemd-sysupdate downloads with # - ExtraTrees copies the job image (mkosi.images/job/) into /usr.
# - systemd-boot-unsigned the bootloader # - UnifiedKernelImageFormat names the UKI runneros_<version>.efi, which
# - util-linux, shadow-utils console login and the first-boot setup # matches the MatchPattern= of mkosi.extra/usr/lib/sysupdate.d/20-uki.transfer.
# - podman, git-core the runner's jobs; git fetches actions # - KernelCommandLine:
# - nftables-services the firewall # - rw has the initrd mount the root filesystem writable. It finds it by its
# - zram-generator-defaults compressed swap in RAM # partition type (mkosi.extra/usr/lib/repart.d/50-root.conf).
Packages= # - The hostname is runneros- and four hex digits of the machine ID, also
kernel-core # the name the runner registers with. Unlike /etc/hostname, which only
systemd # exists once tmpfiles links it, the command line has it from the first
dbus-broker # boot on.
systemd-udev # - The image policy only accepts an encrypted root filesystem (or none, at
systemd-networkd # first boot) and a verity-checked /usr. Otherwise someone with the disk
systemd-resolved # could swap in a plain root filesystem. Our UKI would boot it, and their
systemd-container # code could unseal the key of the real one.
systemd-boot-unsigned # - The root btrfs keeps one copy of its metadata instead of two (DUP,
util-linux # mkfs.btrfs's default). On a VM disk a second copy adds little.
shadow-utils # - The mount rate limit is raised from 5, which holds back mounts at boot
podman # and delays / and /usr by up to a second each.
git-core # - KernelInitrdModules are what the initrd needs to find the disks of a VM,
nftables-services # mount /usr and unlock the root filesystem. The kernel has virtio_blk,
zram-generator-defaults # sd_mod, the TPM drivers and btrfs built in.
# - KernelModules keeps all modules but the hardware drivers, then adds back
# the drivers a VM needs (disks, network, screen) and those of podman's
# networks (veth, tun). The last matching line wins. Keyboard, USB and a
# basic screen are built into the kernel.
# - RemoveFiles drops System.map, which is only for debugging the kernel, and
# the udev hwdb, which holds hardware names and quirks a VM doesn't need.
# Without hwdb.d, systemd-hwdb-update can't build it again at boot.
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.
git-core # The runner fetches the actions jobs use.
curl
procps-ng
iproute
ExtraTrees=%O/job:/usr/lib/runneros/job
UnifiedKernelImageFormat=%i_%v UnifiedKernelImageFormat=%i_%v
KernelCommandLine= KernelCommandLine=
rw
console=tty0
console=ttyS0,115200n8
quiet quiet
systemd.firstboot=no rw
slab_nomerge systemd.hostname=runneros-????
init_on_alloc=1 systemd.image_policy=root=encrypted+absent:usr=verity:esp=unprotected
randomize_kstack_offset=on systemd.setenv=SYSTEMD_REPART_MKFS_OPTIONS_BTRFS=--metadata=single
page_alloc.shuffle=1 SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50
# 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
ext4 KernelModules=
/*
-/drivers/*
/drivers/virtio/*
/drivers/block/*
/drivers/md/*
nvme
virtio_scsi
virtio_net
qemu_fw_cfg
bochs
virtio-gpu
veth
tun
RemoveFiles=
/usr/lib/modules/*/System.map
/usr/lib/udev/hwdb.bin
/usr/lib/udev/hwdb.d
[Validation]
# Validation signs the boot chain with mkosi.key, so the TPM unlocks the root
# filesystem only for our UKIs.
SecureBoot=yes
SignExpectedPcr=yes
[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
+16 -16
View File
@@ -1,18 +1,18 @@
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
MIIC3DCCAcSgAwIBAgIUJf6brtTrJfRyg89YFBAFKNkMhZYwDQYJKoZIhvcNAQEL MIICzjCCAbagAwIBAgIUVszVwCQVaOBS3MyL9TUA4lMaeHowDQYJKoZIhvcNAQEL
BQAwJzElMCMGA1UEAwwcZ2l0LXJ1bm5lci1ta29zaSBTZWN1cmUgQm9vdDAgFw0y BQAwITEfMB0GA1UEAwwWZ2l0LXJ1bm5lciBTZWN1cmUgQm9vdDAeFw0yNjExMTQy
NjExMTIyMTMyMzdaGA8yMTI2MTAxOTIxMzIzN1owJzElMCMGA1UEAwwcZ2l0LXJ1 MTE1MjhaFw0zNjExMTEyMTE1MjhaMCExHzAdBgNVBAMMFmdpdC1ydW5uZXIgU2Vj
bm5lci1ta29zaSBTZWN1cmUgQm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC dXJlIEJvb3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDO1KaKLK6e
AQoCggEBAObV42lyR2vWBjln4wLo0+l3BZY5r9ej6N19H4cGyrGyBlAmM+U8LzAG phfFvGyceuWGkJvnehJ5634rhty4gsyJlFVZSdZvDTU5iU6okjwtnYShEgEH02jX
VQYnxF+vXPfXqJtvWBl1o/10Qww+u6MD4dKrWqI00YMNEyJDTneCaobshkJf1nbK Xgj7Y76iBuetAFjx1ISAdJNxdPHHO7uazLidMQ2gaVsSXayTPgwNmKoJ2xMmkoyQ
iAZyul/nrfR8AErI52fjKrT89PdskpBsQqMeOM3Xu/q585a2aMOLQBn2TRyqq95N SO1vqTymWlVGJptgFIOivUbFBhovxSqeAC2kFplK11/3mQxl1Oxd7Lrh9BwBZbqU
KPEYfMiZRJ5QiIrWU0QdALvrxB07CZ4P0EW9chs8vyjysPM3EwiQiAny4KnAVgKF E9Rd2eQUo8g9JjBA9nR7ogxa4wyP1mpMyvmJ2NbcuMunpKQC66eW5RNH3ERgJi36
pot8rbUcQz9ias92VlqMdTpPks7HaXyDt1eREV3yZoGPaB3kKj1DIUqHWB3B6kuk fPiuT/ou+gjpYZo1HW6c59nx9XFO6epCcDWRV2xfcB/iFaDIVuJafDWvyeB1RFD+
cfmRrU34EGHfRF97Sf26BmqnE2HLIpMCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEA CguGyHI7VFSTAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAI84Ucm8m45nRFPf6ffb
ZhNuMz1p+oc0ClttIQbo4sdarpdmgr5Abvdh8C9vwVQrJLMynEQL4d4IAaSJ+SKz vlfamcO+HIhobyPmafwEGLv6HWjHC9I9XulmEOHz9PePEI2TX0K9I883IGvmoyEA
og6gmNKYwmX6CusK2/vFQnobWYQphe+tiC6qdMcwMuy2R/Shp6PWTQjvsU1R7R42 AMI1f9kskm2Xg7Xk/OLXmqHDGDbJFNaS8e79ImBqu9bBWe4rOa6naeH7JiVjTh5Y
Y9Uba3yFwibqRPGjFjUEh39d0MSZ5pKFuC82F746QntLZnHQQVWdnVnyTaA25JH2 2APyP+o+DKrXuCjcQtZc1PkuQPrElNmqKduhfL4acIPR0N7kJ58FwpuE9Zh8C0p1
F0l8CqH3iz6GHz65Q0zMx7EOVyKfAcM7t4KPH/McV8FSBCkOm9UhxGQcpnxQc8iH NSb7x38Dxxwid4zWDbSuIeIi0FfCFHC8olvzfDQlNst5VQeE921KcK8YKREIgn0H
JvKuI+Vys4I1xtFrCULFhR2Yo2984zafcCXlFv4Xib/h0Mpu1s8f1AcyrEsITonl 2GLtzpczUGq8u6Pen7R8qSjLZ0GlVXfMlW1EthoYnlP1n4oxg6xfPn2J5SyP2EGi
AOTjyyxDX8zSnTrW3phSjA== Iis=
-----END CERTIFICATE----- -----END CERTIFICATE-----
+29
View File
@@ -0,0 +1,29 @@
# 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
# capacity is the number of parallel jobs, set by gitea-runner.service.
capacity: ${CAPACITY}
# shutdown_timeout lets running jobs finish when the runner stops, as it
# does before an update reboots the machine.
shutdown_timeout: 1h
# labels names the job image of jobs with runs-on: linux, which
# gitea-runner.service loads at boot.
labels:
- linux:docker://localhost/runneros-job
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 volumes for /var/tmp and /var/lib/containers. On
# the container's overlayfs, mkosi loses the xattrs of the files it copies,
# such as file capabilities, and podman can't keep its storage.
options: --volume /var/tmp --volume /var/lib/containers
@@ -1,32 +0,0 @@
# 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).
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 (job/Containerfile): git, node, skopeo and podman.
- "linux:docker://git.plabble.org/job79/git-runner-mkosi-job:latest"
# Plain Fedora; our own build workflows use it, so a broken job image can't block its own fix.
- "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
force_pull: true
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"]
+8 -2
View File
@@ -1,4 +1,10 @@
# Grow the root partition to fill the disk at boot (systemd-repart); systemd-growfs then grows # 50-root.conf makes the root filesystem at first boot, in the free space after
# its filesystem (GrowFileSystem= in mkosi.repart/30-root.conf). # /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] [Partition]
Type=root Type=root
Format=btrfs
Encrypt=tpm2
FactoryReset=yes
@@ -1,31 +0,0 @@
# 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.
# Hide kernel addresses in /proc and logs, even from root; they help exploits bypass KASLR.
kernel.kptr_restrict = 2
# Only root may read the kernel log (it leaks addresses and hardware details).
kernel.dmesg_restrict = 1
# No perf events for non-root users. Upstream kernels treat 3 like 2 (the strictest they know).
kernel.perf_event_paranoid = 3
# Harden the BPF JIT against JIT spraying, for every user. Small cost when BPF is used.
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).
kernel.unprivileged_bpf_disabled = 1
# No kexec: nobody can boot another kernel without going through Secure Boot.
kernel.kexec_load_disabled = 1
# No core dumps of setuid programs; they can contain secrets.
fs.suid_dumpable = 0
# Don't load TTY line disciplines on demand; old ones have had exploitable bugs.
dev.tty.ldisc_autoload = 0
# userfaultfd only for root; it is used to make kernel race exploits reliable.
vm.unprivileged_userfaultfd = 0
# Don't open FIFOs and regular files owned by someone else 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 <other pid> doesn't).
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.
fs.inotify.max_user_instances = 8192
Binary file not shown.
@@ -1,5 +1,5 @@
# 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=!*
@@ -1,9 +0,0 @@
# Services enabled in the image (mkosi runs systemctl preset-all).
enable systemd-networkd.service
enable systemd-resolved.service
enable nftables.service
enable podman.socket
enable gitea-runner-setup.service
enable gitea-runner.service
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
@@ -0,0 +1,26 @@
# 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-setup.service registers the runner, and gitea-runner.path then
# starts it.
enable gitea-runner-setup.service
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,17 +0,0 @@
# Pulls the base images that jobs share read-only (see /usr/lib/gitea-runner/config.yaml) before the
# runner starts, so no job uses them while they change. Hosts reboot to update, so this runs about
# as often as there are updates.
[Unit]
Description=Base 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
# 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 quay.io/fedora/fedora-minimal:45
ExecStart=/usr/bin/podman --root ${IMAGES} --runroot /run/containers/base-images image prune -f
TimeoutStartSec=30min
@@ -1,17 +1,21 @@
# First boot: asks for the root password and the runner's registration on the console (tty1). # gitea-runner-setup.service runs /usr/libexec/gitea-runner-setup on the
# console until the runner is registered, after systemd-firstboot has asked
# its questions there. Logins wait for it, as for systemd-firstboot, so no
# getty reads the same console.
[Unit] [Unit]
Description=Gitea runner first-boot setup Description=Gitea runner setup
ConditionPathExists=!/etc/gitea-runner/runner.env ConditionPathExists=!/var/lib/gitea-runner/.runner
Before=getty@tty1.service kmsconvt@tty1.service Wants=network-online.target
After=systemd-firstboot.service network-online.target
Before=systemd-user-sessions.service
[Service] [Service]
Type=oneshot Type=oneshot
# HOME is where gitea-runner keeps its cache, as in gitea-runner.service.
Environment=HOME=/var/lib/gitea-runner
ExecStart=/usr/libexec/gitea-runner-setup ExecStart=/usr/libexec/gitea-runner-setup
StandardInput=tty StandardInput=tty
StandardOutput=tty StandardOutput=tty
TTYPath=/dev/tty1
TTYReset=yes
TTYVHangup=yes
[Install] [Install]
WantedBy=multi-user.target 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-setup.service.
[Unit]
Description=Start the Gitea runner once registered
[Path]
PathExists=/var/lib/gitea-runner/.runner
[Install]
WantedBy=multi-user.target
@@ -1,24 +1,28 @@
# 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
After=network-online.target podman.socket gitea-runner-images.service After=network-online.target podman.socket
Requires=podman.socket Requires=podman.socket
[Service] [Service]
# The runner drives root's podman (podman.socket.d gives this user the socket). The jobs it starts # CAPACITY is the number of parallel jobs. gitea-runner-setup writes a drop-in
# never get the socket (see config.yaml). # that overrides it, which `systemctl edit gitea-runner` changes.
User=gitea-runner Environment=CAPACITY=1
WorkingDirectory=/var/lib/gitea-runner # HOME holds the cache of actions/cache, next to the registration.
EnvironmentFile=/etc/gitea-runner/runner.env Environment=HOME=/var/lib/gitea-runner
Environment=DOCKER_HOST=unix:///run/podman/podman.sock Environment=DOCKER_HOST=unix:///run/podman/podman.sock
# Register once; the result is kept in .runner. # ExecStartPre loads the job image (mkosi.images/job/) from /usr into podman,
ExecStartPre=/bin/sh -c '[ -f .runner ] || exec gitea-runner register --no-interactive --config /usr/lib/gitea-runner/config.yaml --instance "$GITEA_INSTANCE_URL"' # whose storage is wiped at every boot, under the name that the linux label in
ExecStart=/usr/bin/gitea-runner daemon --config /usr/lib/gitea-runner/config.yaml # /etc/gitea-runner/config.yaml uses. podman names nothing it pulls from an
# OCI directory, hence the tag.
ExecStartPre=/bin/sh -c 'podman tag "$(podman pull -q oci:/usr/lib/runneros/job)" localhost/runneros-job'
ExecStart=/usr/bin/gitea-runner -c /etc/gitea-runner/config.yaml daemon
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,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,4 +0,0 @@
# The runner may use root's podman. Jobs never get this socket.
[Socket]
SocketGroup=gitea-runner
SocketMode=0660
@@ -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,18 +1,20 @@
# Updates /usr: writes the next version to the unused /usr partition. # 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] [Transfer]
ProtectVersion=%A ProtectVersion=%A
# Not signed: the Secure Boot signed UKI pins the hash of /usr (usrhash=).
Verify=no
[Source] [Source]
Type=url-file Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/ Path=https://git.plabble.org/api/packages/Job79/generic/runneros/latest/
MatchPattern=git-runner_@v.usr-%a.raw.zst MatchPattern=runneros_@v.usr-%a.@u.raw.zst
[Target] [Target]
Type=partition Type=partition
Path=auto Path=auto
MatchPattern=git-runner_@v MatchPattern=runneros_@v
MatchPartitionType=usr MatchPartitionType=usr
PartitionFlags=0 PartitionFlags=0
ReadOnly=1 ReadOnly=1
@@ -1,17 +1,17 @@
# Updates the dm-verity hashes of /usr, next to 10-usr.transfer. # 11-usr-verity.transfer writes the dm-verity hashes that go with
# 10-usr.transfer, which explains how downloads are checked.
[Transfer] [Transfer]
ProtectVersion=%A ProtectVersion=%A
Verify=no
[Source] [Source]
Type=url-file Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/latest/ Path=https://git.plabble.org/api/packages/Job79/generic/runneros/latest/
MatchPattern=git-runner_@v.usr-%a-verity.raw.zst MatchPattern=runneros_@v.usr-%a-verity.@u.raw.zst
[Target] [Target]
Type=partition Type=partition
Path=auto Path=auto
MatchPattern=git-runner_@v_verity MatchPattern=runneros_@v_verity
MatchPartitionType=usr-verity MatchPartitionType=usr-verity
PartitionFlags=0 PartitionFlags=0
ReadOnly=1 ReadOnly=1
@@ -1,20 +1,23 @@
# Installs the next UKI, which systemd-boot boots by default. If it fails to boot 3 times, # 20-uki.transfer installs the next UKI, which systemd-boot then boots by
# systemd-boot falls back to the previous one. # 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=no
[Source] [Source]
Type=url-file Type=url-file
Path=https://git.plabble.org/api/packages/job79/generic/git-runner-mkosi/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+@l-@d.efi git-runner_@v+@l.efi git-runner_@v.efi MatchPattern=runneros_@v+@l-@d.efi runneros_@v+@l.efi runneros_@v.efi
Mode=0444
TriesLeft=3 TriesLeft=3
TriesDone=0 TriesDone=0
InstancesMax=2 InstancesMax=2
@@ -1,2 +0,0 @@
# The runner's user.
u gitea-runner - "Gitea Actions runner" /var/lib/gitea-runner
@@ -0,0 +1,28 @@
# 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/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
@@ -1,9 +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
# Home directory; holds the registration (.runner) and the actions cache. # registration (/etc/gitea-runner/config.yaml).
d /var/lib/gitea-runner 0700 gitea-runner gitea-runner - d /var/lib/gitea-runner 0700
# podman's own line makes this 0700; the runner needs to reach podman.sock inside (podman.socket.d).
# This file sorts before podman.conf, so its line wins. # The storage of root's podman is wiped at every boot, so images and leftovers
D! /run/podman 0750 root gitea-runner - # of jobs don't pile up. gitea-runner.service loads the job image again.
# 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.
R /var/lib/containers/storage R /var/lib/containers/storage
+19 -20
View File
@@ -1,25 +1,24 @@
#!/bin/bash #!/bin/bash
# First boot: ask for the root password and the runner's registration. # gitea-runner-setup asks on the console for the number of parallel jobs and
# the runner's registration, and registers the runner. gitea-runner.path then
# starts it. gitea-runner-setup.service runs it until the runner is registered.
#
# The capacity goes to a drop-in of gitea-runner.service, which passes it to
# /etc/gitea-runner/config.yaml as CAPACITY. It is written first, because the
# runner starts as soon as it is registered.
set -euo pipefail 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
echo "root:$pw" | chpasswd
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 read -rp "Parallel jobs [1]: " capacity
[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1 [[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1
hostnamectl hostname "$name" mkdir -p /etc/systemd/system/gitea-runner.service.d
install -D -m 0640 -g gitea-runner /dev/stdin /etc/gitea-runner/runner.env <<ENV printf '[Service]\nEnvironment=CAPACITY=%s\n' "$capacity" \
GITEA_INSTANCE_URL=$url > /etc/systemd/system/gitea-runner.service.d/capacity.conf
GITEA_RUNNER_REGISTRATION_TOKEN=$token systemctl daemon-reload
GITEA_RUNNER_CAPACITY=$capacity
ENV export CAPACITY=$capacity
echo "Done. The runner registers itself within a few seconds." until [[ -f /var/lib/gitea-runner/.runner ]]; do
read -rp "Gitea URL: " url
read -rp "Registration token: " token
gitea-runner -c /etc/gitea-runner/config.yaml register --no-interactive \
--instance "$url" --token "$token" || echo "Try again."
done
Executable
+8
View File
@@ -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"
+23
View File
@@ -0,0 +1,23 @@
# mkosi.conf builds the job image, the container that jobs with
# runs-on: linux run in. It is an OCI image, which the OS ships in
# /usr/lib/runneros/job (ExtraTrees= in /mkosi.conf), so it is signed and
# updated with the OS. gitea-runner.service loads it into podman at boot.
#
# Packages holds what common actions need. Jobs install more with dnf.
[Output]
Format=oci
Output=job
[Content]
WithDocs=no
Packages=
dnf5 # Jobs install what else they need.
fedora-repos # dnf needs to know the repositories.
git-core # Checkouts are done with git.
nodejs26 # JavaScript actions run on node.
podman # Jobs build and run containers.
curl
tar # actions/cache and artifacts use these.
gzip
zstd
findutils
+12 -9
View File
@@ -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"
+2 -1
View File
@@ -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
+8 -2
View File
@@ -1,11 +1,17 @@
# /usr, slot A: read-only erofs, protected by dm-verity (usrhash= in the UKI). # 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] [Partition]
Type=usr Type=usr
Label=%M_%A Label=%M_%A
Format=erofs Format=erofs
Compression=zstd Compression=lz4hc
CopyFiles=/usr:/ CopyFiles=/usr:/
Verity=data Verity=data
VerityMatchKey=usr VerityMatchKey=usr
SizeMinBytes=1G SizeMinBytes=1G
SizeMaxBytes=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
+4 -3
View File
@@ -1,8 +1,9 @@
# dm-verity hashes of /usr, slot A. # 11-usr-verity.conf holds the dm-verity hashes of /usr in 10-usr.conf.
[Partition] [Partition]
Type=usr-verity Type=usr-verity
Label=%M_%A_verity Label=%M_%A_verity
Verity=hash Verity=hash
VerityMatchKey=usr VerityMatchKey=usr
SizeMinBytes=64M SizeMinBytes=16M
SizeMaxBytes=64M SizeMaxBytes=16M
SplitName=%t.%U
+2 -1
View File
@@ -1,4 +1,5 @@
# /usr, slot B: empty until systemd-sysupdate writes the next version. # 20-usr-b.conf defines /usr in slot B. It stays empty until systemd-sysupdate
# writes the next version to it.
[Partition] [Partition]
Type=usr Type=usr
Label=_empty Label=_empty
+4 -3
View File
@@ -1,7 +1,8 @@
# dm-verity hashes of /usr, slot B. # 21-usr-verity-b.conf holds the dm-verity hashes for 20-usr-b.conf, empty
# until the next update.
[Partition] [Partition]
Type=usr-verity Type=usr-verity
Label=_empty Label=_empty
SizeMinBytes=64M SizeMinBytes=16M
SizeMaxBytes=64M SizeMaxBytes=16M
SplitName=- SplitName=-
-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
+8 -3
View File
@@ -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"