gitea-ci-in-gvisor

Gitea Actions deployment with a gVisor-sandboxed Docker-in-Docker daemon for CI jobs. The runner talks to that daemon over a private Compose network; it does not receive a host Docker socket.

This repository mirrors the deployment layout used on the target host:

Gitea (Caddy + gitea networks)
  │
  ├── act_runner (gitea + ci networks)
  │       │  Docker API: tcp://dind:2375
  │       ▼
  └── dind (ci network, runtime: runsc-docker)
          │  Docker daemon inside gVisor
          ▼
      CI job containers

Container nesting

physical host
├── gitea container                 [host default runtime]  networks: caddy, gitea
├── runner container                [host default runtime]  networks: gitea, ci
└── dind container                  [runsc-docker]         network: ci
    └── CI job container            [runc inside gVisor]   created by dind

The target host defaults to runsc, so Gitea and the runner also run under gVisor unless the host configuration says otherwise. dind explicitly requests the runsc-docker runtime because it runs Docker inside the sandbox.

Compose layout

networks:
  caddy   external
  gitea   bridge
  ci      bridge

services:
  gitea   Gitea, on caddy + gitea
  dind    gVisor Docker-in-Docker, on ci
  runner  act_runner, on gitea + ci

Persistent paths

./gitea                      -> /data                 Gitea data
./dind-data                  -> /var/lib/docker       dind storage
./dind-runsc/resolv.conf     -> /etc/resolv.conf:ro   dind DNS
./runner                    -> /data                 act_runner config/state
/etc/timezone                -> /etc/timezone:ro      Gitea timezone
/etc/localtime               -> /etc/localtime:ro     Gitea timezone

The Gitea HTTP port is intentionally not published; it is expected to be fronted by Caddy through the external caddy network. SSH is published on host port 222.

Requirements

  • Docker with the runsc-docker runtime configured on the host.

  • The host daemon.json must define a runtime equivalent to:

    {
      "runtimes": {
        "runsc-docker": {
          "path": "/usr/bin/runsc",
          "runtimeArgs": [
            "--net-raw",
            "--allow-packet-socket-write"
          ]
        }
      }
    }
    
  • An external Docker network named caddy.

  • A Caddy configuration that routes the public Gitea hostname to the gitea container on port 3000.

  • ./dind-runsc/resolv.conf with usable DNS servers.

Usage

# Create the external reverse-proxy network once.
docker network create caddy

# Build the gVisor dind image and start the stack.
docker compose up -d --build

Check the stack:

docker compose ps
docker compose logs -f dind
docker compose logs -f runner

Runner registration

./runner is mounted as /data and must contain:

  • config.yaml — act_runner configuration (included here).
  • .runner — registration state, created on first registration.

The Compose file passes GITEA_RUNNER_REGISTRATION_TOKEN into the runner container. On first boot, put the token in .env:

cp .env.example .env
# edit GITEA_RUNNER_REGISTRATION_TOKEN
docker compose up -d runner

Then confirm registration:

docker compose logs -f runner
# look for: Runner registered successfully
ls -l runner/.runner

Remove the token from .env after .runner exists if you prefer. If a stale or invalid ./runner/.runner exists, remove it before retrying:

rm -f runner/.runner
docker compose up -d --force-recreate runner

If the public URL is not reachable from inside the runner container, use the internal Gitea address instead:

GITEA_INSTANCE_URL: http://gitea:3000

The public Gitea instance is expected at:

https://gitea.ct.cozytren.ch

Runner configuration

runner/config.yaml defines:

  • capacity 1
  • labels:
    • ubuntu-latest → docker.gitea.com/runner-images:ubuntu-latest
    • gvisor → alpine:3.20
    • docker → docker:28-cli
  • runner-side Docker host: tcp://dind:2375
  • job environment: DOCKER_HOST=tcp://127.0.0.1:2375
  • job networking: host inside the dind sandbox

Jobs run with host networking inside the gVisor sandbox, so loopback points at the dind daemon listening inside that sandbox. The runner itself reaches dind through the ci network.

Example workflows are in scripts/:

scripts/workflow-gvisor.yml     basic gVisor / isolation checks
scripts/workflow-docker.yml     Docker CLI inside the sandbox
scripts/workflow-compose.yml    a Compose stack inside the sandbox
scripts/workflow-resource.yml   disk / memory / CPU stress

dind storage and overlayfs

The dind image comes from the gVisor Docker-in-gVisor example under gvisor/images/basic/docker.

The default Compose configuration starts dind with:

command: --disk-store

This skips the RAM-backed tmpfs at /var/lib/docker and uses the disk-backed ./dind-data volume. It keeps Docker 29's containerd snapshotter enabled, which supports image layers containing security.capability xattrs.

The dind image is built from gvisor/images/basic/docker. Its startup script supports three modes:

(no flag)          RAM-backed tmpfs at /var/lib/docker
--disk-store       disk-backed volume, containerd snapshotter enabled
--no-overlay       disk-backed volume, containerd snapshotter disabled

If you prefer a bounded RAM-backed store, remove command: --disk-store and set DOCKER_TMPFS_SIZE explicitly:

environment:
  DOCKER_TMPFS_SIZE: 5G

Image pull fails with security.capability / lsetxattr

Example:

failed to register layer: lsetxattr /usr/bin/ping:
xattr "security.capability": operation not supported

This happens when dind uses --no-overlay (Docker 29 classic overlay2/vfs) on a host-backed volume. gVisor's host-backed filesystem path cannot set the security.capability xattr in that mode.

Use --disk-store instead. It keeps the containerd snapshotter enabled and the disk-backed volume, and image pulls with file capabilities work. The old --no-overlay mode is retained only for compatibility and is not recommended for runner images containing files such as /usr/bin/ping.

If you switch an existing deployment from --no-overlay to --disk-store, Docker may keep using the previous overlay2 storage driver because ./dind-data already contains initialized state. In that case docker info inside dind still shows:

Storage Driver: overlay2

and the xattr failure continues. Reset the dind store once:

docker compose stop dind
mv dind-data dind-data.old
mkdir dind-data
docker compose up -d dind
docker exec dind docker info | grep 'Storage Driver'

Expected after a clean start:

Storage Driver: overlayfs

Cached images and builds in the old dind store are discarded by this reset.

Networking details

  • dind has no published Docker API port.
  • runner reaches dind:2375 only over the private ci network.
  • CI jobs reach the dind daemon at 127.0.0.1:2375 because they share the dind sandbox network namespace.
  • dind has a custom resolv.conf mounted read-only. Keep it aligned with the DNS setup of the deployment host.
  • Docker’s embedded DNS inside nested user-defined networks can be limited because Docker-managed iptables is disabled inside gVisor. The Compose test uses a static IP plus extra_hosts for this reason.

Security model

  • No host /var/run/docker.sock is mounted into the runner or CI jobs.
  • The Docker daemon used by CI is itself inside a gVisor sandbox.
  • The Docker API is not published on a host port; it is reachable only from the ci Compose network.
  • CI job containers are created by the sandboxed dind daemon and remain inside that gVisor sandbox.
  • The dind container needs cap_add: ALL so Docker can operate inside the sandbox. Those capabilities are perceived inside gVisor, not granted on the host kernel.
  • The remaining security boundary is gVisor itself. Use a current gVisor release, a dedicated Docker host, and host firewall rules for untrusted CI.

Files

docker-compose.yml
runner/config.yaml
gvisor/images/basic/docker/Dockerfile
gvisor/images/basic/docker/start-dockerd.sh
dind-runsc/resolv.conf
scripts/workflow-*.yml
S
Description
Gitea Actions runner with gVisor-isolated CI jobs and a sandboxed Docker daemon for e2e tests
Readme
128 KiB
0 Stars 2 Watchers 0 Forks
Languages
Shell 96.8%
Dockerfile 3.2%