Files
akyldash/docs/operations/CI_RUNNER.md
T
agent 7701e77b3d
CI / tests-and-images (pull_request) Failing after 12s
Runner smoke test / runner-smoke (pull_request) Successful in 4s
fix: restrict runner log ACL across rotation
2026-10-14 23:47:57 +03:00

14 KiB

AkylDash Gitea Actions runner

Scope and isolation

The deployment follows the official Gitea 1.25 act_runner guide for repository-scoped registration. Gitea warns that access to a Docker daemon is root-equivalent; the dedicated rootless daemon is used instead of the production daemon. The pinned binary and checksum are published in the official Gitea download directory.

The runner is reserved to repository admin/akyldash, using the token under https://git.vakanaut.ru/admin/akyldash/settings/actions/runners. Do not use organization or instance runner settings. Pin the official act_runner 0.2.13 x86_64 binary from dl.gitea.com; the installer verifies its SHA-256 before placing it on the host.

CI jobs run in docker.gitea.com/runner-images:ubuntu-24.04 containers with capacity 1, per-job limits of 2 CPU, 3 GiB RAM and 512 processes, and a 15 GiB dedicated ext4 loop-backed Docker data filesystem. The runner account's home directory is root-owned mode 0711, so CI cannot rename the image or mountpoint entries. Docker config remains under .config; registration state and the runner workspace live in .config/act-runner, which is runner-owned. The rootless Docker setup and user service use .config/act-runner as writable HOME, .config as XDG_CONFIG_HOME, and .config/act-runner/.local/share as XDG_DATA_HOME. This keeps Docker config and its systemd user unit in the existing .config tree without granting write access to the protected home.

The runner system service uses ProtectHome=read-only. ProtectHome=yes hides /run/user, which contains the rootless Docker socket needed by the runner service; read-only protection keeps that path visible without making home paths writable. The installer accepts only the known prior unit with this one-line difference and refuses any other service-unit drift. The rootless Docker daemon and runner user are separate from production Docker; codex is not added to sudo or Docker groups. Jobs do not receive the rootless Docker socket, the production Docker socket, production environment/secrets, or arbitrary host bind mounts. The runner account has no access to /etc/akyldash or the root-owned application checkout. These are host permission boundaries, not a claim that untrusted project code is safe; review workflow changes and actions before merging them.

The runner service restarts on failure and boot. Systemd caps the runner account's shared slice to 2.5 CPU, 4 GiB RAM and 2048 tasks; the rootless daemon is separately capped to 2 CPU, 4 GiB and 1024 tasks, while each job has the limits above. Runner logs go to a rotated file (10 MiB, 7 copies). A systemd timer checks the runner service and the rootless Docker API each minute; on failure it restarts the fixed runner service. No UFW changes or public metrics ports are needed. Runner cache is disabled.

The runner daemon log is /var/log/akyldash-runner/act_runner.log. The installer keeps its directory root-owned, grants codex only search permission on that directory, and limits file access to the runner owner plus a named read-only ACL for codex; group and other users have no file access. Systemd starts with UMask=0077, and its fixed ExecStartPost command reapplies the file ACL. Logrotate uses copytruncate and reapplies the same ACL after each rotation. This access is limited to the runner daemon log; it does not grant access to runner registration state, job workspaces, Docker state, or Gitea workflow logs. The daemon log records task dispatch metadata, not step output.

The registered project label is akyldash-ci, mapped to the pinned docker.gitea.com/runner-images:ubuntu-24.04 image. Both ci.yaml and runner-smoke.yaml target this exact project label; neither uses the generic ubuntu-latest label. The runner inventory API is owner-only, so the current API account cannot independently list the registered labels; the owner reports that the runner is Idle and the smoke workflow succeeds.

The job container receives neither the rootless Docker socket nor the system Docker socket (container.docker_host: "-"). The CI operations have different engine requirements:

Operation Purpose Engine requirement
docker compose ... config --quiet Interpolate and validate production Compose configuration Compose client only; this command does not start containers or contact a daemon.
Caddy validate Check the production Caddyfile syntax and directives Caddy binary only; CI downloads the exact version used by the pinned image and checks its SHA-512.
docker build for backend and OpenSearch Exercise Dockerfile instructions, base-image resolution, and the OpenSearch plugin install A container builder is required; ordinary Python/shell tests cannot replace this check.

Do not run rootless BuildKit inside the current job container. The official BuildKit rootless container recipe requires relaxing seccomp/AppArmor and system path restrictions; its documented no-process-sandbox fallback lets build steps signal processes in the BuildKit daemon and is explicitly discouraged. This runner intentionally keeps its job security profile intact.

The recommended image-build path is a separate, disposable BuildKit VM, with the current runner acting only as a buildctl client. Run BuildKit as a non-root account with its own subordinate UID/GID range and scratch disk; use mutual TLS over a private network, no Docker socket, no production credentials, no route to production, one build at a time, and delete the VM and cache after the job. Keep the test job on akyldash-ci; place image builds in a dependent job on a separate builder label. This keeps arbitrary PR Dockerfile commands off the runner and production host kernel. Gitea 1.25.5 and act_runner 0.2.13 need no special BuildKit integration: the workflow invokes pinned buildctl against the remote BuildKit API.

For a first sizing estimate, allocate the disposable builder 2 vCPU, 4 GiB RAM, and 10 GiB temporary disk at concurrency 1. Disable persistent cache or cap it to 6 GiB with BuildKit garbage collection; remove OCI output archives after validation. These are starting limits, not measured requirements. Reduce them only after recording peak memory and disk use for both Dockerfiles. The current VPS has 7.7 GiB RAM and the runner already has 3 GiB job / 4 GiB account limits, so colocating a builder there would contend with jobs and share the host kernel; it is not the recommended deployment.

Provisioning that disposable VM and private network is an owner-level bootstrap step. It must pin BuildKit and its checksum, create the non-root account and subuid/subgid mapping, enforce CPU/RAM/disk and single-job limits, expose only a TLS-authenticated BuildKit endpoint to the runner, issue a short-lived per-job client certificate, and destroy the VM after the build. Do not enable --privileged, relax seccomp/AppArmor, set --oci-worker-no-process-sandbox, mount either Docker socket, or provide production secrets. Until this bootstrap is approved and available, keep both image builds required and expect the full CI job to remain blocked at those steps. Production deployment is not automated.

Installation and registration

Review the root script and host audit output before running it. It installs uidmap, dbus-user-session, curl, logrotate, and Docker's rootless extras; creates the dedicated system user and selects the first free, shared 65536-ID range from /etc/subuid and /etc/subgid; reserves 15 GiB for runner images/workspaces; and configures systemd services. It starts only the separate rootless Docker daemon; the runner and health timer stay disabled until repository registration. It does not change SSH/UFW, production Docker configuration, application data, or production secrets. It can be rerun after partial setup: it validates and reuses an existing runner account, subordinate ID mappings, image, and mount unit. An existing image must be exactly 15 GiB and contain ext4; a mismatch stops the installer without resizing or formatting it. The runner account must retain a non-root system UID below UID_MIN, its expected home, primary group, and sole supplementary group. After validating the account, the installer locks its home directory to root ownership and mode 0711; it refuses to rerun while the runner service is active, so it cannot interrupt a job. The mount is started only when it is not already active, and an active mount must be the expected ext4 loop device backed by the runner image with both nosuid and nodev active. Runner-home directories and user configuration files are created in runner-owned subdirectories. Root creates only the first .config entry beneath the already locked home; subsequent directory and config writes run as akyldash-runner. The installer rejects static symlinks and validates ownership and mode after setup. This also normalizes the 0755 intermediate directories left by the first installer version. Conflicting files or state stop the installer for manual inspection. A new image requires at least 25 GiB free on /. Image creation opens each parent component without following symlinks, creates the image exclusively relative to the opened directory, and passes the open file descriptor to mkfs.ext4; validation checks the same inode and rejects path replacement. Systemd mounts the image under the root-owned home entry, which the runner cannot replace after validation.

If the reviewed checkout is not present at the inventoried path, first verify that the target is absent and clone the reviewed main there. Do not overwrite an existing checkout.

sudo test ! -e /opt/akyldash/current
sudo git clone --branch main \
  --single-branch https://git.vakanaut.ru/admin/akyldash.git \
  /opt/akyldash/current

From that root-owned reviewed checkout on the VPS:

sudo bash /opt/akyldash/current/infra/runner/install-runner.sh

Then, as a repository owner, open repository Settings → Actions → Runners, create a repository-level runner, and copy its registration token locally. Do not send the token in chat or save it in the checkout. Register interactively in a terminal so it is not placed in shell history or process arguments:

sudo -u akyldash-runner env HOME=/var/lib/akyldash-runner/.config/act-runner \
  /usr/local/bin/act_runner \
  --config /etc/akyldash-runner/config.yaml register

Enter https://git.vakanaut.ru/, the token, runner name akyldash-ci-vps-01, and label akyldash-ci:docker://docker.gitea.com/runner-images:ubuntu-24.04 when prompted. The config sets the label and capacity; verify them in the repository runner settings. The token is saved only in the mode-0700 runner runtime directory, outside Git. Start/enable the runner after registration:

sudo systemctl enable --now akyldash-act-runner.service
sudo systemctl enable --now akyldash-runner-healthcheck.timer
sudo systemctl status akyldash-act-runner.service
sudo systemctl status akyldash-runner-healthcheck.timer

The interactive command's terminal behavior should be confirmed before pasting the token. If it echoes input, stop and use the repository settings to revoke that token; do not put it in command-line arguments or environment variables.

Validation

  1. Confirm the runner is Online in the repository runner settings, with the expected name and akyldash-ci label.
  2. Confirm Runner smoke test runs for the open PR (or dispatch it manually). It checks that production sockets, files, environment secrets, and writable application paths are not present in the job container.
  3. Confirm the run reports the expected runner, succeeds, and the runner service and health timer remain active.
  4. Confirm both workflows target akyldash-ci, and verify the container has no system or runner-account Docker socket, production secret, writable host checkout, or privileged execution. Do not add a production deploy workflow or secrets to this runner until a separate restricted deploy mechanism is reviewed.

Upgrade

Update runner_version and its expected official SHA-256 together in infra/runner/install-runner.sh, review upstream release compatibility with the installed Gitea, and open a PR. Do not replace the binary while a job is active. Stop the runner, install/verify the new binary, then start it and confirm Online plus a smoke run. Preserve /var/lib/akyldash-runner/.config/act-runner/.runner.

Recovery and rollback

The runner is disposable: production data and secrets are not on its filesystem. For a runner process failure, inspect systemctl status and journalctl -u akyldash-act-runner.service; restart the fixed runner service. If installation stops after creating or enabling the mount unit, inspect the image and mount with stat, blkid, findmnt, and losetup, then rerun the reviewed installer only when the image is 15 GiB ext4 and the active mount is backed by it. The installer recognizes that state and does not format or restart the mounted filesystem. If size, filesystem, unit contents, or backing device differ, stop and resolve the state manually; never format the existing image as a retry. For lost/corrupt registration state, stop the service and obtain a fresh repository-level token from Settings → Actions → Runners. Preserve the 15 GiB data image and state for diagnosis; re-register only after the repository owner confirms/revokes the old runner in Gitea. The images/cache can be rebuilt from the workflow. Never format or remove an existing runner store as an automatic recovery step.

Status

The owner reports that the repository-level runner is registered and Idle, and that runner-smoke.yaml succeeds. Read-only checks on 2026-10-14 confirmed the runner service and health timer are active, the runner account has no supplementary groups, and the active service uses the rootless Docker socket. The live service has ProtectHome=read-only; the installer still needs the PR update applied by an owner-run command after merge. Read-only SSH now confirms that act_runner 0.2.13 declares [akyldash-ci] and accepts task 301; its log does not include workflow step output. The Actions jobs API returns an empty list for completed run 49, so step details are not available through the current API account. The repository runner inventory API returns 403 to the current non-owner API account. PR #46 pins the narrow log ACL and its rotation hooks; this installer change has not been applied to the VPS.