Skip to content

Setting up the agent ​

vulnboxd-agent connects the vulnbox to your team's hub. It reads the capture from the capture broker and sends it on, reports what vulnboxd is doing, and applies the rule pushes the hub sends. It comes in every release next to the other binaries, and runs as its own service.

You need the hub deployed first, or at least its certificate and the address the agent will connect to.

Turn it on ​

  1. Capture has to be on, since the agent reads the broker: set pcap.enabled if it is not. The agent finds the broker at pcap.listen.

  2. Make the agent's key, and swap certificates with the hub as described in exchange the keys:

    sh
    sudo vulnboxd-agent keygen /etc/vulnboxd     # writes agent.crt and agent.key

    Give the hub agent.crt, and put the hub's certificate at /etc/vulnboxd/hub.crt. Those are the paths the agent reads by default.

  3. Add the agent section to /etc/vulnboxd/config.yml, with the address of the hub's ingest Service:

    yaml
    agent:
      enabled: true
      hub: hub-ingest.example.org:7443
  4. Install and start it:

    sh
    sudo vulnboxctl install          # writes the unit; keeps the existing config

    With agent.enabled set, vulnboxctl install writes /etc/systemd/system/vulnboxd-agent.service and enables and starts it (with --no-start, only enables it). It is safe to run again on a box that is already set up.

Then check that it is connected:

sh
systemctl status vulnboxd-agent
journalctl -fu vulnboxd-agent

and open the hub's Vulnbox screen: it shows what vulnboxd is doing, reported by the agent a few seconds ago. Capture shows the spool and any gaps.

If the agent stops for good once it is running — an unreadable spool directory, a listen address that is taken — it posts to the alert webhook on its way out, and systemd starts it again five seconds later. A config or a certificate it cannot read stops it before that, without a post: look in journalctl -u vulnboxd-agent.

The unit ​

ini
[Unit]
Description=vulnboxd traffic analysis agent
After=network-online.target vulnboxd-pcap.service
Wants=network-online.target

[Service]
ExecStart=/usr/local/bin/vulnboxd-agent -c /etc/vulnboxd/config.yml
Restart=always
RestartSec=5
# Below the capture broker: when memory runs out, a spool that lives on disk is the cheaper loss.
OOMScoreAdjust=-300

[Install]
WantedBy=multi-user.target

The same unit is in every release as vulnboxd-agent.service, for a box you set up by hand.

Like the broker, it is tied to nothing of the daemon's. The agent only reads what vulnboxd publishes — its metrics, its state directory, the services' compose files, rules files and Git history — so either can restart without the other noticing. Leave metrics on: like vulnboxctl top, the agent reads the daemon's state from there.

vulnboxctl upgrade replaces the agent along with the daemon and restarts it. Unlike the broker's, the agent's restart costs nothing: its spool is on disk, and the hub says where to resume.

What it sends ​

  • The capture, cut into segments of up to a second or 4 MiB, compressed. A segment is deleted from the box only once the hub says it has stored it.
  • The manifest: your services and their ports, the flag format, the game's timing and, with a game mode, your flag IDs. The hub needs it to file flows under services and ticks and to find flags.
  • vulnboxd's state, every second when it changes and at least every five: deploys, checker verdicts, ports, rules files and their Git history.
  • Host events from vulnboxd-sensor, which connects to <state_dir>/sensor.sock: what the services' processes do. They are segments like the capture, kept in the same spool within the same budget and acknowledged the same way; what the agent cannot keep up with is counted and reported as lost rather than slowing the sensor down.
  • Rule hits, from <state_dir>/rule-hits.jsonl, and the proxy's requests, from <state_dir>/requests.jsonl. How far each has been read is kept in the spool directory once the hub has the lines, so a restart neither skips them nor sends many twice.
  • The container inventory, from <state_dir>/inventory.json, on every connection and whenever it changes.
  • Files the hub asks for, out of a service's running container (see agent.file_pull).
  • Snapshots of a service's checkout for the hub's hook proposals: its files, compose configuration and commit (see agent.service_files).
  • A heartbeat every ten seconds: whether the capture is connected, how full the spool is, what was lost.

The spool ​

What the hub has not acknowledged yet waits on disk in agent.dir (/var/lib/vulnboxd/spool), so a hub that is down, a slow link or a restart of either side loses nothing — as long as there is room.

The disk is a guest here. During a game a full disk stops the services, the builds and Git, all of which matter more than the capture, so before every write the spool works out what it may use:

text
budget = min(max_size, what the spool holds + free space − min_free)
default
max_sizethe smaller of 1 GiB and 5% of the filesystem
min_freethe larger of 2 GiB and 10% of the filesystem

Sizes are counted in allocated blocks, since blocks are what fill a disk. Over budget, the oldest segments go first, those the hub already has before those it does not; capture dropped before the hub got it is reported to the hub as a gap, so the Capture screen shows exactly what is missing.

When there is no budget at all, or a write fails, the spool keeps segments in memory instead, up to agent.memory (64 MiB), and tries the disk again 30 seconds later. max_size: 0 keeps it in memory for good.

A day of capture

A busy game produces a lot. If the hub is going to be unreachable for a while — a cluster upgrade, the team's uplink — the defaults may not cover it. Raise max_size if the box has the room; min_free still keeps the services safe.

The spool directory is the agent's own, and it cleans up after itself there: half-written and broken segments, and those of an earlier run that can no longer be resumed. So it must be an absolute path to a directory of its own, and must not be or contain state_dir or services_dir.

Nothing the capture does waits for the disk or the network. The broker disconnects a reader that falls behind, so if the spool's writer cannot keep up, segments are counted as lost and become a gap rather than stalling the capture.

When the hub cannot be reached ​

By default the agent dials the hub, retrying with a growing pause up to 30 seconds. If the vulnbox cannot open connections to your cluster but the cluster can reach the box, let the hub dial instead:

yaml
agent:
  enabled: true
  mode: listen
  listen: "[::]:7443"

and set ingest.dial in the chart to the box's address and that port (see the hub side). Only the pinned hub certificate gets past the handshake, but there is no reason to show other teams the port at all: firewall it to the hub's address.

Limiting what the hub may change ​

The agent applies rule pushes by default. The hub is one more thing that can be compromised, so the agent's config, which the hub cannot touch, decides what it may change:

yaml
agent:
  rule_push: true                  # false refuses every push
  rule_push_deny: [route, mirror]  # rule keys the hub may not add or change
  rule_push_bypass: false          # the hub may not change bypass headers
  rule_push_rate: 6                # at most this many pushes a minute
  file_pull: false                 # the hub may not read files out of the containers
  file_push_allow: ["**/Dockerfile", "*compose*.y*ml"]  # the only files a file push may change
  file_push_rate: 2                # at most this many file pushes a minute
  shell: false                     # the hub may not open shells in the containers
  container_restart: false         # the hub may not restart containers

route and mirror send traffic somewhere else, which a compromised hub would like to do with your flags; a bypass header opens a way past every rule. Denying them still leaves the hub everything it needs to block, stall, rewrite and log. See Rule pushes for how a push is applied, and agent for every setting.

A file push, which commits an approved hook proposal to a service's checkout, changes the services' code itself: file_push: false refuses them all, and file_push_allow and file_push_deny keep them to the files hooks need (see agent.file_push).