Skip to content

Instance groups, configurable compose prefix, deploy fixes, and worker observability - #7

Merged
CorentinFelten merged 4 commits into
28Pollux28:masterfrom
SenequeZ:unitedctf-improvements
Nov 12, 2026
Merged

CorentinFelten merged 4 commits into
28Pollux28:masterfrom
SenequeZ:unitedctf-improvements

Conversation

@SenequeZ

@SenequeZ SenequeZ commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR collects the changes we made while running Galvanize for UnitedCTF. It contains bug fixes found during the event, new instancer features, and an optional monitoring stack.

It is rebased on v0.7.4. Where upstream already fixed the same problem, upstream's version was kept: the pids limit, the sha1 project suffix, category-aware project names, and the index skipping bad files. Our features sit on top of that.

Companion Zync PR: 28Pollux28/zync#1. It covers individual mode (team_id) and rendering multi-line connection info, which show_tcp_ports below relies on.

🐛 Bug fixes

# Symptom Cause Fix
1 Clicking Spawn in CTFd returns 400 "Invalid challenge" or "not found", even though the challenge exists The category was compared case-sensitively. A CTFd category Web did not match web in challenge.yml. ChallengeIndex.Get now ignores case for the category. The deployment queries in models/deployment.go (GetDeployment and GetUniqueDeployment) compare LOWER(category).
2 Extend and terminate don't find the deployment even though status shows it running ExtendInstance and TerminateInstance looked up the DB row with the raw JWT category and challenge_name, so they hit #1 and did not use the deployment key. TerminateInstance also only looked up the challenge when a job queue was configured. Both handlers now find the challenge first (and return 400 if it is invalid), then look up the row with chall.Category and chall.InstanceKey().
3 An HTTP instance comes up, but the app can't reach its own DB or other services attachNetwork replaced a missing networks: key with only the Traefik network. That drops the service from compose's implicit default network, which its sibling services are on. When a service has no networks: key, it now gets [default, <traefik>]. The test checks for this.
4 Some challenges in a directory are never indexed During the directory walk, filepath.SkipDir was returned on a file: after a parse error, a duplicate, or a challenge that isn't zync. For a file, SkipDir skips the rest of its parent directory, so any challenge files after it were silently ignored. A file now returns nil, so the walk continues. Only directories return SkipDir. Bad files are still reported in Skipped().
5 Deleting a tcp instance leaves containers running or fails on hung containers, and http delete fails if the containers already stopped tcp.yaml had no kill step before state: absent. In http.yaml, docker compose kill exits with an error when nothing is running. Added the kill step to tcp.yaml. Both playbooks now set failed_when: false on it.
6 The compose definition built by the playbook is ignored when a challenge also sets compose_definition The playbook's set_fact: compose_definition has the same name as the compose_definition deploy parameter. Galvanize passes deploy parameters as extra-vars, and Ansible extra-vars win over set_fact. The playbook fact is renamed to _compose_def in http.yaml and tcp.yaml.
7 Ansible fails with couldn't resolve module/action 'community.docker.docker_compose_v2' in some image builds The collection was not installed explicitly in the instancer image. The Dockerfile now runs ansible-galaxy collection install community.docker.
8 An admin-deployed unique challenge shows as not deployed to players (only with instance groups, below) The admin endpoints stored unique deployments under chall.Name, while player status lookups use InstanceKey(). DeployAdminInstance, deploy-all and TerminateAdminInstance now use InstanceKey().

✨ Features

  • instancer.compose_project_prefix: the readable prefix of instance project names and subdomains, default ctf-event (no event-specific default in the code).

    • Team instances: <prefix>-<cat>-<name>-<team>-<hash>. Unique instances: <prefix>-global-<cat>-<name>-<hash>.
    • The prefix is not part of the hashed identity. It is useful when several events share a worker, or to brand the subdomains.
    • Upgrade: the v0.7.2–v0.7.4 names (polypwn-…, global-…) are added to the upgrade cleanup next to the v0.7.1 ones. Galvanize passes them as legacy_compose_projects, and the delete task of each playbook loops over them, so instances running before the upgrade can still be terminated.
  • Numbered challenge files: challenge-*.yml/challenge-*.yaml are indexed as well as challenge.yml, so one directory can hold a series of challenges (challenge-1.yml, challenge-2.yml, …).

  • deploy_parameters.instance_group: challenge entries with the same group share one deployment per team. This is for multi-part challenges that all run against the same service. All of these key on the new Challenge.InstanceKey(), which returns the group if set and the challenge name otherwise:

    • deployments, locks and jobs
    • conflict metrics
    • compose project names
    • admin endpoints

    ChallengeIndex.Get also resolves a challenge by its group name, so worker jobs can find it.

  • deploy_parameters.show_tcp_ports: by default, connection info stops at the first Traefik HTTP URL and hides every TCP port the instance publishes (SSH, SMB, …). With show_tcp_ports: true, it lists the HTTP URL first, then each published port, one per line. Ports are sorted by target port, duplicates are removed, and IPv6 binds are skipped. Without the flag nothing changes.

  • port shorthand: deploy_parameters.port fills in published_ports (and http_port for the http playbook) when those aren't set.

Monitoring (optional)

Two parts. The control plane runs Prometheus, Grafana and Loki. The worker, which is the Ansible target running the challenge containers, runs the edge stack.

Control plane

  • prometheus.yml: scrape jobs for the worker's docker-stats-exporter on :8088 (keeps docker_container_* only) and the worker's Traefik metrics on :8082. The targets are placeholders (<worker-ip>).
  • Loki (monitoring/loki.yml) and its Grafana datasource.
  • Grafana dashboards: worker-traffic.json and ai-usage.json (requests from AI/LLM user agents, with markdown links to the instances).
  • These are not wired into docker-compose.monitoring.yml yet.

Worker (monitoring/worker/docker-compose.yml, deployed separately on the worker host)

  • Traefik:
    • routes *.challs.<domain> to instances
    • gets a wildcard certificate through a Cloudflare DNS-01 challenge: dynamic/tls.yml, plus cf.env, made from cf.env.example and gitignored
    • exposes Prometheus metrics on :8082
    • writes a JSON access log that keeps only the User-Agent and Referer headers
  • monitoring/docker-stats-exporter: a small exporter that reads the Docker socket and reports CPU, memory and network per container, using cAdvisor-style metric names. It is much lighter than cAdvisor.
  • monitoring/tcp-access-logger: a raw-socket sniffer that logs connections and the first bytes of data sent to published challenge ports, as JSON lines.
  • Promtail (monitoring/promtail.yml): ships both access logs to the control-plane Loki. The push URL is a placeholder (<control-plane-ip>).
  • Only the control plane should be able to reach :8082 and :8088.

Notes for the reviewer

  • Some monitoring files are still specific to UnitedCTF: the unitedctf- container filter in the TCP logger and the dashboard titles and queries. Happy to make them generic or split them into a separate PR.
  • Changing compose_project_prefix on a running event changes the names of new instances. Instances that already exist aren't renamed.
  • Following review, school-scoreboard/ and theme/ were removed from this PR.

Test plan

  • go build ./..., go vet ./... and go test ./... pass in galvanize-instancer/ (rebased on v0.7.4)
  • New tests:
    • prefix naming (default ctf-event, custom prefix, and the hash staying the same with any prefix)
    • v0.7.4 names included in the upgrade cleanup
    • numbered challenge files
    • instance groups
    • case-insensitive Get
    • the default network being kept
    • show_tcp_ports: hidden by default, HTTP URL then ports, ports only
  • Deploy and terminate an http and a tcp challenge, with and without compose_project_prefix
  • Two challenge-N.yml entries sharing an instance_group resolve to one deployment

@SenequeZ
SenequeZ force-pushed the unitedctf-improvements branch from 2ec8094 to a88a165 Compare November 9, 2026 18:57
@SenequeZ SenequeZ changed the title Instance groups, configurable compose prefix, and worker observability Instance groups, configurable compose prefix, deploy fixes, and worker observability Nov 9, 2026
…r observability

Instancer:
- Add optional instancer.compose_project_prefix. Unset keeps upstream
  names; set, it prefixes team and unique instance projects.
- Load numbered challenge definition files (challenge-*.yml) and keep
  walking a directory after a match, parse error, duplicate or non-zync
  file instead of skipping its remaining siblings.
- Add deploy_parameters.instance_group so several challenge entries
  share one deployment; deployments, locks and jobs use InstanceKey(),
  including the admin unique-challenge endpoints.
- Case-insensitive category lookups in the index and deployment queries.
- Infer published_ports / http_port from deploy_parameters.port.
- Keep services on the compose default network when attaching Traefik.
- Extend/Terminate resolve the challenge before the deployment lookup.

Playbooks / image:
- Rename the compose_definition fact (it collided with the extra-var),
  tolerate kill failures on delete, add kill step to tcp delete, and
  install community.docker in the instancer image.

Monitoring / extras:
- Worker cAdvisor + Traefik scrape jobs, Loki, Promtail, TCP access
  logger, AI-usage and worker-traffic Grafana dashboards.
- School scoreboard service and CTFd theme header/footer snippets.
@SenequeZ
SenequeZ force-pushed the unitedctf-improvements branch from a88a165 to 386abc7 Compare November 9, 2026 19:35
Connection info normally stops at the first Traefik HTTP URL, hiding
every published TCP port of the instance. deploy_parameters.show_tcp_ports
lists the HTTP URL first, then each published port (sorted, deduplicated,
IPv6 binds skipped), one per line.

Also update the AI-usage Grafana dashboard to the version used live
(markdown links to instances).
- monitoring/worker: the worker-side compose (Traefik with JSON access
  log keeping User-Agent/Referer, Prometheus metrics on :8082, DNS-01
  wildcard cert via Cloudflare; docker-stats-exporter; tcp-access-logger;
  Promtail), dynamic/tls.yml for the wildcard cert, cf.env.example.
- monitoring/docker-stats-exporter: small exporter reading the Docker
  socket, exposing per-container CPU/memory/network with cAdvisor-style
  names. This is what the worker-cadvisor scrape job targets on :8088.

// DefaultComposeProjectPrefix is the readable prefix of team instance project
// names when instancer.compose_project_prefix is not set.
const DefaultComposeProjectPrefix = "polypwn"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible de le sortir directement dans une string paramètre de Galvanize, et default la valeur à "ctf-event" ou quelque chose comme ça ? De cette manière l'instancer n'est pas trop lié à Polycyber dans le code, ça sera plus générique

@@ -0,0 +1,3 @@
# Cloudflare API token with Zone:DNS:Edit, used by Traefik for the
# DNS-01 challenge of the *.challs.<domain> wildcard certificate.
CF_DNS_API_TOKEN=

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pareil ici, si le token peut être un paramètre de config de Galvanize ça serait l'idéal

Comment thread school-scoreboard/templates/index.html Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour ce fichier, soit le rendre plus générique (classement par catégorie custom), soit le supprimer. Pas sur qu'il soit pertinent dans le repo en l'état actuel

Comment thread school-scoreboard/app.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Même commentaire que le précédent, à rendre générique (avec paramètres qui remontent dans la config Galvanize) ou sortir du repo

Comment thread theme/selectstar-theme-footer.html Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas pertinent d'ajouter des thèmes dans le repo

Comment thread theme/selectstar-theme-header.html Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas pertinent d'ajouter des thèmes dans le repo

Comment thread config.example.yaml Outdated
ansible_dir: "./data/playbooks" # Directory for Ansible playbooks
challenge_dir: "./data/challenges" # Directory for challenge files
instancer_host: "challs.example.com" # Public hostname of the deployer (will be used in domain names)
# compose_project_prefix: "myctf" # Optional readable prefix of instance names/subdomains (default: "polypwn-" for team instances, none for unique ones)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas de default qui revienne à PolyCyber, comme mentionné plus haut

@CorentinFelten CorentinFelten left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quelques petites modifs nécessaires, sinon c'est super !

… theme

- compose_project_prefix defaults to "ctf-event" and applies to both team
  and unique instances (<prefix>-global-...). No PolyCyber-specific default.
- Instances named by v0.7.2-v0.7.4 (polypwn-/global- names) are added to the
  upgrade cleanup next to the v0.7.1 names: playbooks now loop over
  legacy_compose_projects.
- Remove school-scoreboard/ and theme/, which are event-specific.
@CorentinFelten
CorentinFelten merged commit 8c0df0e into 28Pollux28:master Nov 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants