The purpose of this repository is to propose a simple setup and challenge management tool for CTFd infrastructures. It has been tested and validated on PolyCyber's CTFd infrastructures (PolyPwn2025, PolyPwn2026, as well as the internal CTFd for PolyCyber).
Bash script that automates the installation and configuration of a CTFd server using the Zync plugin and its dedicated instancer Galvanize.
Bash script for building, ingesting, and synchronizing CTF challenges with support for Docker containers and Docker Compose.
Optional, opt-in add-ons, not installed by setup.sh: a CTFd plugin that records real client IPs behind Cloudflare, a Discord solve/first-blood bot, and a Python challenge sync. See extras/README.md.
- Operating System: Tested and verified on:
- Ubuntu Server 24
- Ubuntu Server 25
- Debian 12
- Privileges: The script must be executed as root (automatically uses sudo if necessary)
- Docker: Installed and functional
- curl, jq, yq: For API calls and YAML/JSON processing (automatically verified)
- Challenge repository: Folder structure with
challenge.ymlfiles
-
Clone this repository:
git clone https://github.com/CorentinFelten/ctfd-management cd ctfd-management -
Run the installation script and follow the instructions:
./setup.sh --domain <your-domain.com> --acme-email <you@example.com> \ --admin-name <admin> --admin-email <admin@example.com> --user-mode teams --ctf-name "<Event name>"
The script asks for the first admin's password at the start, then runs unattended. CTFd goes live already set up (see First admin and CTFd setup).
-
Go to the configured server URL
- Log in with the admin account created by the script
- Navigate to the admin configuration panel:
Admin Panel-->Plugins-->Zync Config - Check the Galvanize instancer URL and JWT secret (both are pre-filled by the setup, see below)
Instancer URL and JWT secret: with the provided setup workflow, both are injected automatically into the CTFd container from
deploy/.env:ZYNC_DEPLOYER_URL(https://instancer.<domain>for the bundled instancer) andZYNC_JWT_SECRET. The same secret is written to the Galvanize config. You therefore do not need to enter either value manually in the Zync Config panel.
| Option | Description | Required |
|---|---|---|
--domain domain/IP |
URL/domain of your CTFd server | ✅ Yes |
--admin-name NAME |
First admin's user name (the password is asked for during the run) | ✅ New deployment |
--admin-email EMAIL |
First admin's email address | ✅ New deployment |
--user-mode MODE |
teams or users |
✅ New deployment |
--ctf-name NAME |
Event name (default: "CTFd") | ❌ No |
--ctf-description TEXT |
Event description | ❌ No |
--team-size N |
Maximum team size (teams mode) | ❌ No |
--working-folder DIR |
Working directory (default: your home directory, /root when run as root) |
❌ No |
--theme SOURCE |
Install a custom theme: a folder or a Git URL (#ref for a branch/tag). Repeatable |
❌ No |
--remove-theme NAME |
Remove an installed custom theme. Repeatable | ❌ No |
--active-theme NAME |
Make NAME CTFd's active theme | ❌ No |
--backup-schedule TYPE |
Database backup frequency (daily (default), hourly, 10min) |
❌ No |
--backup-remote REMOTE:PATH |
Also upload every backup to a bucket, with rclone (see Backups) | ❌ No |
--backup-rclone-config FILE |
rclone config defining the remote | ❌ No |
--backup-remote-retention DAYS |
Delete uploaded backups older than DAYS (default: 30, 0 keeps all) | ❌ No |
--no-backup-remote |
Stop uploading backups | ❌ No |
--instancer-url URL |
Use an external Galvanize instancer instead of deploying one locally | ❌ No |
--no-instancer |
Skip Galvanize setup entirely (deploy it separately later) | ❌ No |
--dns-provider NAME |
DNS provider for wildcard TLS certs (default: cloudflare) |
❌ No |
--acme-email EMAIL |
Email address for Let's Encrypt certificates (required for HTTPS) | ✅ HTTPS |
--no-https |
Deployment without HTTPS (automatically enabled for IP addresses) | ❌ No |
--yes |
Answer every prompt with its default, for unattended runs (see below) | ❌ No |
--help |
Display help | ❌ No |
--instancer-urland--no-instancerare mutually exclusive.
--domainmust be an address players can reach: loopback addresses (127.0.0.1,localhost,::1) and0.0.0.0are rejected. The Galvanize instancer also connects to this address over SSH from inside its container, where a loopback address is the container itself. For an IP deployment, use the server's real IP (ip -4 route get 1.1.1.1shows it).
Unattended runs (
--yes): every prompt takes its default answer. On a re-run this recreates the Ansible SSH key pair (the instancer container is recreated to pick it up). The DNS provider wizard cannot ask for credentials, so for HTTPS deployments they must already be indeploy/traefik.env, or be passed in the root environment (sudo CF_DNS_API_TOKEN=... ./setup.sh ... --yes). Without--yes, a prompt with no terminal attached (CI, cron) fails with a message pointing to--yes.
The first-run options (--admin-name, --admin-email, --user-mode) are needed on a new deployment and left out of the examples below for brevity.
# Basic installation with domain (includes local Galvanize instancer by default)
./setup.sh --domain example.com --acme-email admin@example.com
# Basic installation with IP address - automatically uses the --no-https option
./setup.sh --domain 192.168.123.123
# Installation with custom directory
./setup.sh --domain example.com --working-folder /opt/ctfd
# Installation with custom theme
./setup.sh --domain example.com --theme /home/user/my-custom-theme
# Installation with custom theme downloading a theme directly from github
./setup.sh --domain example.com --theme https://github.com/user/theme.git
# Several themes, one pinned to a Git tag, and pick the active one
./setup.sh --domain example.com --theme https://github.com/user/theme.git#v2.0 \
--theme ./second-theme --active-theme theme
# Custom ACME email for Let's Encrypt
./setup.sh --domain example.com --acme-email admin@example.com
# Hourly backup
./setup.sh --domain example.com --backup-schedule hourly
# Backup every 10 minutes
./setup.sh --domain example.com --backup-schedule 10min
# Also upload every backup to a bucket (any rclone remote, see Backups)
./setup.sh --domain example.com --backup-remote offsite:ctfd-backups/prod --backup-rclone-config ./rclone.conf
# Use an external Galvanize instancer
./setup.sh --domain example.com --instancer-url https://instancer.example.com
# Skip Galvanize entirely (deploy it independently later)
./setup.sh --domain example.com --no-instancer
# Display help
./setup.sh --helpCTFd's web setup wizard is disabled: Traefik never routes /setup. Instead, setup.sh creates the first admin account and the event settings from the command line, as soon as CTFd starts, so the instance goes live already set up. Nobody can claim it through the browser in the meantime, which the public wizard allowed until someone completed it.
On a new deployment, these options are mandatory. The script stops before changing anything on the system if one is missing or invalid:
--admin-nameand--admin-email: the first admin's user name (which cannot be an email address) and email address.--user-mode teams|users: CTFd's mode. CTFd itself requires a choice, and the mode cannot be changed later without deleting every account.- The admin password, which is asked for at the start of the run (hidden, typed twice). It never appears on a command line and is never written to disk: it stays in the script's memory and reaches CTFd on standard input, and CTFd stores only its hash. For unattended runs (
--yes), set it in theCTFD_ADMIN_PASSWORDenvironment variable and keep it throughsudo:read -rs CTFD_ADMIN_PASSWORD && export CTFD_ADMIN_PASSWORD sudo --preserve-env=CTFD_ADMIN_PASSWORD ./setup.sh --domain example.com ... --yes
Optional: --ctf-name (CTFd shows "CTFd" otherwise), --ctf-description, --team-size (teams mode), and --active-theme, which is applied as part of the setup. Every other setting keeps CTFd's default (challenges visible to logged-in users only, public registration and scoreboard, no email verification) and can be changed in the admin panel.
Once CTFd is set up, later setup runs skip this step: the first-run options are not needed, and are ignored if given. Blocking /setup also blocks /setup/integrations (MajorLeagueCyber integration), which this setup does not use.
--theme installs a custom theme, and can be given any number of times. Each source is a local folder or a Git URL; append #REF to a Git URL to clone a branch or tag (https://github.com/user/theme.git#v2.0). The theme is named after the folder or repository (theme here), and must contain a templates/ folder. The names core, core-deprecated and admin are CTFd's own themes and are refused.
Themes are built into the CTFd image: they are kept in <working-folder>/deploy/ctfd/themes/<name>/, and Dockerfile.ctfd copies that folder next to CTFd's built-in themes. They therefore stay installed on later setup runs, including runs without --theme; giving a theme again updates it, and --remove-theme NAME removes it. Editing a theme in place takes effect after the image is rebuilt (docker compose build ctfd && docker compose up -d in deploy/, or a setup run).
Installed themes appear in CTFd under Admin Panel → Config → Themes. --active-theme NAME selects one from setup (core switches back to the default theme). On a new deployment it is applied as part of CTFd's setup, so the instance goes live with it.
Deployments made before this change mounted a single theme from deploy/data/CTFd/themes/<THEME_NAME>; the next setup run copies it into the image automatically.
setup.sh installs a cron job (--backup-schedule, daily by default) that runs deploy/backup/backup_db.sh. Each run writes two archives to <working-folder>/backups/, keeping the 5 most recent of each:
ctfd_backup_<date>.tar.gz: the MariaDB database, CTFd's uploads, and the Galvanize instancer's database (deployments and published port bindings, copied consistently while Galvanize runs). Restore it withdeploy/backup/restore_db.sh <archive>(orlatest), which stops Galvanize while its database is replaced.ctfd_config_<date>.tar.gz(chmod 600): the deployment's.env,.secretsandtraefik.env, needed to rebuild the server. It holds every secret of the deployment, so it is never uploaded off-site (see below) and is not restored automatically: extract what you need from it withtar -xzf.
With --backup-remote, every ctfd_backup_* archive is also uploaded to a bucket, right after it is created (the config archive stays on the server). The upload uses rclone, so any provider rclone supports works: AWS S3 and S3-compatible storage (Cloudflare R2, Backblaze B2, Wasabi, OVHcloud, Scaleway, MinIO…), Google Cloud Storage, Azure Blob Storage, SFTP and many more. Setup installs rclone and checks that the bucket can be written to before finishing, so wrong credentials fail at setup time, not at the first backup.
--backup-remote takes an rclone REMOTE:PATH. Define the remote once with rclone config (on any machine) and pass the resulting file with --backup-rclone-config:
# Cloudflare R2, Backblaze B2, Azure, GCS…: a remote named "offsite" in rclone.conf
./setup.sh --domain example.com --acme-email admin@example.com \
--backup-remote offsite:ctfd-backups/prod --backup-rclone-config ./rclone.confCredentials that come from the server itself (an AWS instance role, GCP workload identity) need no config file: use an rclone connection string instead:
./setup.sh --domain example.com --acme-email admin@example.com \
--backup-remote ':s3,provider=AWS,env_auth=true,region=eu-west-3:ctfd-backups/prod'- The config is stored in
deploy/backup/rclone.conf(chmod 600, owned by the user the cron job runs as). The settings are kept on later setup runs; change them by passing the options again, or stop uploading with--no-backup-remote. - Uploaded archives older than 30 days are deleted after each upload. Change this with
--backup-remote-retention DAYS, or use0to keep everything (for example to let the bucket's own lifecycle rules handle expiry). - A failed upload keeps the local archive and makes the backup run fail, with the details in
<working-folder>/backups/backup.logand the cron log. - The uploaded archives hold the whole CTFd database, including flags and password hashes. To encrypt them before they leave the server, whatever the provider, point
--backup-remoteat an rclonecryptremote that wraps the bucket.
To restore from the bucket, for example on a new server after running setup there with the same --backup-remote:
rclone --config deploy/backup/rclone.conf lsf offsite:ctfd-backups/prod
rclone --config deploy/backup/rclone.conf copy offsite:ctfd-backups/prod/ctfd_backup_<date>.tar.gz ~/backups/
deploy/backup/restore_db.sh ~/backups/ctfd_backup_<date>.tar.gzBy default, setup.sh deploys Galvanize as part of the CTFd Docker Compose stack. Two alternatives are available:
--instancer-url URL— point CTFd at an already-running Galvanize instance; no local container is started.--no-instancer— skip Galvanize entirely during setup. You can deploy it independently later with its own config (seeconfig/galvanize/config.yamlfor the config template andconfig/galvanize/playbooks/for the Ansible playbooks).ZYNC_DEPLOYER_URLdefaults tohttps://instancer.<domain>; update it indeploy/.envif your instancer lives elsewhere.
setup.sh records the choice in deploy/.env as COMPOSE_PROFILES (instancer for the bundled instancer, empty otherwise), so plain docker compose up -d, down or pull run from deploy/ start and manage the instancer only when it is hosted locally. Switching away from the bundled instancer stops and removes its container on the next setup run.
The template config/galvanize/config.yaml is copied to deploy/data/galvanize/config.yaml on every run of setup.sh, so make lasting changes in the template rather than in the deployed copy. The setup then fills in:
| Key | Value |
|---|---|
auth.jwt_secret |
Generated secret (shared with CTFd as ZYNC_JWT_SECRET) |
instancer.ansible.user / inventory |
ansible-user on the --domain host |
instancer.instancer_host |
--domain, or <ip>.sslip.io for IP deployments (wildcard DNS) |
instancer.redis.addr / db |
redis:6379, db 1 (CTFd uses db 0 on the same Redis) |
instancer.extra_deployment_parameters.traefik_network |
<COMPOSE_PROJECT_NAME>_challenges (see Network isolation) |
instancer.metrics.username / password |
prometheus and a generated password (GALVANIZE_METRICS_PASSWORD): basic auth on Galvanize's Prometheus metrics, served on port 5001 of the instancer container, reachable only from the deployment's internal Docker network. A Prometheus scraping it uses these credentials |
Other defaults: TCP host ports are randomized per team (randomize_published_ports: true), and every challenge container is limited to 1 CPU, 512 MB of RAM and 256 PIDs unless the challenge overrides resource_limits.
The Ansible playbooks (http, tcp, custom_compose) are shipped in config/galvanize/playbooks/ and copied to deploy/data/galvanize/playbooks/ on every setup run. The data/ bind mount hides the playbooks baked into the Galvanize image, so they must live on the host. They are unmodified copies of the data/playbooks/ of the Galvanize version pinned in config/docker-compose.yml (currently 0.7.5), and CI checks that they match it. To upgrade Galvanize, change the image tag and copy that version's data/playbooks/*.yaml into config/galvanize/playbooks/ in the same commit.
The stack uses separate Docker networks so that player-controlled challenge containers cannot reach the platform:
| Network | Members | Purpose |
|---|---|---|
proxy |
Traefik, CTFd, instancer | Public ingress (ports 80/443), instancer outbound SSH to the Ansible target host |
internal (no internet access) |
CTFd, MariaDB, Redis, instancer | Backend traffic (database, Redis) |
challenges |
Traefik, challenge instances | Traefik routing to http challenges |
- The Galvanize API must be publicly reachable: Zync calls it directly from players' browsers (and from the admin dashboard), which is also what lets Galvanize run on a separate machine (
--instancer-url). The bundled instancer is published by Traefik on its own subdomain,https://instancer.<domain>(http://instancer.<ip>.sslip.iofor IP deployments), on port 443. No extra port (such as 8080) is opened, and its Prometheus/metricsendpoint is not routed. This subdomain needs DNS pointing to the server; the wildcard record used for challenge subdomains (*.<domain>) already covers it. - Challenge instances cannot reach CTFd, MariaDB, Redis or the instancer directly; they only see the same public endpoints as players. They can still reach Traefik, other challenge instances on the
challengesnetwork, and the internet. TCP challenges run on Docker's default bridge network. - Traefik's Docker provider uses the
challengesnetwork by default, because containers deployed by Galvanize carry notraefik.docker.networklabel. Core services routed by Traefik (CTFd) must settraefik.docker.network=<COMPOSE_PROJECT_NAME>_proxyexplicitly.
Upgrading an existing deployment: terminate running challenge instances first (they are attached to the old network), then re-run
setup.sh. This rewritesdocker-compose.yml, the Traefik configs, the Galvanize config and playbooks, and resetsZYNC_DEPLOYER_URLtohttps://instancer.<domain>(unless--instancer-urlis given). Zync caches the instancer URL in each player's browser (localStorage), so upgrade between events: players who already opened a challenge with the old:8080URL keep using it until their site data is cleared.
After running setup.sh, the following layout is created under <working-folder>/deploy/:
deploy/
├── docker-compose.yml # Active compose file (copied from repo)
├── .env # Environment variables and generated secrets
├── .secrets # Plaintext copy of generated secrets (chmod 600)
├── traefik.env # DNS provider credentials, the only env Traefik gets (chmod 600)
├── traefik-config/ # Traefik static & dynamic configs, letsencrypt storage
├── ctfd/ # CTFd image build context (Dockerfile, entrypoint)
│ ├── plugins/zync/ # CTFd instancer plugin clone
│ └── themes/ # Custom themes (--theme), built into the CTFd image
├── ansible-ssh/ # Ansible SSH key pair (local instancer only)
├── data/ # Runtime data (database, uploads, galvanize)
│ ├── CTFd/
│ ├── mysql/
│ ├── redis/
│ └── galvanize/ # Galvanize data (local instancer only)
│ ├── config.yaml # Galvanize config (from config/galvanize/config.yaml)
│ ├── playbooks/ # Ansible playbooks (from config/galvanize/playbooks/)
│ ├── challenges/ # Challenge repositories indexed by Galvanize
│ └── deployer.sqlite # Galvanize deployment database
├── backup/ # Backup and restore scripts, rclone.conf (--backup-remote)
└── cron_backup.log # Backup cron job log
Challenges are described with the same challenge.yml format used by CTFd's
official ctfcli. Existing ctfcli-compatible
challenge repositories therefore work here unchanged, and challenges authored
for this tool stay portable back to ctfcli.
What this tool does not do is wrap or depend on ctfcli. Ingestion and
synchronization are implemented natively in Bash against the CTFd REST API
(curl + jq). This keeps the tool dependency-light (no Python/pip environment
to manage) and lets a single run build the Docker images, register the
challenge in CTFd, and wire up the Galvanize/Zync
deployment together.
The following challenge.yml fields are honored: name, category,
description, value, type (ctfcli's standard/dynamic, plus the
Galvanize-specific zync extension), state, connection_info, attempts,
attribution, the dynamic-scoring initial/minimum/decay values, flags,
files, hints (including title, cost, and key-based prerequisite
gating), tags, topics, requirements (either a bare list of prerequisites
or the {prerequisites, anonymize} object form), and an extra map passed
through verbatim for CTFd plugin fields.
The first time you run an action that talks to CTFd (ingest, sync, or the
default all), the tool prompts for your CTFd instance URL and an admin
Access Token. Generate this token beforehand from the CTFd web UI, logged in
as an administrator: Settings → Access Tokens → Generate. The account must
have admin rights, since ingesting and managing challenges uses admin-only API
endpoints.
The URL and token are saved to <working-folder>/.ctfd/config and reused on
subsequent runs, so you are only prompted once.
| Action | Description |
|---|---|
all |
Build + ingest (default) |
build |
Build Docker images only |
ingest |
Ingest challenges into CTFd |
sync |
Synchronize existing challenges |
status |
Display status and statistics |
cleanup |
Stop compose stacks and clean up Docker images (respects --categories/--challenges filters) |
| Option | Description | Required |
|---|---|---|
--repo REPO |
Name of the challenge repository present in the working directory | ✅ Yes |
--action ACTION |
Action to perform (all (default), build, ingest, sync, status, cleanup) | ❌ No |
--working-folder DIR |
Working directory (default: your home directory) | ❌ No |
--config FILE |
Load configuration from a file | ❌ No |
| Option | Description |
|---|---|
--categories LIST |
List of categories to process (comma-separated) |
--challenges LIST |
List of specific challenges to process (comma-separated) |
| Option | Description |
|---|---|
--dry-run |
Simulation mode (shows actions without executing them) |
--force |
Force operations (rebuild, overwrite) |
--parallel-builds N |
Number of parallel builds (default: 4) |
--build-images MODE |
Build challenge images: auto (default), yes, no |
| Option | Description |
|---|---|
--debug |
Enable debug output |
--skip-docker-check |
Skip Docker daemon check |
--help |
Display help |
--version |
Display version information |
# Full configuration (build + ingest)
./challenges.sh --repo challenge_repo
# Build only for certain categories
./challenges.sh --action build --repo challenge_repo --categories "web,crypto"
# Synchronization with forced update
./challenges.sh --action sync --repo challenge_repo --force
# Simulation mode to see planned actions
./challenges.sh --repo challenge_repo --dry-run
# Processing specific challenges
./challenges.sh --action build --repo challenge_repo --challenges "web-challenge-1,crypto-rsa"
# Parallel build with 8 threads
./challenges.sh --action build --repo challenge_repo --parallel-builds 8
# Display status
./challenges.sh --action status --repo challenge_repo
# Clean up Docker images
./challenges.sh --action cleanup --repo challenge_repoCreate a .env file with KEY=VALUE pairs:
REPO=challenge_repo
WORKING_DIR=/opt/ctf
PARALLEL_BUILDS=8
FORCE=true
DEBUG=falseUsage:
./challenges.sh --config .env- Update system packages
- Install dependencies
- Add official Docker repository
- Install Docker CE, Docker Compose, etc.
- Enable Docker service to start on boot
- Configure user groups
With --theme, --remove-theme or --active-theme:
- Installs, updates or removes the custom themes built into the CTFd image
- Optionally sets CTFd's active theme (see Custom theme configuration)
- Verify Docker and daemon availability
- Check for required system tools (curl, jq, yq)
- Analyze the challenge repository structure
- Identify Docker and static challenges
- Only runs when the Galvanize instancer is hosted on this machine: Galvanize deploys images from its own Docker host, so images built elsewhere are never used. Detection (
--build-images auto) readsINSTANCER_MODEfrom<working-folder>/deploy/.env(written bysetup.sh:local,externalornone), falls back to a localGALVANIZE_CONFIG_PATHfor older deployments, then to a runninggalvanize-instancercontainer. When no local instancer is found,allgoes straight to ingestion andbuilddoes nothing. Override with--build-images yesor--build-images no. - Sequential or parallel image building
- Support for
--forcemode for complete rebuild - Error handling with detailed reports
- Installation via the CTFd REST API into the CTFd instance
- Challenges are installed in dependency order:
requirementsare topologically sorted so a prerequisite is always created before the challenge that needs it. Circular dependencies are detected and reported. - Atomic install with rollback: if attaching flags, files, hints, tags, topics, or requirements fails, the partially-created challenge is removed so a failed ingest leaves no half-registered challenge behind.
- Docker Compose image tag validation before ingest, and duplicate detection (existing challenges are skipped — use
syncto update them).
- Updates existing challenges in place: the challenge is PATCHed, so its CTFd ID never changes.
- Propagates edits to owned sub-resources without losing player state:
- Hints are updated in place, so players keep the hints they already unlocked (CTFd tracks unlocks by hint ID). The Nth hint in
challenge.ymlupdates the Nth existing hint: keep hint order stable and append new hints at the end. Hints removed fromchallenge.ymlare deleted, and players lose access to them. - Flags are diffed: new flags are added before removed ones are deleted, so the challenge is never left without a valid flag.
- Files are diffed by content (SHA-1) and name: unchanged files are left alone and keep their download URL; new or changed files are uploaded, stale ones deleted.
- Tags and topics, which carry no player state, are cleared and recreated.
- Hints are updated in place, so players keep the hints they already unlocked (CTFd tracks unlocks by hint ID). The Nth hint in
- Requirements are resolved in a second pass, after every challenge has been synced, so a prerequisite referenced by name resolves correctly regardless of processing order.
- Option to backup before synchronization, and
--forcemode for overwriting.
- CTFd stores requirement prerequisites as raw challenge IDs and does not cascade-clean them: deleting and recreating a challenge would give it a new ID and silently orphan every challenge that required it.
- To avoid this, sync never deletes-and-recreates a challenge (it patches in place), and the tool refuses to delete a challenge that other challenges list as a prerequisite unless explicitly forced.
- Remove Docker images associated with challenges
- Dry-run mode available
challenge_repo/
├── challenges/ # (optional, detected automatically)
│ ├── web/
│ │ ├── challenge-1/
│ │ │ ├── challenge.yml # Challenge configuration
│ │ │ ├── Dockerfile # Docker image (for type: zync)
│ │ │ ├── src/ # Source code
│ │ │ └── files/ # Challenge files
│ │ └── challenge-2/
│ ├── crypto/
│ └── pwn/
name: "MyChallenge"
author: Challenge_Author
category: AI
description: |-
## Description (French)
Petite description en français
## Description (English)
Short description in English
flags:
- flag{flag_to_find}
tags:
- AI
- A:Challenge_Author
# Prerequisites: a bare list of challenge names/IDs...
requirements:
- "Rules"
# ...or the object form, to show locked challenges as "???" instead of hiding them:
# requirements:
# prerequisites:
# - "Rules"
# anonymize: true
# If files needed
files:
- "files/hello_world.txt"
# If hints needed, choose the cost
hints:
- Interesting hint
- {
cost: 10,
content: "Interesting payed hint"
}
# Gated hint: stays hidden until the player unlocks the hints it requires.
# Give the prerequisite hints a `key` and reference those keys in `requirements`.
- key: step1
cost: 5
content: "First step"
- cost: 20
content: "Second step (only revealed after step1 is unlocked)"
requirements:
- step1
value: 5
type: zync # or type: dynamic / static
# Following options are for type: zync only. See https://github.com/28Pollux28/galvanize/tree/master/data/challenges/example for up-to-date examples (http, tcp, custom_compose)
playbook_name: http # 'http' (single container behind Traefik, HTTPS subdomain), 'tcp' (published ports), or 'custom_compose' (see below)
deploy_parameters:
image: nginx:alpine # Docker image to deploy ('http' and 'tcp' playbooks)
unique: false # Set to true if there needs to be a unique instance for all players
http_port: 80 # Container port Traefik forwards to (Only for 'http' playbooks, default: 80)
published_ports: # Ports to expose from the container (Only for 'tcp' playbooks)
- 1337 # Random host port per team; "22/ssh" adds a URL scheme hint, "8080:80/http" is a fixed mapping
env: # Environment variables passed to the container
FLAG: "flag{flag_to_find_in_env}"
TZ: Europe/Zurich
resource_limits: # Override default resource limits (optional)
cpus: "1"
memory: "512M"
pids_limit: 256For challenges that need several containers, put a standard Compose file (compose.yaml, compose.yml, docker-compose.yaml or docker-compose.yml) next to challenge.yml. Galvanize detects it and defaults playbook_name to custom_compose. Declare which services players reach with an expose block instead of hand-writing Traefik labels, networks or host ports:
type: zync
deploy_parameters:
unique: false
expose:
- service: web # routed through Traefik -> https://<instance>.<domain>/
port: 80
type: http
- service: ssh # published on a random host port per team
port: 22
type: tcp
scheme: ssh # optional, only changes the displayed connection URLNotes:
challenges.shbuilds every service that has abuild:key and, if it has noimage:, tags it<challenge>_<service>:latestin the compose file so Galvanize can deploy the locally built image. With a remote instancer nothing is built: give eachbuild:service a taggedimage:that the instancer's Docker host can pull (ingestion rejects built services without one).- Do not set
container_nameor publishports:yourself: Galvanize names each project per team and wires the networking fromexpose. build:contexts and bind mounts are resolved on the deploy host, so prefer pre-built images.
The setup script automatically generates:
- CTFd secret key (32 characters)
- Database password (16 characters)
- Database root password (16 characters)
- Galvanize JWT secret (48 characters)
- Galvanize metrics password (32 characters, with a local instancer)
All secrets are written to <deploy-dir>/.secrets (chmod 600) and to .env.
DNS provider credentials (for wildcard TLS certificates) are written to <deploy-dir>/traefik.env (chmod 600) instead. It is the only env file passed to the Traefik container, so Traefik never sees the database passwords, CTFd's SECRET_KEY or the Zync JWT secret. Deployments made before this change kept their DNS credentials in .env: re-running setup.sh copies them to traefik.env, after which they can be removed from .env.
How setup writes the configuration. deploy/.env is the source of the deployment settings: setup works out every value first (from the options, the existing .env and .secrets), then writes them to .env in a single pass. Keys it does not manage, such as ones you add by hand, are kept. Docker Compose reads everything else from .env itself, so docker-compose.yml is never edited. The two generated YAML files, the Galvanize config and Traefik's static config, are each filled in with a single yq call from the same values. In config/traefik/traefik.yml, setup only replaces the __BASE_DOMAIN__, __ACME_EMAIL__ and __DNS_PROVIDER__ placeholders, so other values you change in that template (for example caServer, to use Let's Encrypt's staging server) are kept. COMPOSE_PROJECT_NAME is taken from the environment, else from .env, else ctfd_infra.
The Traefik dashboard (HTTP-only deployments; it is disabled with HTTPS) has no authentication, so its port (9090) is only published on the server's loopback interface (TRAEFIK_DASHBOARD_BIND in .env). Reach it through an SSH tunnel: ssh -L 9090:127.0.0.1:9090 <server>, then open http://localhost:9090/dashboard/.
Re-running setup is safe: if secrets already exist in
.env, they are preserved. Only missing secrets are generated, so runningsetup.shagain will not break existing containers.
.github/workflows/setup-e2e.yml runs on every push to a branch other than main (documentation-only changes excepted), and can be started manually from the Actions tab. Branches are merged into main once their run passes, so main is not tested again. It runs setup.sh for real on fresh Ubuntu 24.04 runners, in five jobs:
- no HTTPS:
./setup.sh --domain <runner IP> --yes, with the bundled Galvanize instancer. This job also checks that a loopback--domainis rejected, and finally re-runs setup with--instancer-urlto check that switching to an external instancer stops and removes the local one. - HTTPS:
./setup.sh --domain <runner-ip>.sslip.io --acme-email … --dns-provider cloudflare --yes, with the bundled instancer, against Pebble, Let's Encrypt's test ACME server, running on the runner. sslip.io resolves the domain and all its subdomains to the runner. For this job only, the CI points the checkout's Traefik template at Pebble and the DNS-01 challenge at lego'sexecprovider running a no-op (Pebble accepts every challenge), and pre-seedstraefik.envwith a placeholder Cloudflare token that--yesmust keep. A real DNS provider API and the real Let's Encrypt servers are not exercised. --no-instancerand--instancer-url(no HTTPS): CTFd without a local instancer. The checks make sure no instancer container, Galvanize data, Ansible user or SSH key is created, that nothing is routed atinstancer.<domain>, and that.envhas the rightINSTANCER_MODE,COMPOSE_PROFILESandZYNC_DEPLOYER_URL.- Debian 13 (no HTTPS, bundled instancer): GitHub has no Debian runners, so this job boots a fresh Debian 13 virtual machine on the runner with Incus (KVM), with only a sudo user and sshd, and runs
setup.shand the checks below inside it. Unlike on the Ubuntu runners, which ship with Docker, setup installs Docker from Docker's Debian repository here.
Each job then:
- checks the stack (
.github/scripts/setup-e2e/check-stack.sh): container health, Traefik routing to CTFd and the instancer, the generated.env/traefik.env/Galvanize config, data ownership, Ansible SSH access, the backup cron job and a backup run. In HTTPS mode it also checks that a wildcard certificate for the domain is issued and verifies against Pebble's root, that HTTP redirects to HTTPS, the HSTS header, and that the Traefik dashboard port is closed; - with the bundled instancer, deploys and terminates a challenge instance through the Galvanize API with a Zync-style JWT (
deploy-challenge.sh), reaching it over HTTPS through Traefik (with certificate verification in HTTPS mode); - re-runs
setup.sh --yes, checks that the secrets are unchanged, then repeats the checks (and the deployment, with the recreated SSH key).
On failure, container logs and redacted configs are uploaded as the setup-e2e-diagnostics-<job> artifact.
Testing an unreleased Galvanize. The Galvanize end-to-end workflow (Actions tab → Galvanize end-to-end → Run workflow) tests a Galvanize version that is not published yet, such as a fork branch with a fix meant for upstream: set galvanize_repository (e.g. CorentinFelten/galvanize) and galvanize_ref (a branch, tag or commit). It builds that version's image and runs one complete Ubuntu job with it, deploying it with that version's own playbooks instead of the vendored ones, so the deployments exercise the code under test: the --no-https job by default (challenge deployments, re-runs, backup restore, switch to an external instancer), or the HTTPS job with tls=https. With multi_endpoint (on by default), it also deploys a challenge with a web and an SSH-like service and checks that both endpoints are reported and answer; untick it for Galvanize v0.7.4 and earlier. With without_redis (on by default), the job also restarts Galvanize without Redis for a while: it deploys a TCP challenge without traefik_network, checks that its port is within the randomized range, and that the expiry scheduler terminates it, then restores the original configuration; untick it to test a Galvanize version older than these fixes (v0.7.2 and earlier). It skips the other scenarios and the Debian VM, which do not test Galvanize, and runs independently of the push runs. setup.sh is unchanged: only the checkout's compose template and playbooks are pointed at it. From the command line: gh workflow run galvanize-e2e.yml --ref main -f galvanize_repository=CorentinFelten/galvanize -f galvanize_ref=<galvanize-branch>.
This project is licensed under the MIT License - see the LICENSE file for details.
These scripts were initially developed for the PolyCyber team to automate the installation and management of CTFd servers. They were built to work specifically with the Galvanize instancer and Zync plugin.