Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
run: |
VERSION=$(grep -oP 'Version = "\K[0-9]+\.[0-9]+\.[0-9]+' galvanize-instancer/constants.go)
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -62,6 +64,7 @@ jobs:
with:
context: .
file: galvanize-instancer/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.REGISTRY }}/${{ steps.image.outputs.name }}:${{ steps.version.outputs.version }}-B${{ github.run_number }}
labels: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand Down Expand Up @@ -65,6 +68,7 @@ jobs:
with:
context: .
file: galvanize-instancer/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ TODO
docker-compose.local.yml
config.yaml
coverage.out
openapi.yaml
openapi.yaml
monitoring/worker/cf.env
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

## vX.X.X (YYYY-MM-DD)

## v0.7.5 (2026-11-11)

### Added
- `GET /admin/version` returns the running version (e.g. `{"version": "0.7.5"}`), for Zync to check compatibility. It requires an admin token: requests without a valid token get 401 and player tokens 403, so the version is never disclosed to players or unauthenticated clients

### Changed
- The API port no longer serves `/metrics`, which was exempt from authentication and exposed challenge names and team IDs to anyone who could reach the API. Metrics stay on the metrics server (port 5001, basic auth when `metrics.password` is set), which the provided Prometheus configuration already scrapes

### Fixed
- Connection info lists every HTTP endpoint of an instance, one per line, ordered by compose service: each host of each Traefik router rule as `https://<host>/`. Only the first container with a route was reported, so a challenge with several web services showed only one of them, depending on the order Ansible listed the containers. Without any route, the published ports of every container are listed, sorted by container port, instead of only the first container's; with `show_tcp_ports`, they follow the HTTP endpoints as before. Only routers' `.rule` labels are read, so other Traefik labels set by challenge authors (entrypoints, tls, middlewares) no longer make the route random, and containers with `traefik.enable=false` are skipped

## v0.7.4 (2026-10-27)

### Added
- Multi-arch Docker images (linux/amd64, linux/arm64)

## v0.7.3 (2026-10-01)

### Fixed
Expand Down
1 change: 1 addition & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ instancer:
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: "ctf-event" # Readable prefix of instance names/subdomains (default: "ctf-event")
db_path: "./data/deployer.sqlite" # Path to SQLite database
deployment_ttl: "1h" # Time-to-live for deployments (default: 1h)
deployment_ttl_extension: "30m" # Time to extend deployment TTL with on extension request (default: 30m)
Expand Down
5 changes: 5 additions & 0 deletions data/challenges/example/custom_compose/challenge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ deploy_parameters:
#
# You no longer need to hand-write Traefik labels, attach the external
# network, or pick host ports yourself.
#
# Several services can be exposed: players get every https://<subdomain>/
# endpoint, one per line, ordered by service name. Published tcp ports
# (<scheme or tcp>://<host>:<port>) are listed when nothing is exposed over
# http, or after the http endpoints with `show_tcp_ports: true`.
expose:
- service: web
port: 80
Expand Down
3 changes: 2 additions & 1 deletion data/challenges/example/http/challenge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type: zync

# The 'http' playbook deploys a single container behind Traefik.
# Traefik routes traffic based on a generated subdomain:
# <compose_project>.<instancer_host> (e.g. polypwn-web-example-http-team1-9448f1e7.challs.example.com)
# <compose_project>.<instancer_host> (e.g. ctf-event-web-example-http-team1-9448f1e7.challs.example.com)
# The "ctf-event" prefix can be changed with instancer.compose_project_prefix in config.yaml.
playbook_name: http

deploy_parameters:
Expand Down
12 changes: 6 additions & 6 deletions data/playbooks/custom_compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
tags:
- delete

# Instances started by Galvanize v0.7.1 or earlier have another project
# name (legacy_compose_project, set when it differs): remove such a
# leftover too. A no-op when there is none, and never fails the run.
- name: Remove an instance left under its previous project name
ansible.builtin.command: "docker compose -p {{ legacy_compose_project }} down --remove-orphans"
when: legacy_compose_project is defined
# Instances started by earlier Galvanize versions have other project
# names (legacy_compose_projects, those that differ): remove such
# leftovers too. A no-op when there are none, and never fails the run.
- name: Remove an instance left under a previous project name
ansible.builtin.command: "docker compose -p {{ item }} down --remove-orphans"
loop: "{{ legacy_compose_projects | default([]) }}"
changed_when: false
failed_when: false
tags:
Expand Down
19 changes: 10 additions & 9 deletions data/playbooks/http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

- name: Build compose definition
ansible.builtin.set_fact:
compose_definition:
_compose_def:
services:
web: "{{ _web_service }}"
networks: "{{ {traefik_network: {'external': true}} }}"
Expand All @@ -46,28 +46,29 @@

- name: Déploiement du docker-compose
community.docker.docker_compose_v2:
definition: "{{ compose_definition }}"
definition: "{{ _compose_def }}"
project_name: "{{ compose_project }}"
pull: missing
tags: create

- name: Arrêt des conteneurs
ansible.builtin.command: "docker compose -p {{ compose_project }} kill"
failed_when: false
tags: delete

- name: Arrêt et suppression du docker-compose
community.docker.docker_compose_v2:
definition: "{{ compose_definition }}"
definition: "{{ _compose_def }}"
project_name: "{{ compose_project }}"
state: absent
tags: delete

# Instances started by Galvanize v0.7.1 or earlier have another project
# name (legacy_compose_project, set when it differs): remove such a
# leftover too. A no-op when there is none, and never fails the run.
- name: Remove an instance left under its previous project name
ansible.builtin.command: "docker compose -p {{ legacy_compose_project }} down --remove-orphans"
when: legacy_compose_project is defined
# Instances started by earlier Galvanize versions have other project
# names (legacy_compose_projects, those that differ): remove such
# leftovers too. A no-op when there are none, and never fails the run.
- name: Remove an instance left under a previous project name
ansible.builtin.command: "docker compose -p {{ item }} down --remove-orphans"
loop: "{{ legacy_compose_projects | default([]) }}"
changed_when: false
failed_when: false
tags:
Expand Down
23 changes: 14 additions & 9 deletions data/playbooks/tcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

- name: Build compose definition
ansible.builtin.set_fact:
compose_definition:
_compose_def:
services:
tcp: "{{ _tcp_service }}"
tags:
Expand All @@ -33,24 +33,29 @@

- name: Déploiement du docker-compose
community.docker.docker_compose_v2:
definition: "{{ compose_definition }}"
definition: "{{ _compose_def }}"
project_name: "{{ compose_project }}"
pull: missing
tags: create

- name: Arrêt des conteneurs
ansible.builtin.command: "docker compose -p {{ compose_project }} kill"
failed_when: false
tags: delete

- name: Arrêt et suppression du docker-compose
community.docker.docker_compose_v2:
definition: "{{ compose_definition }}"
definition: "{{ _compose_def }}"
project_name: "{{ compose_project }}"
state: absent
tags: delete

# Instances started by Galvanize v0.7.1 or earlier have another project
# name (legacy_compose_project, set when it differs): remove such a
# leftover too. A no-op when there is none, and never fails the run.
- name: Remove an instance left under its previous project name
ansible.builtin.command: "docker compose -p {{ legacy_compose_project }} down --remove-orphans"
when: legacy_compose_project is defined
# Instances started by earlier Galvanize versions have other project
# names (legacy_compose_projects, those that differ): remove such
# leftovers too. A no-op when there are none, and never fails the run.
- name: Remove an instance left under a previous project name
ansible.builtin.command: "docker compose -p {{ item }} down --remove-orphans"
loop: "{{ legacy_compose_projects | default([]) }}"
changed_when: false
failed_when: false
tags:
Expand Down
8 changes: 5 additions & 3 deletions galvanize-instancer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM golang:1.25 AS builder
FROM --platform=$BUILDPLATFORM golang:1.25 AS builder
ARG TARGETOS TARGETARCH

WORKDIR /app

Expand All @@ -8,7 +9,7 @@ RUN go mod download

# Copy source code
COPY ./galvanize-instancer .
RUN go build -o galvanize .
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o galvanize .

FROM debian:stable-slim
LABEL authors="28Pollux28"
Expand All @@ -19,7 +20,8 @@ RUN useradd -ms /bin/bash galvanize
RUN apt-get update && apt-get install -y curl pipx ssh-client tini \
&& rm -rf /var/lib/apt/lists/* \
&& pipx ensurepath --global \
&& pipx install --include-deps --global ansible
&& pipx install --include-deps --global ansible \
&& ansible-galaxy collection install community.docker -p /usr/share/ansible/collections
WORKDIR /app
RUN mkdir "data"
COPY ./data/playbooks ./data/playbooks
Expand Down
30 changes: 29 additions & 1 deletion galvanize-instancer/api/openapi.yaml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.3
info:
title: Galvanize Instancer
version: 0.7.3
version: 0.7.5
description: API for deploying CTF challenges using Ansible

paths:
Expand Down Expand Up @@ -244,6 +244,25 @@ paths:
'500':
description: Internal server error

/admin/version:
get:
summary: Galvanize version
description: Returns the version of the running Galvanize, e.g. for Zync to check that it is compatible. Admins only, so that neither players nor unauthenticated clients learn which version, and so which known issues, a deployment has.
operationId: getVersion
security:
- bearerAuth: [ ]
responses:
'200':
description: Galvanize version
content:
application/json:
schema:
$ref: '#/components/schemas/VersionResponse'
'401':
description: Unauthorized
'403':
description: Forbidden - Admin access required

/admin/config-check:
post:
summary: Check communication with Zync
Expand Down Expand Up @@ -554,6 +573,15 @@ components:
- created_at
- updated_at

VersionResponse:
type: object
properties:
version:
type: string
description: Version of the running Galvanize (e.g. 0.7.3).
required:
- version

ReloadChallengesResponse:
type: object
properties:
Expand Down
47 changes: 47 additions & 0 deletions galvanize-instancer/cmd/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/assert"
)

// The API port no longer serves /metrics, which skipped authentication:
// metrics are only on the metrics server (:5001)
func TestAPIPort_NoMetrics(t *testing.T) {
e := newAPI("9.8.7")
assert.Equal(t, http.StatusUnauthorized, get(e, "/metrics", "").Code, "requires a token like any route")

admin := signed(t, jwt.SigningMethodHS256, []byte(testSecret), "admin", time.Now().Add(time.Hour))
assert.Equal(t, http.StatusNotFound, get(e, "/metrics", admin).Code, "and is not served")
}

func scrape(h http.Handler, user, pass string) int {
req := httptest.NewRequest(http.MethodGet, "/metrics", nil)
if user != "" || pass != "" {
req.SetBasicAuth(user, pass)
}
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
return rec.Code
}

// The metrics server's authentication is unchanged: none without a
// password, basic auth with one (username defaults to prometheus)
func TestMetricsHandler(t *testing.T) {
metrics := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte("ok")) })

assert.Equal(t, http.StatusOK, scrape(metricsHandler("", "", metrics), "", ""), "open without a password")

h := metricsHandler("", "s3cret", metrics)
assert.Equal(t, http.StatusUnauthorized, scrape(h, "", ""))
assert.Equal(t, http.StatusUnauthorized, scrape(h, "prometheus", "wrong"))
assert.Equal(t, http.StatusUnauthorized, scrape(h, "admin", "s3cret"))
assert.Equal(t, http.StatusOK, scrape(h, "prometheus", "s3cret"))

assert.Equal(t, http.StatusOK, scrape(metricsHandler("scraper", "s3cret", metrics), "scraper", "s3cret"))
}
30 changes: 18 additions & 12 deletions galvanize-instancer/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ var serveCmd = &cobra.Command{
// 2. Middleware
useMiddleware(e)

// 3. Prometheus
// 3. Prometheus: request metrics are gathered here and served by the
// metrics server on :5001 only, never on the API port
e.Use(echoprometheus.NewMiddleware("instancer")) // register middleware to gather metrics from requests
e.GET("/metrics", echoprometheus.NewHandler())

// JWT secret from env (for security);
jwtSecret := os.Getenv("JWT_SECRET")
Expand All @@ -83,16 +83,7 @@ var serveCmd = &cobra.Command{
cfg.Instancer.AnsibleDir = ansiblePath

// 4. Auth
jwtConfig := echojwt.Config{
NewClaimsFunc: func(c echo.Context) jwt.Claims {
return new(auth.Claims)
},
SigningKey: []byte(jwtSecret),
Skipper: func(c echo.Context) bool {
return c.Path() == "/health" || c.Path() == "/metrics"
},
}
e.Use(echojwt.WithConfig(jwtConfig))
e.Use(jwtMiddleware(jwtSecret))

if err := utils.RegisterSSHHosts(cfg); err != nil {
zap.S().Fatalf("Failed to register SSH hosts: %v", err)
Expand Down Expand Up @@ -191,6 +182,7 @@ var serveCmd = &cobra.Command{
TeamDeployer: teamDeployer,
ExpiryScheduler: expirySched,
JobQueue: jobQueue,
Version: rootCmd.Version,
})
api.RegisterHandlers(e, srv)

Expand Down Expand Up @@ -280,6 +272,20 @@ func configureQueueless(cfg *config.Config, jobQueue *worker.Queue, expirySched
return teamDeployer
}

// jwtMiddleware requires a valid HS256 token signed with secret on every
// route but /health; handlers then check the claims' role.
func jwtMiddleware(secret string) echo.MiddlewareFunc {
return echojwt.WithConfig(echojwt.Config{
NewClaimsFunc: func(c echo.Context) jwt.Claims {
return new(auth.Claims)
},
SigningKey: []byte(secret),
Skipper: func(c echo.Context) bool {
return c.Path() == "/health"
},
})
}

// useMiddleware installs the request logger, panic recovery and CORS.
//
// Recover turns a panic in a handler into a 500 response, logged with its
Expand Down
Loading
Loading