Skip to content

Installing the platform ​

CTFGarden consists of three components:

  • The API server (ctfgarden-api), which serves the GraphQL API on port 3000 and stores users, teams and solves in PostgreSQL.
  • The manager (ctfgarden-manager), which reads the CTF repository, deploys challenge instances to Kubernetes and builds challenge images. It's only reachable by the API server through gRPC on port 50051.
  • The SSH gateway (ssh-gateway), which forwards SSH connections to challenges exposed with app_protocol: ssh. It listens on port 2222.
  • Optionally, the traffic agent (ctfgarden-traffic-agent), a DaemonSet that captures the traffic of challenge instances for cheat detection. See traffic agent.

All of them are built from the Dockerfile in the repository (targets api, manager, ssh-gateway, traffic-agent and data-import, the job that loads challenge data into instances). The frontend has its own image.

Requirements ​

  • A Kubernetes cluster using Traefik as ingress controller and Cilium as network plugin, which network policies depend on.
  • KubeVirt if you want to use VMs.
  • Kata Containers with a runtime class named kata if you want to allow privileged or cap_add on services. These containers are run in a lightweight VM.
  • Kubernetes 1.30 or newer.
  • A PostgreSQL 18 database (the migrations use uuidv7()). Migrations are run automatically when the API server starts.
  • A container registry that challenge images are pushed to when they are built through the platform.
  • A wildcard DNS record pointing *.<your domain> to your ingress, because every exposed challenge service gets its own hostname.

The manager needs a service account that's allowed to manage namespaces and the resources inside them, and runs the image builds as docker buildx pods in its own namespace (BUILDX_NAMESPACE).

Installing with Helm ​

The recommended way to install CTFGarden is the Helm chart in charts/ctfgarden. It deploys all components with least-privilege RBAC, generates the secrets the platform needs, and can create the database with CloudNativePG and the certificates with cert-manager:

sh
helm install ctf ./charts/ctfgarden --namespace ctf --create-namespace \
  --set domain=ctf.example.com \
  --set git.url=https://gitlab.com/example/my-ctf.git \
  --set registry.server=registry.example.com \
  --set registry.username=ci --set registry.password=... \
  --set postgresql.cnpg.enabled=true \
  --set tls.certManager.enabled=true --set tls.certManager.issuerRef.name=letsencrypt-dns

See the chart's README.md for all values. The chart generates the HMAC key, the internal API token and the session signing key on the first install and keeps them in the secret <release>-ctfgarden-generated, also when the release is uninstalled. Back up this secret: a new HMAC key changes all per-team flags.

The rest of this page describes the components and their environment variables, for deployments without the chart.

First steps ​

After installing, sync the repository. Then register an account: the first user that registers automatically becomes an admin.

Configuration ​

All components are configured using environment variables.

API server ​

VariableDescription
DATABASE_URLRequired. PostgreSQL connection string, for example postgres://user:password@host/db
MANAGER_ENDPOINTRequired. URL of the manager's gRPC endpoint, for example http://manager.ctf-platform.svc.cluster.local:50051
SIGNING_KEYThe key session tokens are signed with: a 32-byte seed, base64-encoded (for example openssl rand -base64 32). Takes precedence over SIGNING_KEY_FILE, and is needed for more than one replica
SIGNING_KEY_FILEFile to store the key used to sign session tokens in, if SIGNING_KEY isn't set. Generated on the first start if it doesn't exist. Defaults to key.json. Keep it on persistent storage, otherwise all sessions are invalidated on every restart
EXPOSED_DOMAINDomain the platform is served on, used for links in emails
SMTP_SERVER, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROMSMTP server used to send verification emails. If these aren't set, new users are activated without email verification
CAP_INSTANCE_URL, CAP_SITE_KEY, CAP_SECRET_KEYOptional, enables Cap as a CAPTCHA for registration
INTERNAL_API_TOKENShared secret for the internal endpoints under /internal/, which the traffic agent and the frontend server use. Clients send it as Authorization: Bearer <token>. If it's not set, the internal endpoints are disabled
AI_IP_RANGES_FILEOptional file with additional AI provider IP ranges
NO_OPENAI_DOWNLOADSet to true (or 1, yes, on) to not download OpenAI's published IP ranges

The API server determines the client IP from the connection, or, if the connection comes from a private or loopback address (a proxy), from the rightmost public address in X-Forwarded-For. Entries further left are set by the client and are ignored, so make sure your ingress appends the client's address.

The Discord integration and writeup uploads have their own configuration.

Manager ​

VariableDescription
GIT_URL, GIT_BRANCHRequired. The CTF repository, see syncing the repo
REPO_DIRWhere the local copy of the repository is stored. Defaults to /data/repo
EXPOSED_DOMAINDomain that challenge services are exposed on. Services are available at <service>-<port>-<challenge>-<instance>.<EXPOSED_DOMAIN>
SSH_EXPOSED_DOMAINHostname of the SSH gateway shown to players. Defaults to EXPOSED_DOMAIN
HMAC_SECRET_KEYRequired for events. Secret used to generate actor flags, canary tokens and the per-instance SSH passwords. If it's not set, actor flags and canaries use a publicly known development key (anyone can compute every team's flag), and SSH passwords are derived from the challenge's flag. Don't change it during an event, because all actor flags and canaries change with it
DOCKER_REGISTRY, DOCKER_USERNAME, DOCKER_PASSWORDRequired. Registry and credentials that built challenge images are pushed to
DOCKER_NAMESPACERequired. Namespace in the registry that images are pushed to
DOCKER_CONFIG_REGISTRYRegistry hostname for the credentials, if it differs from DOCKER_REGISTRY
DEFAULT_RUNTIME_CLASSKubernetes runtime class used for challenge containers that don't set runtime
KATA_RUNTIME_CLASSRuntime class for privileged services and services with cap_add. Defaults to kata
DATA_IMPORT_IMAGEImage of the job that loads a challenge's data/ directory into instances (Dockerfile target data-import)
BUILDX_NAMESPACENamespace the docker buildx builder pods run in. Defaults to POD_NAMESPACE, then ctf-platform
BUILDX_REPLICASNumber of buildkit pods. Defaults to 4

Frontend ​

The frontend server fetches the list of decoy challenges from the API's internal endpoint, so set INTERNAL_API_TOKEN on the frontend server to the same value as on the API server.

Traffic agent ​

See traffic agent.

SSH gateway ​

VariableDescription
SSH_GATEWAY_INSTALL_CRDSet to false if the sshgateways.plfanzen.garden CRD is installed separately (the Helm chart does this). Otherwise the gateway installs it on startup, which needs permissions for CRDs
PRIVATE_KEY_FILESSH host key. Generated if it doesn't exist (readable only by the gateway). Defaults to /data/ssh_host_key
API_ENDPOINTURL of the API. Together with INTERNAL_API_TOKEN, logins are reported to the API for cheat detection: the client's IP address and SSH client version, for the team of the instance. Without them, nothing is reported
INTERNAL_API_TOKENSame value as for the API
AI_IP_RANGES_FILE, NO_OPENAI_DOWNLOADAI provider IP ranges for the traffic_ai_provider_ip check, like for the traffic agent
MAX_CONNECTIONSMaximum concurrent connections. Defaults to 2000
SSH_VERIFY_KEYSAsk clients to sign with the SSH keys they offer, to detect shared keys. Defaults to true. With false, offered keys are only recorded
MAX_CONNECTIONS_PER_IPMaximum concurrent connections from one IP address. Defaults to 50. A team behind one NAT shares it

The gateway needs permissions to read SSHGateway resources, services, pods (list, for headless services) and namespaces (get, for the team and challenge of an instance). The Helm chart sets them up.

Every client gets one SSH connection to the instance, and all its channels (shells, commands, sftp, ssh -L port forwards) are forwarded over it. Terminal size changes, EOF, exit codes and signals are forwarded. Remote port forwarding (ssh -R) is forwarded to the instance's SSH server, which listens, and the connections it accepts are sent back to the client (at most 16 forwardings per connection). What players paste into interactive sessions is logged. When an instance is stopped, its credentials stop working within 15 seconds. The backend's host key isn't checked: challenge containers generate their keys when they start, and the connection stays inside the cluster.

Imprint