Skip to content
Kaiov0.8.0

Forgejo

Forgejo is a self-hosted Git forge: repositories, issues, pull requests, packages, and Forgejo Actions for CI, through a separate runner. It is where an agent’s code lands, and the runner is where it gets built, which makes it a good stack to see Kaio’s host access check at work on something that needs it.

services:
forgejo:
image: codeberg.org/forgejo/forgejo:${FORGEJO_TAG:-17}
restart: unless-stopped
environment:
- USER_UID=1000
- USER_GID=1000
- FORGEJO__database__DB_TYPE=postgres
- FORGEJO__database__HOST=db:5432
- FORGEJO__database__NAME=forgejo
- FORGEJO__database__USER=forgejo
- FORGEJO__database__PASSWD=${POSTGRES_PASSWORD}
- FORGEJO__server__ROOT_URL=${ROOT_URL}
- FORGEJO__server__SSH_PORT=222
- RUNNER_SECRET=${RUNNER_SECRET}
ports:
- "127.0.0.1:3000:3000"
- "222:22"
volumes:
- forgejo:/data
depends_on:
db:
condition: service_healthy
db:
image: docker.io/library/postgres:17
restart: unless-stopped
environment:
- POSTGRES_USER=forgejo
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=forgejo
volumes:
- db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U forgejo -d forgejo"]
interval: 5s
timeout: 5s
retries: 10
docker:
image: docker.io/library/docker:dind
restart: unless-stopped
privileged: true
command: ["dockerd", "-H", "tcp://0.0.0.0:2375", "--tls=false"]
runner:
image: data.forgejo.org/forgejo/runner:${RUNNER_TAG:-13}
restart: unless-stopped
environment:
- DOCKER_HOST=tcp://docker:2375
command: ["forgejo-runner", "daemon", "--config", "/config.yml"]
configs:
- source: runner
target: /config.yml
depends_on:
- docker
- forgejo
configs:
runner:
content: |
server:
connections:
forgejo:
url: http://forgejo:3000/
uuid: ${RUNNER_UUID}
token: ${RUNNER_SECRET}
runner:
labels:
- docker:docker://node:20-bookworm
volumes:
forgejo:
db:
  • Everything Forgejo keeps, repositories included, is in the forgejo and db named volumes. Nothing is mounted from the host, so stack copy --with-volumes carries the whole forge.
  • The runner’s configuration is written by Compose itself, from configs.content, with its secret interpolated from Kaio’s environment: no file beside the compose.yml, nothing to forget on a copy. It needs Docker Compose 2.23 or later.
  • Jobs run in the docker service, a Docker daemon of the stack’s own, not on the host’s. The runner reaches it over the stack’s network only; port 2375 is published nowhere.
  • The web UI stays on the loopback for a reverse proxy to serve; SSH is published on 222, which SSH_PORT puts in the clone URLs.
FORGEJO_TAG=17
RUNNER_TAG=13
ROOT_URL=https://git.example.net/
POSTGRES_PASSWORD=generate-with-openssl-rand-hex-32
RUNNER_SECRET=generate-with-openssl-rand-hex-20
RUNNER_UUID=

RUNNER_SECRET must be 40 hexadecimal characters, which is what openssl rand -hex 20 prints. Both it and the database password are flagged as secrets by their names. RUNNER_UUID stays empty until step 4.

Terminal window
kaio-cli stack deploy forgejo ./compose.yml --env-file .env
Error: deploy stack refused: This file hands the host to a service: docker runs privileged, with every device and capability of the host. Nothing was deployed. Rerun with --accept-risks to go ahead anyway

That is the Docker-in-Docker service, and the refusal is right: a privileged container is root on the host, and the jobs it runs come from whoever can push a workflow to the forge. Nothing ran. Deploying it is a second command, made on purpose:

Terminal window
kaio-cli stack deploy forgejo ./compose.yml --env-file .env --accept-risks
Stack forgejo deployment started.
warning: docker runs privileged, with every device and capability of the host

The deploy leaves a warn event naming the risk, and the stack keeps the HOST ACCESS mark on its row, and kaio_stack_host_access{stack="forgejo"} reads 1, for as long as the file asks for it. It is the price of building containers in CI. Pay it on purpose: run this stack on a node of its own, or drop the docker and runner services and keep the forge alone, which carries no mark at all.

The runner restarts in a loop for now, since it is not registered yet. Open http://localhost:3000: the first visit is Forgejo’s installation page, with the database already filled in from the variables, and it creates the administrator.

Forgejo registers a runner from its shared secret, offline. Open a shell in the forgejo container and run it as the git user:

Terminal window
kaio-cli container shell <forgejo-container>
su git -c "forgejo forgejo-cli actions register --name kaio-runner --secret $RUNNER_SECRET"

It prints a UUID. Hand it to the stack and apply, accepting the same risk again, since an apply brings the file up as a deploy does:

Terminal window
kaio-cli stack env set forgejo RUNNER_UUID=<the-uuid>
kaio-cli stack apply forgejo --accept-risks

The apply rewrites the runner’s configuration with the UUID, the runner connects, and it appears in Forgejo’s site administration under Actions. A workflow with runs-on: docker now runs in a node:20-bookworm container on the stack’s own daemon. See Forgejo’s runner configuration for more labels.

To rotate the secret, change its last 24 characters, register again with the new value, then stack env set and stack apply --accept-risks.

Terminal window
kaio-cli stack check-update forgejo # did the 17 tag move?
kaio-cli stack update forgejo --wait
kaio-cli stack scan forgejo
kaio-cli stack versions forgejo

--wait answers once every container runs again and Postgres passes its healthcheck, and puts back the images the stack ran before when it does not get there.

17 follows the latest minor release of that major version. Moving to the next major is a stack env set forgejo FORGEJO_TAG=... and an apply, after reading Forgejo’s release notes and backing up the two volumes: a rollback restores the tag, not the database migrations the newer version ran.

An update pulls the images and recreates the containers without asking, since the file does not change. An apply or a rollback is refused until it is run with --accept-risks, and through MCP an agent at write gets the same refusal on kaio_stack_apply, kaio_stack_rollback and kaio_stack_copy until it passes accept_risks, because the file asks for privileged. That is the point: the privileged daemon stays a decision a person made.

Kaio, built by Régis Gaidot