Self-hosted CTF: original web challenges + scoreboard, deployed with Docker Compose via GitLab CI and a GitOps agent. Flags derived from one CI secret; every pipeline deploys the stack and auto-solves every challenge.
A complete capture-the-flag event you can run yourself: four original web challenges, a scoreboard, and the GitLab CI/CD + GitOps machinery that builds, scans, deploys and plays the whole thing on every commit.
What it showcases
compose.yaml runs six hardened containers, with no bind mounts, so the
same file deploys to a laptop, a CI Docker-in-Docker service, or a remote host over SSH.depends_on ordering, resource limits, read-only root filesystems,
dropped capabilities, non-root users, and a persistent volume that survives redeploys.main is the desired state. A pull-based agent (ctfops reconcile, a systemd
timer) deploys a commit only after its pipeline passed, verifies it, and rolls back automatically if it
doesn't come up healthy. Rolling back on purpose is git revert.flowchart LR
players((Players)) -->|":8000"| gw
players -->|":9001-9004"| gw
subgraph host["Docker host (compose project 'ctf')"]
gw["gateway<br/>nginx, rate limits"]
subgraph sbnet["network: scoreboard (internal)"]
sb["scoreboard<br/>Flask + SQLite"] --- vol[("scoreboard-data")]
end
subgraph c1["net-paper-trail (internal)"]
pt["paper-trail"]
end
subgraph c2["net-cookie-jar (internal)"]
cj["cookie-jar"]
end
subgraph c3["net-bookworm (internal)"]
bw["bookworm"]
end
subgraph c4["net-fetch-docs (internal)"]
fd["fetch-docs"]
end
gw --> sb & pt & cj & bw & fd
end
Only the gateway sits on a routable network. Each challenge is alone on an internal network, so a player
who gets code execution in one challenge can reach neither the scoreboard, nor the other challenges, nor the
internet. ctfops verify-isolation proves this in CI from inside every container.
| Service | Image | Notes |
|---|---|---|
gateway | nginx-unprivileged (pinned digest) | Single ingress. 2 req/s per client on flag submission, 1 req/s on login/register, per-IP connection caps, no version banner. Resolves upstreams lazily, so one challenge being replaced never takes the platform down. |
scoreboard | Python 3.13 / Flask / gunicorn | Teams, flag submission (HTML + JSON API), ranking with first bloods, event window, admin stats. scrypt passwords, hashed API tokens, CSRF tokens, CSP. |
paper-trail, cookie-jar, bookworm, fetch-docs | one shared challenge.Dockerfile | Intentionally vulnerable apps, one per container. The reference solver is stripped from the image. |
All original. Point values live in ctf.toml, the single source of truth for the event.
| Challenge | Points | Description |
|---|---|---|
| Paper Trail | 100 | A billing portal with a guest account. |
| Cookie Jar | 150 | A staff noticeboard that remembers you with a cookie. |
| Bookworm | 200 | A library catalogue with a search box. |
| Fetch Docs | 200 | An internal docs viewer with a homemade path filter. |
| Challenge | Vulnerability | Reference exploit |
|---|---|---|
| Paper Trail | Insecure direct object reference: invoices check login, not ownership | log in as guest, walk invoice ids down to #1001 |
| Cookie Jar | Unsigned client-side session (base64 JSON) | decode the cookie, set "role": "admin", re-encode |
| Bookworm | SQL injection (SQLite) | UNION SELECT from sqlite_master to find a hidden table, then dump it |
| Fetch Docs | Path traversal past a one-pass ../ filter | ....// collapses to ../; read /proc/self/environ, where the flag was handed to the process |
Each exploit is implemented in challenges/<id>/solve.py and runs in every pipeline.
Requires Docker with the Compose plugin and Python 3.11+.
pip install -r requirements-dev.txt
export PYTHONPATH=src
python -m ctfops new-seed > .ctf-seed && chmod 600 .ctf-seed # gitignored; it IS every flag
python -m ctfops compose up -d --build --wait # build and start all six containers
python -m ctfops smoke --host localhost # play the CTF end to end
Open http://localhost:8000, register a team, and start hacking on ports 9001-9004.
python -m ctfops compose down -v removes everything, including the scoreboard data.
ctfops compose ... is docker compose ... with the derived secrets injected into Compose's process
environment. Each container receives only its own secret; a container started without one refuses to start,
so a deploy that forgot the seed fails loudly instead of serving a guessable flag.
| Stage | Jobs | What it proves |
|---|---|---|
| lint | python-lint, dockerfile-lint, compose-config | Ruff, Hadolint, Compose parses; ctfops validate checks that ctf.toml, compose.yaml, gateway/nginx.conf and the challenge folders describe the same platform, and that every service keeps its hardening and isolation |
| test | unit-tests, secret_detection, semgrep-sast | 100+ tests (each challenge exploited in-process by its solver, >90% coverage gate); GitLab Secret Detection: no flag or seed was committed; SAST on the platform code |
| build | build-images | docker compose build + push of all six images, tagged with the commit SHA |
| scan | trivy-images, trivy-config | Fails on fixable critical CVEs and on any secret found inside an image; Dockerfile misconfigurations |
| verify | deploy-ephemeral | Deploys the pushed images to a Docker-in-Docker host with a throwaway seed, then: health, security headers, challenge list, every challenge solved and scored, bad flags and bad tokens rejected, admin auth, gateway rate limiting, isolation probes, and a scoreboard recreate that must keep its data |
| release | promote-latest (main) | Moves :latest to the verified images |
| deploy | deploy-production (main, manual) | Push-mode deploy over SSH; only appears once DEPLOY_HOST is configured |
Everything runs on GitLab shared runners with the job token: no external credentials or servers. Merge request pipelines never see the real seed.
See docs/deploying.md: seed handling, host preparation, the pull-based GitOps agent
(deploy/systemd/), the push-mode job, and putting TLS in front.