Files
gitea-ci-in-gvisor/README.md
T

216 lines
6.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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:
```text
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
```text
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
```text
networks:
caddy external
gitea bridge
ci bridge
services:
server Gitea, on caddy + gitea
dind gVisor Docker-in-Docker, on ci
runner act_runner, on gitea + ci
```
### Persistent paths
```text
./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:
```json
{
"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
```bash
# 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:
```bash
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.
If the runner has not been registered yet, provide a registration token on the
first boot. One way is to add this to the `runner` service temporarily:
```yaml
environment:
GITEA_RUNNER_REGISTRATION_TOKEN: <token>
```
Then start the runner once, confirm `./runner/.runner` exists, and remove the
token from the Compose environment again.
The public Gitea instance is expected at:
```text
https://gitea.ct.cozytren.ch
```
## Runner configuration
`runner/config.yaml` defines:
- capacity `1`
- labels:
- `ubuntu-latest` → `node:22-bookworm`
- `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/`:
```text
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:
```yaml
command: --no-overlay
```
This skips the RAM-backed tmpfs at `/var/lib/docker` and uses the disk-backed
`./dind-data` volume instead, so image/build storage is not capped at a fixed
tmpfs size. The startup script also disables Docker 29's containerd snapshotter
for this mode.
If you prefer a bounded RAM-backed store, remove `command: --no-overlay` and set
`DOCKER_TMPFS_SIZE` explicitly:
```yaml
environment:
DOCKER_TMPFS_SIZE: 5G
```
## 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
```text
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
```