Repository navigation
Manage challenge repositories, builds and images through the admin API - #9
Merged
CorentinFelten merged 1 commit intoDec 2, 2026
Merged
Conversation
…min API Galvanize owns challenge_dir: CTF platforms (Zync) manage challenges through the admin API instead of scripts on the server, and Galvanize can run on its own machine. - Repositories: list, clone (only from repositories.sources, compared by scheme, host, port and path segments; optional per-source token sent as a header scoped to the source), pull (fetch + reset to the followed ref), remove (refused while instances exist). Git runs without hooks, fsmonitor or the ext transport. - GET /admin/challenges lists every definition with its build plan, its declared files resolved (challenge folder, then files/; absolute paths, "..", .git, symlinks leading outside and Git LFS pointers refused) and the repository commit. GET /admin/challenges/file serves a file or its SHA-1. Definitions JSON cannot encode are skipped. - POST /admin/build builds images on every Ansible host (docker build, docker compose build) from an archive of the challenge folder; POST /admin/images checks or removes them, reporting unreachable hosts. Compose build sections are allowlisted, names validated, and a challenge may not build an image another challenge folder uses or a protected one (build.protected_images). Extra vars of the build playbooks are marked unsafe for Ansible. - Background operations with logs and cancellation (/admin/operations). Cancelling stops the run: ansible-playbook gets SIGTERM, then every local process of the run is killed after 15 s, and a stop playbook ends what the run started on the hosts (marked by GALVANIZE_RUN_ID) and removes its build folder; the operation ends, and releases the lock, once all of it has stopped. A panic in a run or a build fails it instead of the server. Cancelling a finished operation answers 409. - GET /admin/challenges answers 404 for an unknown repository. A pull names the local changes it discards; a clone or pull answered with a credentials prompt says the repository does not exist or is private. - These endpoints need an admin token with the "manage" scope; every token must have an expiry. - Built compose services get unique tags (slugs + hash). Fixes the SSH ControlPath of Ansible runs: "%%h" reached ssh as a literal "%h", so all hosts of a run shared one control socket. Fixes config hot reloads: a file changed in several writes (cp truncates it first) could be applied half written, leaving an empty config until a restart. Changes are applied once the file is quiet for 500 ms, and a config without challenge_dir or ansible_dir is refused.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manage challenge repositories, builds and images through the admin API
Replaces the challenge tooling of ctfd-management (
challenges.sh) on the Galvanize side: Galvanize ownschallenge_dir, and a CTF platform (Zync) manages challenges through the admin API, without access to the server. Galvanize stays independent of CTFd and can run on its own machine.What's new
GET/POST /admin/repos,POST /admin/repos/{name}/pull,DELETE /admin/repos/{name}: list, clone (only fromrepositories.sources), update (fetch + reset to the followed branch or tag), remove (refused while instances of its challenges exist). The challenge index is reloaded afterwards. A pull names the local changes it discards; a repository that does not exist, or is private without a token, gives a clear error instead of git's askpass message.GET /admin/challengeslists every definition (any type) with its content, build plan (buildable,refused+ reason), declared files resolved (files[]), and the repository commit (404 for an unknown repository);GET /admin/challenges/fileserves a file or its SHA-1.POST /admin/buildbuilds on every Ansible host (docker build, ordocker compose buildfor the services with abuildsection) from an archive of the challenge folder;POST /admin/imageschecks or removes the built images, with the state of each image on each host (unreachableorerrorfor a host the check could not run on, never left out). Updating a repository builds nothing. Challenges are referenced by definition path ({path}) or{category, name}./admin/operations; 409 for a finished operation). Cancelling a build or image action really stops it:ansible-playbookgets SIGTERM, every local process of the run is killed 15 s later, and a stop playbook ends what the run started on the hosts (commands marked withGALVANIZE_RUN_ID) and removes its build folder. The operation ends, and releases the lock, only once all of it has stopped; an image is never retagged after a cancellation. A panic in a run or a build fails it instead of the server.repositories(sources,git_timeout),build(concurrency,timeout,protected_images). The Docker image includes git and git-lfs.Security
url_prefixmust end with/; credentials, queries, percent-encoding and./..segments are refused. A source token is https only, sent as a header scoped to the source, never written to the clone; redirects are not followed with a token. Git runs without hooks, fsmonitor or theexttransport..gitis never served; Git LFS pointers are reported.buildsections are allowlisted (no host network, secrets, SSH, extra contexts, host caches or extra tags); image, service and Dockerfile names are validated; a challenge may not build an image another challenge folder deploys, builds or buildsFROM, nor a protected image; extra vars of the build playbooks are marked unsafe, so Jinja in a name is never rendered (verified with Ansible).scope: manage; every token must now haveexp.Fix
ControlPathused%%h, which reaches ssh as a literal%h: every host of a run shared the first host's control socket. Now%C, for deployments too.cptruncates it first) could be applied half written, leaving Galvanize with an empty config until a restart. The change is now applied once the file has been quiet for 500 ms, and a config withoutchallenge_diroransible_diris refused (the current one is kept). Reproduced and verified on the test VM.Behaviour changes (see CHANGELOG)
expare rejected.challenge_dirare no longer indexed.imageis deployed asgalvanize/<slugs>-<hash>:latest.compose_filemust stay inside the challenge folder; a definition JSON cannot encode is skipped.Tests
make test: 245 passed on macOS, 247 passed on Linux with-race(six runs, no race);golangci-lint: 0 issues;make api-genreproducesapi.gen.go.docker build --no-cache, slowdocker compose build, rebuild + ingest cancelled from Zync, anddocker stopof Galvanize during a build: stopped in under 2 s, no process, build folder or zombie left on the host or in the container, image not retagged. Deployments behave exactly as before this PR.Not covered / follow-ups
deploy_parametersstill reach the deployment playbooks as Jinja-rendered extra vars (pre-existing; same class as the build issue fixed here).galvanize:0.7.5: a release is needed before it can use this.managetokens, warnings on unknown keys of challenge definitions (e.g.file:forfiles:).