Skip to content

Developing locally ​

You don't need a cluster to work on a challenge. The ctfgarden CLI uses the platform's own code to render, parse and check challenges, and runs them with Docker Compose.

sh
cargo install ctfgarden-cli

This installs the ctfgarden command. To run challenges, you also need Docker with the Compose plugin (or another compose tool).

Run the commands in a challenge directory, pass it as an argument (ctfgarden lint challs/my-challenge), or pass the repository root and the challenge ID (ctfgarden lint --id my-challenge).

Linting ​

sh
ctfgarden lint
Linting challenge `my-challenge` in /repo/challs/my-challenge (actor=user-local, is_export=false)
warning: [services.web.healthcheck] not supported by the platform, ignored (not converted to Kubernetes probes)
error: [services.web.imgae] unknown field: the platform can't load this compose file (typo?)
1 error(s), 1 warning(s)

Lint does what the platform does when it deploys the challenge, and reports everything that would go wrong:

  • Parsing: all templates render, the compose file is valid and loads, x-ctf-metadata, x-ctf-vms and x-ctf-network-policy are valid, and the flag validation function runs. Every service is converted into the Kubernetes objects the platform would create (without a cluster), so anything that fails to deploy shows up.
  • Unsupported fields: every compose field the platform ignores is a warning, every field that stops the deployment an error (see Compose support). Unknown fields in x-ctf-metadata and the other extensions are warnings, they're usually typos.
  • Consistency: categories and difficulties exist in event.yml, attachments exist, SSH ports have credentials.
  • Licensing: if the repository uses REUSE (it has a LICENSES directory or a REUSE.toml), every file needs copyright and license information, like reuse lint checks. --reuse checks it anyway, --no-reuse skips it.
OptionDescription
--flag <FLAG>Also check whether a flag is accepted when --actor submits it
--actor <ACTOR>Render for this actor (team-<slug> or user-<username>, default user-local)
--exportRender as if for a handout
--strictFail on warnings too
--format jsonMachine-readable output

The exit code is 1 if there are errors (or warnings with --strict), so you can run it in CI:

sh
for chall in challs/*/; do ctfgarden lint --strict "$chall" || exit 1; done

From Node.js ​

The same checks are available as the ctfgarden-lint npm package, for editor integrations or CI pipelines that already use Node.js:

sh
npx ctfgarden-lint challs/*/
js
const { lint } = require("ctfgarden-lint");

const { errors, findings } = await lint("challs/my-challenge", { flag: "ctf{test}" });

Running the challenge ​

sh
ctfgarden compose up --build

ctfgarden compose passes everything after it to docker compose, so any compose command works:

sh
ctfgarden compose up -d
ctfgarden compose logs -f web
ctfgarden compose exec web sh
ctfgarden compose down -v

Before running compose, it renders the challenge into a work directory (in ~/.cache/ctfgarden):

  • Templates are rendered for --actor (default user-local).
  • Directories and files without templates are used straight from your challenge directory: edit your code, and a bind-mounted directory sees it right away, ctfgarden compose up --build builds from your files.
  • Templated files come from the work directory. While the compose command runs, changed templates are re-rendered within a second, and changed files copied. The files are rewritten in place, so bind mounts of single files see the changes too.
  • If you change the compose file itself, run ctfgarden compose up again to apply it.

Commands that start containers (up, run, build, ...) lint the challenge first and print problems, but don't stop. logs, down and other commands reuse the actor of the running containers.

The compose project is called ctfgarden-<challenge id>. Set CTFGARDEN_COMPOSE (or --compose-command) to use another tool, like podman compose or docker-compose. Compose options that come before the command need a --: ctfgarden compose -- --profile debug up.

Differences to the platform

Locally, Docker Compose runs the challenge, so it behaves like Compose, not like the platform:

  • VMs don't start, network policies aren't enforced, and there's no TLS, SSH gateway or per-instance domain. Ports are published the Compose way (ctfgarden compose ps shows them).
  • privileged and cap_add services run as normal containers, not in a VM.
  • Fields the platform ignores, like depends_on and healthcheck, work locally.

ctfgarden lint tells you about everything that won't work on the platform.

Rendering templates ​

sh
ctfgarden render -o /tmp/rendered --actor team-red

Renders every template into the output directory (which must be empty, or use --force), and copies everything else. Add --export to render like for a handout, and --handout <FILE> to also build the handout archive exactly like the platform does.

Flags and secrets ​

Per-team flags and canaries are derived from HMAC_SECRET_KEY. If it isn't set, the CLI uses an insecure development key (like the platform without it), so local values differ from the platform's. Never put the platform's key on machines that don't need it.

To get a team's flag, render the challenge for them (ctfgarden render --actor team-red -o /tmp/out) and look at the output of flag(). Check flags with ctfgarden lint --flag:

ResultMeaning
acceptedValid for everyone, or it's the submitting actor's flag
rejected (another actor's flag)The platform reports this as flag sharing. It may also be the fake flag from a handout
rejected: the flag is wrongThe flag is wrong

Previewing certificates ​

Render an attendance certificate with the repository's certificate configuration:

sh
ctfgarden render --certificate certificate.pdf path/to/repo --name "Alice Example" --team "The Gardeners" --solves 7

--username, --team-slug and --bracket set the other values the template gets, --cheater renders the cheater certificate with sample evidence. If a player wouldn't get the certificate yet (min_solves, available_from), the CLI says so, but renders it anyway.

Imprint