Skip to content

Fixes on top of v0.7.1 - #6

Closed
CorentinFelten wants to merge 5 commits into
masterfrom
fix/v0.7.1-fixes
Closed

CorentinFelten wants to merge 5 commits into
masterfrom
fix/v0.7.1-fixes

Conversation

@CorentinFelten

@CorentinFelten CorentinFelten commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Five bug fixes on top of v0.7.1, one commit each:

  • Set the PID limit under deploy.resources.limits (Docker Compose 2.38+ rejects pids_limit next to it)
  • Include the category in the JWT check, deploy lock and compose project name, and hash project names properly
  • Skip invalid challenge files instead of failing the whole challenge index
  • Honor randomized_port_min and randomized_port_max
  • Query expires_at instead of the nonexistent expired_at in GetExpiredDeployments

Docker Compose 2.38 and later reject a service that sets the
service-level pids_limit next to deploy.resources.limits:

  services.web: can't set distinct values on 'pids_limit' and
  'deploy.resources.limits.pids': invalid compose project

BuildResourceOverrides emitted exactly that whenever a PID limit and a
CPU or memory limit were configured, which is the default
(default_resource_limits in config.example.yaml), so every deployment
failed on current Docker installs. The PID limit is now emitted as
deploy.resources.limits.pids, next to cpus and memory. The pids_limit
setting in config.yaml and challenge.yml keeps its name.

The custom_compose playbook also drops a pids_limit set in the
challenge's own compose file when Galvanize sets the PID limit, as it
would otherwise hit the same error; Galvanize's limit applies, as it did
when it overwrote pids_limit. The services are replaced as a whole,
since a recursive combine cannot remove a key.
Challenge names are only unique within a category, but three places
used the name alone:

- DeployInstance and TerminateInstance compared only the challenge name
  of the request with the JWT's, so a token for web/login could deploy
  or terminate pwn/login;
- the per-instance deploy lock was keyed on name + team;
- BuildComposeProject built the Docker Compose project name, which also
  names the instance's Traefik router and subdomain, from the name and
  team, so two such instances shared one project.

Its suffix did not help either: sha1.New().Sum(name) appends the hash
of nothing to name instead of hashing it, so hexSum[:6] was always the
hex of "pol", 706f6c.

The JWT check and the lock key now include the category, and project
names are the sanitized category, name and team, cut to fit a
63-character DNS label, plus 8 hex characters of a SHA-1 of the
instance's identity.

Instances started before an upgrade keep their old project name:
PreparePlaybook passes it as legacy_compose_project when it differs,
and the http, tcp and custom_compose playbooks' delete tasks also run
docker compose -p <old name> down, a no-op when nothing exists and
never failing the run, so terminating them leaves nothing behind.
BuildIndex returned on the first challenge.yml it could not parse, so
one broken file stopped Galvanize from starting (Fatalf in serve) or
made every /admin/reload-challs fail. It also panicked instead of
returning an error when the challenge directory did not exist, since
WalkDir then calls back with a nil DirEntry, and it emptied the index
before walking, so a failed reload left no challenges at all.

Now:
- files that cannot be parsed (a bad compose file included), unreadable
  directories, and challenges declaring a category/name already indexed
  are skipped and logged, and the other challenges are indexed;
- the index is built aside and swapped in only on success: an
  unreadable challenge directory returns an error and keeps the current
  index;
- Skipped() lists the files the last build left out; serve warns about
  them at startup, and /admin/reload-challs returns
  {"indexed": n, "skipped": [{"path", "reason"}]} (Zync only checks
  the status, so it is unaffected).
The randomized host port range was read from the config but never
used: both allocators, the port bindings store used for deployments
and the in-memory one, hard-coded 20000-60999.

- InstancerConfig.RandomizedPortRange returns the configured range,
  each bound defaulting to 20000 and 60999 when unset, and Validate
  rejects a range outside 1-65535 or with the minimum above the
  maximum; Load calls it, so startup fails on an invalid range and a
  reload with one keeps the current config.
- Both allocators pick from that range. The store tries 128 random
  ports, then takes the first port no binding uses, so a nearly full
  range is still used up.
- A deployment that cannot get a host port (no free port left, or the
  store cannot be opened) now fails with an error naming the range,
  instead of leaving the container port to an ephemeral host port
  outside it.
GetExpiredDeployments filtered on expired_at, a column that does not
exist (the field is ExpiresAt, stored as expires_at), so any call
failed with "no such column". Nothing calls it yet, which is why it
went unnoticed.

The expiry scheduler ran its own, correct, copy of the query. Both now
use models.GetDeploymentsExpiringBy(db, t): running team deployments
expiring at t or earlier, soonest first. GetExpiredDeployments is that
query at time.Now(), and so, like the scheduler, it now leaves out
unique deployments, which have no team and never expire.
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.

1 participant