Repository navigation
Instance groups, configurable compose prefix, deploy fixes, and worker observability - #7
Conversation
2ec8094 to
a88a165
Compare
…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.
a88a165 to
386abc7
Compare
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" |
There was a problem hiding this comment.
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= | |||
There was a problem hiding this comment.
Pareil ici, si le token peut être un paramètre de config de Galvanize ça serait l'idéal
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Pas pertinent d'ajouter des thèmes dans le repo
There was a problem hiding this comment.
Pas pertinent d'ajouter des thèmes dans le repo
| 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) |
There was a problem hiding this comment.
Pas de default qui revienne à PolyCyber, comme mentionné plus haut
CorentinFelten
left a comment
There was a problem hiding this comment.
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.
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
pidslimit, 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, whichshow_tcp_portsbelow relies on.🐛 Bug fixes
Webdid not matchwebinchallenge.yml.ChallengeIndex.Getnow ignores case for the category. The deployment queries inmodels/deployment.go(GetDeploymentandGetUniqueDeployment) compareLOWER(category).ExtendInstanceandTerminateInstancelooked up the DB row with the raw JWTcategoryandchallenge_name, so they hit #1 and did not use the deployment key.TerminateInstancealso only looked up the challenge when a job queue was configured.chall.Categoryandchall.InstanceKey().attachNetworkreplaced a missingnetworks:key with only the Traefik network. That drops the service from compose's implicitdefaultnetwork, which its sibling services are on.networks:key, it now gets[default, <traefik>]. The test checks for this.filepath.SkipDirwas returned on a file: after a parse error, a duplicate, or a challenge that isn'tzync. For a file,SkipDirskips the rest of its parent directory, so any challenge files after it were silently ignored.nil, so the walk continues. Only directories returnSkipDir. Bad files are still reported inSkipped().tcpinstance leaves containers running or fails on hung containers, andhttpdelete fails if the containers already stoppedtcp.yamlhad no kill step beforestate: absent. Inhttp.yaml,docker compose killexits with an error when nothing is running.tcp.yaml. Both playbooks now setfailed_when: falseon it.compose_definitionset_fact: compose_definitionhas the same name as thecompose_definitiondeploy parameter. Galvanize passes deploy parameters as extra-vars, and Ansible extra-vars win overset_fact._compose_definhttp.yamlandtcp.yaml.couldn't resolve module/action 'community.docker.docker_compose_v2'in some image buildsansible-galaxy collection install community.docker.chall.Name, while player status lookups useInstanceKey().DeployAdminInstance, deploy-all andTerminateAdminInstancenow useInstanceKey().✨ Features
instancer.compose_project_prefix: the readable prefix of instance project names and subdomains, defaultctf-event(no event-specific default in the code).<prefix>-<cat>-<name>-<team>-<hash>. Unique instances:<prefix>-global-<cat>-<name>-<hash>.polypwn-…,global-…) are added to the upgrade cleanup next to the v0.7.1 ones. Galvanize passes them aslegacy_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-*.yamlare indexed as well aschallenge.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 newChallenge.InstanceKey(), which returns the group if set and the challenge name otherwise:ChallengeIndex.Getalso 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, …). Withshow_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.portshorthand:deploy_parameters.portfills inpublished_ports(andhttp_portfor thehttpplaybook) 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'sdocker-stats-exporteron:8088(keepsdocker_container_*only) and the worker's Traefik metrics on:8082. The targets are placeholders (<worker-ip>).monitoring/loki.yml) and its Grafana datasource.worker-traffic.jsonandai-usage.json(requests from AI/LLM user agents, with markdown links to the instances).docker-compose.monitoring.ymlyet.Worker (
monitoring/worker/docker-compose.yml, deployed separately on the worker host)*.challs.<domain>to instancesdynamic/tls.yml, pluscf.env, made fromcf.env.exampleand gitignored:8082User-AgentandRefererheadersmonitoring/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.monitoring/promtail.yml): ships both access logs to the control-plane Loki. The push URL is a placeholder (<control-plane-ip>).:8082and:8088.Notes for the reviewer
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.compose_project_prefixon a running event changes the names of new instances. Instances that already exist aren't renamed.school-scoreboard/andtheme/were removed from this PR.Test plan
go build ./...,go vet ./...andgo test ./...pass ingalvanize-instancer/(rebased on v0.7.4)ctf-event, custom prefix, and the hash staying the same with any prefix)Getdefaultnetwork being keptshow_tcp_ports: hidden by default, HTTP URL then ports, ports onlyhttpand atcpchallenge, with and withoutcompose_project_prefixchallenge-N.ymlentries sharing aninstance_groupresolve to one deployment