Skip to content

How it works ​

Discovery ​

Every second, vulnboxd looks through services_dir (default /srv). Each directory with one of these files is a service, named after the directory:

  • compose.yaml
  • compose.yml
  • docker-compose.yml
  • docker-compose.yaml

Directories starting with a dot, and those listed in exclude, are skipped. A service whose directory disappears is dropped and its ports released.

Moving ports behind the proxy ​

For each service, vulnboxd works out the compose files exactly as docker compose would when run in the service directory: the compose file plus the service's own override (compose.override.yaml, docker-compose.override.yml and so on, if there is one), or whatever COMPOSE_FILE names in .env or the environment (split on COMPOSE_PATH_SEPARATOR, : by default). It asks docker compose config what those files add up to — after variable substitution, include, extends, !reset and !override — and collects every port that is published on the host. Services in a profile that is not active are left out, as compose leaves them out; services on the host network have no ports to move (see below). If docker cannot be asked (or takes longer than five seconds), vulnboxd merges the files' ports and networks itself, following compose's rules but without include and extends, and logs that it did. It then writes an override to /var/lib/vulnboxd/<service>/compose.override.yml that republishes each of those ports on loopback, starting at 127.0.0.1:20000, and listens on the original public port itself.

Where vulnboxd sits Traffic from the game network reaches the public port, which vulnboxd now holds. It applies the incoming rules, forwards to the container on a loopback port, and applies the outgoing rules to the answer. Game networkcheckerattackersvulnboxd:8080public portrulesin: blockrewrite, routeout: blockrewrite, redactContainer127.0.0.1:20000unchanged compose+ generated override
The public port moves into vulnboxd; the container keeps running as before, on loopback.

The service's own compose files are never modified. Every docker compose command vulnboxd runs passes all of the service's files with -f, in compose's order, and vulnboxd's override last, so everything the service's own override sets (environment, volumes, commands, extra ports) still applies. vulnboxd's override uses ports: !override and lists the complete port list of each service it touches, intercepted ports moved to loopback and the rest as they were, so ports that came from the service's override are kept rather than lost.

Use vulnboxctl compose

Because the override lives outside the service directory, a plain docker compose up would start the containers with their original ports, which then clash with the proxy. Use vulnboxctl compose <service> ... instead: it runs the same command with the override applied.

A port can be left alone with intercept: false in the rules file, for the whole service or one port. It is then published exactly as the compose file says, with no proxy and no rules.

Which ports count as public ​

A port is moved behind the proxy when the game can reach it: published on every address (no address, 0.0.0.0, ::, or the same written out as 0:0:0:0:0:0:0:0), or on the box's game address (init.vulnbox_ip, or what the game mode works out). A port bound to loopback, a bridge's address or any other address of the box's own is left as it is. Some shapes need a word:

  • A range for one port, 8000-8010:80: Docker publishes the container port on one free port of the range, and which one cannot be known beforehand. The proxy takes the first, 8000.
  • SCTP (9000:9000/sctp): the proxy speaks tcp and udp only, so an SCTP port stays published as it is, and an alert says it is public without the proxy.
  • Ranges that do not fit (8000-8010:80-81), an unknown protocol, or any port entry that cannot be read: see below.

Services on the host network ​

A service on the host's network shares the box's own network stack: every port it listens on is open on the box's addresses directly, and Docker publishes nothing for it (it discards ports: for such a service). So vulnboxd has nothing to move behind the proxy: no rule applies to it, nothing of it is filtered, and the capture is not scoped to it. The check after a deploy, which compares Docker's port bindings, cannot see it either. A service is on the host network when:

  • it has network_mode: host, whether or not it also lists ports: (usually it does not);
  • it is on a network that is the host's, such as an external network named host (networks: {hostnet: {name: host, external: true}});
  • it has network_mode: service:<other> and the other service is on the host network.

All of these are followed through the service's override, COMPOSE_FILE, !reset and !override, both when docker compose config is asked and when vulnboxd merges the files itself.

vulnboxd raises one alert per service and change naming each such compose service and how it got there, shows it in vulnboxctl top (<service>: HOST NETWORK, in red) and in vulnboxctl inventory, and counts it in vulnboxd_host_networked_services. After each deploy it also looks for what the service's running containers listen on (through their processes' sockets in /proc, best effort, at most a few seconds) and names those ports in a second alert when they changed since the last deploy. Loopback is left out of that list, as the game cannot reach it.

The service is still deployed. Refusing would take it down, which the checker counts against the team, while the fix belongs in the compose file anyway: give the service a normal network and publish the ports it listens on with ports:, and vulnboxd moves them behind the proxy like any other. Putting a service on the host network in a change, however it is written, is also something the compose gate holds back until a person allows it.

When the ports cannot be worked out ​

If the compose files do not say which ports they publish — a port entry that cannot be read, files that do not parse — the service is not deployed until they do, and an alert says why. The containers that run keep running. Deploying anyway would publish a port vulnboxd knows nothing about, on its public address, with no proxy and no rule in front of it.

Checking what Docker really publishes ​

After every deploy, once the service is up (or the health check gave up), vulnboxd asks Docker which host ports the service's containers actually have, and compares them with the plan: intercepted ports must be on 127.0.0.1, and a public binding is expected only for an intercept: false or SCTP port. Anything else — an override that did not apply, a container started by hand with docker run -p, a compose feature vulnboxd did not understand — raises an alert naming the port, address and container, and shows in vulnboxd_unproxied_bindings.

A container left over from docker compose run (a one-off job, such as a migration) is not part of what up deploys: it does not fail the health check, stopped or failed, and it does not count as the service running.

The rules file ​

The first time a service is discovered, vulnboxd writes a vulnboxd-rules.yml into its directory. It lists every public port, with its protocol set to tcp or udp, and a header comment that documents every option. After that vulnboxd never writes it again, so your edits and comments stay.

If the service is in a git repository, the new file is committed as vulnboxd and pushed, rebasing onto the remote if it moved on. The whole team can then edit rules through git. Only that one file is committed; anything else someone has staged is left alone.

A port the file does not mention is still proxied. The file is a starting point, not the list of ports vulnboxd knows about: a port published later is picked up from the compose file, moved behind the proxy at the end of the tick like any other, and treated as plain tcp or udp with whatever service-wide rules: you have written. Add it to the file when you want rules or a protocol of its own. The reverse is only a warning: a port in the rules file that the compose file does not publish is logged and ignored.

A service added mid-game is discovered within a second, gets a rules file of its own written, committed and pushed the same way, and is deployed at the end of the tick.

What happens when something changes ​

you changepicked uptakes effect
the ruleswithin a secondimmediately, open connections included
the rules, but the file is invalidwithin a secondnot at all; the error is logged and the previous rules stay
protocolwithin a secondon the next connection; open ones keep the protocol they started with
intercept or which ports are publishedwithin a secondat the end of the tick, with a redeploy
code, pushed to giton the next poll (poll_interval)built right away, deployed at the end of the tick
a compose file (an override, or one it includes or extends) or .envwithin a secondports at the end of the tick; code on the next deploy; held back if it grants containers more

Open connections switch to the new rules on their next read, request or message. On a tcp stream, a match that was part way through starts over.

Rules are not reloaded while the end-of-tick window is open, so that compiling them never holds up a deploy; a change made then is picked up just after.

Editing only the rules file never causes a rebuild: it is left out of the fingerprint vulnboxd uses to decide whether a service changed.

Git ​

Every poll_interval (default 10 s), vulnboxd fetches each service's repository. If only the remote moved, the branch is fast-forwarded. If both moved, local commits are replayed onto the remote, with any uncommitted changes stashed for the duration and put back afterwards. If that does not apply cleanly, everything is put back as it was and the conflict is logged for a human to resolve.

An untracked or ignored file that an incoming commit would write over is not lost: it is moved to .git/vulnboxd-saved/<time>/ in the repository first, with an alert saying so. A rebase that vulnboxd started and that was cut short (vulnboxd stopped in the middle) is aborted before the next pull. A repository that a person left in the middle of a rebase, merge or cherry-pick, or on a detached HEAD, is not touched: syncing it pauses, the poll result is failed, and one alert says why (and another when it works again).

Fetches and pushes have time limits (15 s to connect, 60 s without progress, 10 minutes in all) and run without holding the lock that deploys and rollbacks take, so an unreachable remote never holds up a rollback.

A repository without a remote is left alone: local commits only.

vulnboxd drives git through libgit2, and authenticates with the deploy key recorded for the repository by init, falling back to an ssh agent.

What vulnboxd does not take from the repository ​

A container that can write its service's directory (a .:/app volume, common in CTF services) can write its .git too, and vulnboxd runs git as root. So nothing in a repository's own configuration decides where vulnboxd writes, what it fetches or where it pushes:

  • The working tree is the service directory, always. The git directory has to be the .git directory in it. vulnboxd refuses a .git file (gitdir: …), a .git symbolic link, core.worktree, commondir, objects/info/alternates, config includes, and git files (HEAD, config, index, refs, …) that are not regular files or are absurdly large. A refused repository is not synced; one alert says why, and another when it works again.
  • The remote and the branch come from vulnboxd's config: git.remote and git.branch (origin and main by default). A checkout moved to another branch is not synced. The repository's own branch.*.merge, fetch refspecs and url.*.insteadOf rewrites are not used (a rewrite stops the fetch rather than being followed).
  • The remote's address is vulnboxd's own record, in <state_dir>/git-remotes.json. vulnboxctl init writes it when it sets the remote up, and a repository vulnboxd has not seen before gets it recorded at the first sync. After that, a change to .git/config is ignored and alerted once. To really move a service to another remote, use vulnboxctl git-remote.
  • The repository's owner is checked. A repository owned by the user vulnboxd runs as is fine. One owned by someone else is accepted inside the services directory (a checkout made as an ordinary user is common there), and an alert names the owner once. Anywhere else, such as a .git found above the services directory, it is refused, with the repository and its owner named. libgit2 refuses such repositories on its own, and vulnboxd used to fail silently on that.

Git hooks are never run by vulnboxd (libgit2 runs none). They do run when a person uses git by hand in a service directory whose .git a container can write, which is one reason for the self-mount alert.

Files in a service directory ​

A service's containers can write to its directory: a volume such as ./data is theirs to fill, and whoever breaks into a container can put a symbolic link there. vulnboxd runs as root, so every file it reads or writes in a service directory — the rules file, the files of a rollback or a deploy bisect, files pushed from the hub, the hub's snapshot of the service, a .gitignore the setup adds — is opened below the directory with openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS): a link anywhere on the way, .., or an absolute path is refused by the kernel. Writes go to a new file that is renamed over the old one, so a link standing where the file goes is replaced, never followed. A commit vulnboxd makes reads the file the same way, so a link to /etc/shadow can never be committed and pushed.

Where git itself writes the working tree (a fast-forward, a rebase), vulnboxd refuses to go on when a file would be written through a link that the repository does not have, and the sync reports itself stuck until someone looks; libgit2 also opens every file it writes with O_NOFOLLOW. Kernels before 5.6 have no openat2; there the path is walked one directory at a time with O_NOFOLLOW, which refuses the same things.

Every compose file, .env file, file they include or extend (an env_file included), and rules file is read with a size cap (4 MiB), only if it is a regular file, and without blocking: it is opened with O_PATH first, checked, and only then read. A FIFO, a link to /dev/zero or a 64 GiB sparse file is refused at once, before docker compose is run on it, rather than hanging or exhausting the daemon that serves every port. A service with such a file is not deployed (its ports cannot be worked out), and the alert says which file.

Compose changes that grant more ​

Before every build and every deploy, vulnboxd reviews what the service's compose configuration lets its containers do to the host:

  • privileged, cap_add, devices, device_cgroup_rules;
  • network_mode, pid, ipc, uts, userns_mode or cgroup set to host, and cgroup_parent; joining the host's network some other way (an external network named host, or network_mode: service: a service on the host network) counts as well;
  • security_opt (anything but no-new-privileges);
  • binds of host paths outside the service directory, binds through a symbolic link in it, and named volumes that are really host directories (driver_opts: {o: bind, device: …});
  • secrets, configs, env_files and build contexts from outside the service;
  • privileged builds, build.network: host, build entitlements;
  • binds of the service's own files (its directory, .git, compose and .env files, rules file).

Then it compares the list with the list of the version that is deployed. A change that adds anything, whether it was pushed, edited in the working tree, or written by a container that can write the service's directory, is held back. The running version stays, and one alert names what it adds and the code to allow it with. Until someone runs vulnboxctl allow-compose <service> <code>, that change is not built or deployed. The code covers exactly that list, so anything added afterwards is held back again. Changes that grant the same or less go through as before. The first configuration vulnboxd sees for a service (at install or after the upgrade that brought this) is taken as it is, with an alert listing what it grants.

What is deployed is exactly what was reviewed. docker compose config renders the configuration into <state_dir>/<service>/compose.rendered.json, and build and up run on that file and the port override, not on the compose files, which could change between the review and the deploy.

A service whose compose lets containers write its own files gets an alert at setup (vulnboxctl init, vulnboxctl install) and once from the daemon. Mount only the data directories if you can.

Two things the review cannot cover:

  • Docker follows a symbolic link in a bind source when it creates the container. A link planted below the service directory after the review (in a directory the container can write) is not seen.
  • A FIFO planted somewhere in the working tree can stall git sync for that repository, because libgit2 opens files such as .gitignore while it works. It shows as a sync that keeps reporting the checkout as busy, never as a hang of the daemon.

Starting and restarting ​

On startup every service is deployed once, in the first window, so the containers match the current override. A window that opens while the daemon is busy with something else (taking up an upgrade, a slow reload) is not skipped: its deploys start as soon as the daemon comes round to them, still inside the window. If vulnboxd is restarted and finds the containers already running with the override it would write, it takes them over as they are, without redeploying.

While vulnboxd is not running, intercepted ports have nothing listening on them. Run it under systemd with Restart=always.

Whether the daemon that wrote a status file (deploy.json, inventory.json, bisect.json) is still running is judged by the process name (comm) of the pid it recorded, and the inventory recognises Docker's port forwarders by theirs (docker-proxy). A container process can give itself either name, so after the daemon died and its pid was reused, a stale file can look current, or the inventory can list a port that isn't Docker's. This only affects what is shown (vulnboxctl top, inventory, bisect show, what the agent reports). Nothing that matters for security is decided on it.