vagusQUIC and WebTransport relay for services behind NAT

☰ Contents · Reference › Operations

Operations

Deployment and runtime reference for vagus relay and vagus connect. For a step-by-step deployment guide (including Docker Compose), see Self-hosting. For an AWS Lightsail walkthrough, see AWS Lightsail.

Ports and boundaries

Run vagus relay on a public host with reachable UDP and HTTPS ports. Run vagus connect beside each private QUIC service behind NAT; the service host needs outbound UDP only.

Listener Port / Proto Exposure Purpose
Relay -public UDP 443 Public Client QUIC v1/v2, HTTP/3, and WebTransport traffic (*.relay.example.com)
Relay -control UDP 19451 Connectors (firewall on private relays) Outbound vagus/1 control tunnel from vagus connect (control.relay.example.com)
Relay -https TCP 443 Public Route statements (/v1/statements/<id>), WebSocket fallback, admission, and native handoff
Service -backend Local UDP (e.g. 127.0.0.1:4443) Loopback / private net Target QUIC service; one connected local UDP socket per client route

See Security and threat model for the trust-boundary diagram and key roles, and Self-hosting for DNS and certificate setup.

Kernel UDP buffers

vagus relay requests 7 MiB socket buffers on its public and control UDP sockets, which Linux clamps to net.core.rmem_max and net.core.wmem_max (often 208 KiB by default). Under bursts of incoming QUIC Initial packets, a small cap causes kernel drops visible as RcvbufErrors in /proc/net/snmp. Raise both caps on Linux:

sudo sysctl -w net.core.rmem_max=7500000 net.core.wmem_max=7500000

Persist those lines in /etc/sysctl.d/99-vagus.conf.

-domain must be a DNS suffix with no port, spaces, colons, slashes, or *. Trailing dots are stripped and matching is case-insensitive.

Binary and systemd

On a systemd host, let engram follow install vagus and keep it current. It is a service that watches one of vagus's channels on pkg.neuroplast.io (stable for releases, dev for every commit of main) and, for each newer build:

  1. checks the build's signed manifest against the pinned release key, and that it is newer than the installed one;
  2. installs it into /var/lib/engram/<name>/builds/<commit>/, points /var/lib/engram/<name>/bin at it, and keeps the build before;
  3. runs systemctl restart on vagus's unit, which waits for the relay to drain;
  4. checks that the unit is active and that its main process holds the sockets the config lists;
  5. if it isn't, puts the build before back and refuses the new one for good.

Install engram as root, pinning the same release key that signs vagus:

signer='release@neuroplast.io namespaces="engram" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCsEZcn1tiubvKQzEVs5pJ4QVXoFmSDtO+k6SdetUdf'
curl -fsS https://pkg.neuroplast.io/engram/install.sh | ENGRAM_SIGNERS="$signer" sh -s -- engram /usr/local/bin

Each program engram follows has a config, named for its follower (engram-follow@<name>). One keeps engram itself on its stable channel, so the follower updates itself:

# engram.conf
url = https://pkg.neuroplast.io
project = engram
channel = stable
signer = release@neuroplast.io namespaces="engram" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCsEZcn1tiubvKQzEVs5pJ4QVXoFmSDtO+k6SdetUdf
self = true

The relay's and the connector's configs are below, beside their units. Install the unit first and enable it without starting it: the follower's first restart starts it on the first build. Then, as root:

engram follow install engram.conf
engram follow install vagus.conf
journalctl -u engram-follow@vagus     # one line per decision
/var/lib/engram/vagus/bin/vagus version

engram's README has the other keys (delay, pause, interval) and commands (rollback, allow, check). To install one build by hand instead, with no updates, run curl -fsSL https://vagus.neuroplast.io/install.sh | sudo VAGUS_BINDIR=/usr/local/bin sh (see Install) and use /usr/local/bin/vagus in ExecStart.

Relay unit

Requires systemd 250+ for LoadCredential. The follower's config, vagus.conf, names the unit and every socket the relay listens on (-public, -control and -https below), and waits for the certificate before it installs anything:

# vagus.conf
url = https://pkg.neuroplast.io
project = vagus
channel = stable
signer = release@neuroplast.io namespaces="engram" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCsEZcn1tiubvKQzEVs5pJ4QVXoFmSDtO+k6SdetUdf
unit = vagus-relay.service
listen = tcp:443 udp:443 udp:19451
require = /etc/letsencrypt/live/control.relay.example.com/fullchain.pem

Create /etc/systemd/system/vagus-relay.service, set GOMEMLIMIT to the RAM available to the relay process, and run systemctl daemon-reload && systemctl enable vagus-relay.service:

[Unit]
Description=vagus relay
After=network-online.target
Wants=network-online.target

[Service]
Environment=GOMEMLIMIT=160MiB
ExecStart=/var/lib/engram/vagus/bin/vagus relay \
  -public 0.0.0.0:443 \
  -control 0.0.0.0:19451 \
  -https 0.0.0.0:443 \
  -domain relay.example.com \
  -cert %d/control.pem \
  -key %d/control.key
LoadCredential=control.pem:/etc/letsencrypt/live/control.relay.example.com/fullchain.pem
LoadCredential=control.key:/etc/letsencrypt/live/control.relay.example.com/privkey.pem
DynamicUser=yes
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
Restart=on-failure
# A restart drains: SIGINT, then up to -drain-timeout (1h) plus a margin.
KillSignal=SIGINT
TimeoutStopSec=65min
RestartSec=2s

[Install]
WantedBy=multi-user.target

With certbot, add a deploy hook at /etc/letsencrypt/renewal-hooks/deploy/vagus-relay running systemctl try-restart vagus-relay.service.

Connector unit

Create /etc/vagus/endpoint.pem with any vagus build (vagus keygen -out /etc/vagus/endpoint.pem, for example from the by-hand install above), create the vagus system user, and add your service user to the vagus group (sudo usermod -aG vagus your-service-user). The connector's follower config, vagus-connect.conf, lists no sockets, because the connector only dials out. It waits for the key. Its delay holds each build until the relay, on the same channel, has had time to install it and finish draining: longer than the relay's -drain-timeout plus the follower's 5-minute interval.

# vagus-connect.conf
url = https://pkg.neuroplast.io
project = vagus
channel = stable
signer = release@neuroplast.io namespaces="engram" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCsEZcn1tiubvKQzEVs5pJ4QVXoFmSDtO+k6SdetUdf
unit = vagus-connect.service
require = /etc/vagus/endpoint.pem
delay = 90m

Install /etc/systemd/system/vagus-connect.service, run systemctl daemon-reload && systemctl enable vagus-connect.service, then engram follow install vagus-connect.conf:

[Unit]
Description=vagus connector
After=network-online.target
Wants=network-online.target
StartLimitIntervalSec=0

[Service]
ExecStart=/var/lib/engram/vagus-connect/bin/vagus connect \
  -relay control.relay.example.com:19451 \
  -identity %d/endpoint.pem \
  -backend 127.0.0.1:4443 \
  -leaf-dir ${STATE_DIRECTORY}
LoadCredential=endpoint.pem:/etc/vagus/endpoint.pem
User=vagus
Group=vagus
StateDirectory=vagus
StateDirectoryMode=0750
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
Restart=always
RestartSec=2s
# Stop if another connector with the same identity key took over the route.
RestartPreventExitStatus=3

[Install]
WantedBy=multi-user.target

The connector writes cert.pem, key.pem (0640), and keyring.msgp (0600) into /var/lib/vagus. Configure your service to serve cert.pem and key.pem and reload when cert.pem changes.

CLI reference

All subcommands accept -h and shut down cleanly on SIGINT or SIGTERM. For vagus handoff, see Native handoff.

vagus relay

Flag Default Description
-public 127.0.0.1:19452 Public client UDP listen address
-control 127.0.0.1:19451 Connector control UDP listen address
-domain (required) Routing DNS suffix (no port)
-cert (required) Relay TLS certificate PEM (for -control, -https, and -admission)
-key (required) Relay TLS private key PEM
-https (disabled) HTTPS TCP listen address serving /v1/statements/<route-id>, plus admission, handoff, and WebSocket sessions when enabled
-native-handoff false Enable native handoff on -https
-admission (disabled) HTTPS TCP listen address for browser admission only (requires -allow-origins; mutually exclusive with -https)
-allow-origins (disabled) Comma-separated exact page origins allowed to request admission tickets
-admission-rate 0 (30) Admission attempts per minute per IPv4 address or IPv6 /64
-max-connectors 0 (1,024) Maximum concurrent connectors
-max-routes 0 (1,024) Maximum concurrent public QUIC client routes across all connectors
-max-sessions 0 (4,096) Maximum concurrent browser WebSocket sessions
-drain-timeout 1h Maximum time to wait for client routes and sessions to drain or go idle on SIGINT or SIGTERM (0 exits immediately)
-drain-idle 10s Quiet period with no bytes in either direction after which open routes and sessions count as idle during a drain
-disable-per-source-limits false Lift per-IP/per-key rate and concurrency limits while keeping relay-wide caps; for load testing only (requires -https or -admission; never use on a public relay)
-turnstile-secret-file (optional) Path to Cloudflare Turnstile secret file
-debug false Log debug counts: Initials dropped for missing tickets (at most every 10s), failed connector admissions, and dropped return datagrams (no client IPs)

Setting -allow-origins makes routing ticket-only for every client; unticketed dials to <route-id>.<domain> are dropped silently. See Browser admission.

vagus connect

Dials the relay control port (15-second timeout), completes Ed25519 admission, prints admitted <route-id> to stderr, and forwards UDP datagrams to -backend.

Flag Default Description
-relay (required) Relay control hostname:port or ip:port
-identity (required) Path to Ed25519 PKCS#8 PEM identity key
-backend (required) Concrete local service UDP host:port (non-unspecified IP, non-zero port)
-ca (system roots) Custom PEM root certificate replacing system roots for control TLS
-mode stream Control link framing mode: stream or datagram
-leaf-dir (none: warns) Directory for pinned leaf certificates (cert.pem, key.pem, keyring.msgp), checked hourly for rotation and published to the relay. Without it, clients cannot pin the route

vagus keygen and vagus bootstrap

  • vagus keygen -out PATH creates a new Ed25519 PKCS#8 PEM file (0600), refuses to overwrite an existing file, and prints the route ID to stdout.
  • vagus bootstrap -dir DIR creates a new 0700 directory (failing if it already exists) with endpoint.pem (0600) and a 7-day self-signed control.key (0600) and control.pem (0644, CA:TRUE) for localhost, 127.0.0.1, and ::1, and prints the route ID. For local development only.

vagus version

Prints the build's name and commit, then the Go version and os/arch; -version and --version do the same. Builds are named by date: a stable release prints vagus 26.12.04 (<commit>), a development build vagus 26.12.04-dev.0123456 (<commit>), and a build from source its short commit and (local build).

Framing modes

Select the control link framing mode on vagus connect with -mode:

Aspect -mode stream (default) -mode datagram
Outer transport Single bidirectional QUIC stream Unreliable QUIC DATAGRAM frames
Inner packet MTU Segments across outer packets; supports inner UDP payloads up to 65,531 bytes Inner packet + 4-byte return-route ID must fit inside the outer datagram capacity (fixed 1,452-byte outer UDP payload)
Oversized packets Forwarded reliably Dropped with a one-time warning (packet exceeds held datagram capacity)
Head-of-line blocking Outer loss stalls the stream until retransmitted, affecting all routes on that connector None across routes; inner QUIC handles recovery
Write stalls 5-second write deadline closes the control link on stall One DATAGRAM frame per packet

Start with -mode stream. Switch to -mode datagram only if you have verified that your service and clients keep inner QUIC datagrams below the outer datagram payload cap (PMTUD is disabled on the control link at 1,452 bytes).

Supervision, failover, and upgrades

vagus connect has no built-in reconnect loop. On control-link loss or fatal write error it exits non-zero, and the relay removes its registration and active routes. Run both processes under Docker Compose (restart: unless-stopped), systemd, or another supervisor.

If a new connector proves possession of an identity key already registered on the relay, the relay reassigns the route to the new link and closes the old link with application error 4. Restarted connectors recover immediately without waiting for timeouts. If the displaced vagus connect process is still running, it exits with status 3 (another connector with this route's key took the route over). Set RestartPreventExitStatus=3 in systemd so two connectors sharing one key do not repeatedly displace each other.

Each relay instance needs its own domain, DNS records, and non-wildcard certificate. Do not load-balance multiple relays behind one hostname: routes, tickets, statements, and handoff invitations exist only in process memory, so splitting traffic across instances breaks them. For failover, run a second relay under a separate domain (such as relay-b.example.com) and attach a second connector with the same identity key. Both relays serve the same route ID and pin, and clients can fail over between domains. Relays do not mesh.

A new build may change the wire protocol, and a relay and a connector on either side of the change can't talk, so upgrade them together: keep them on the same channel, relay first. The connector's delay above waits for the relay. A connector build that comes up before its relay has moved can't connect and exits, so its follower may refuse that build; engram follow allow takes it off the list. On the first SIGINT or SIGTERM, vagus relay starts a drain while continuing to admit and serve connections, then exits 0 once no client routes or browser sessions remain open, every open one has been silent in both directions for -drain-idle (default 10s), or -drain-timeout (default 1h) elapses. Connectors do not keep a drain open. A second SIGINT or SIGTERM exits immediately, and vagus connect exits immediately on the first signal. In systemd, set KillSignal=SIGINT and TimeoutStopSec=65min (more than -drain-timeout) on the relay unit so restarts wait for the drain, including the follower's: it waits as long as the restart takes, and its health check starts when the restart returns.

Incident recovery

Lost relay host

The relay stores no irreplaceable state. Provision a replacement host, point DNS (or reassign a static IP) to it, and restore any Turnstile secret from your secret store. Connectors reconnect automatically with their existing identity keys, reclaim the same route IDs, and republish their statements. Active relayed sessions drop during the outage and pending native handoff invitations must be reissued; direct peer-to-peer connections outside the relay continue unaffected.

Leaked relay credentials

A relay host stores its TLS key and certificate, its ACME account key (/etc/letsencrypt), and any Turnstile secret, never connector identity keys, leaf keys, or application data. See Threat 8 for impact analysis.

To recover:

  1. Revoke and reissue the relay certificate with a fresh key (certbot revoke then certbot certonly).
  2. Deactivate the compromised ACME account (certbot unregister), register a new one, and update your CAA accounturi.
  3. Rotate the Turnstile secret in Cloudflare and update the relay's secret file.
  4. Restart the relay. Connectors and clients need no changes.

Built-in limits

-max-connectors, -max-routes, and -max-sessions configure the three relay-wide limits (relay.Limits in Go); the remaining constants are compiled into pkg/connector/protocol and pkg/relay.

Limit Default / Value Behavior when exceeded
Registered connectors 1,024 (-max-connectors) New admissions rejected with ErrRelayFull (application error 3)
Active QUIC routes, relay-wide 1,024 (-max-routes) New client Initials dropped until routes expire
Active QUIC routes, per connector 1,024 (MaxRoutes) New per-client backend sockets dropped until routes expire (raising -max-routes above 1,024 helps only with multiple connectors)
Idle route timeout 2 minutes (RouteLifetime) Idle routes evicted (relay sweeps every 250 ms; connector closes idle backend sockets via read deadlines)
Pending Initial handshakes 128 total (4 per IPv4 or IPv6 /64), 3s TTL Excess incomplete multi-packet Initial flights dropped
Multi-packet Initial flight 8 packets, 16 KiB CRYPTO data Oversized, conflicting-overlap, or malformed flights discarded
Per-connector outbound queue 128 packets Excess packets dropped so one slow connector does not stall others
Control admission timeout 10 seconds Unauthenticated control links closed
Control link keepalive 10 seconds Maintains NAT mappings and detects dead peers
Browser WebSocket sessions 4,096 total (-max-sessions), 16 per IPv4 or IPv6 /64, 256 per connector, 60 attempts/min per source, 128 KiB max message, 2 min idle timeout Excess upgrades get HTTP 429 (Retry-After: 60 on rate limit); oversized messages close with status 1009; idle sessions close (live peers ping every 30s)
Embedded connector session queue 16 handshaken, 16 handshaking (10s deadline) Session closed with code 0x42 or stream refused
Control link UDP payload 1,452 bytes (PMTUD disabled) Fixed outer packet size (requires path MTU ≥ 1,500 on IPv6 or ≥ 1,480 on IPv4)

Memory and capacity

On small VMs, RAM usually runs out before the numeric caps above. Set GOMEMLIMIT in the relay's environment to the memory budget available to the relay process (after subtracting OS and other services, not the VM's total RAM).

When GOMEMLIMIT is set, vagus relay checks its live heap plus goroutine stacks (memory_bytes) once a second. At 80% of GOMEMLIMIT, it logs relay overloaded (WARN) and rejects new work: new connectors get ErrRelayFull, new QUIC Initials are dropped, and new ticket or WebSocket requests get HTTP 503 with Retry-After: 60. Existing connections continue uninterrupted, and refused tickets are not consumed. Once usage falls below 70%, it logs relay no longer overloaded and resumes accepting new work. Without GOMEMLIMIT, the relay logs a startup warning and disables overload shedding, leaving the kernel OOM killer as the only stop.

Use the overload threshold as a backstop and size -max-sessions to stay below 80%:

-max-sessions = (0.8 × GOMEMLIMIT − baseline) / cost per session

On a relay with 20 connectors, measured memory_bytes is roughly 15 MB baseline, ~45 KB per idle WebSocket session, and ~65 KB per active full-speed session. On a 512 MB VM with GOMEMLIMIT=160MiB, (0.8 × 168 MB − 15 MB) / 45 KB works out to about 2,600 idle sessions before overload shedding engages (without shedding, the same VM reached ~3,000 idle sessions at ~153 MB RSS; see Performance).

Once a minute, vagus relay logs a relay load line (INFO) with current counts (connectors, routes, sessions), refusals since the previous minute (refused_connectors, refused_routes, refused_sessions, refused_tickets, refused_connector_sessions, refused_source, refused_overloaded), overloaded status, and memory_bytes vs memory_limit_bytes. Read your relay's actual baseline and per-session cost from these lines.

Routing constraints

Because return paths are keyed by client UDP IP:port and initial routing reads the QUIC ClientHello SNI:

  • QUIC connection migration is unsupported. If a client's IP or UDP port changes mid-connection (such as Wi-Fi to cellular or NAT rebinding), packets from the new address will not match the existing route.
  • One client UDP socket (IP:port) cannot talk to two <route-id>.<domain> services through the same relay at once.
  • Encrypted ClientHello (ECH) is unsupported because the relay requires a plaintext SNI extension in the Initial ClientHello.
  • New routes must start with a QUIC v1 or v2 Initial. Once bound, subsequent datagrams are forwarded without checking the version.

Logging

vagus connect prints admitted <route-id> on admission and fatal errors to stderr on exit, and logs a one-time WARN per control link (packet exceeds held datagram capacity) if a packet is too large in datagram mode.

vagus relay logs via log/slog and never logs client IP addresses. By default it emits periodic relay load lines, overload transitions, and relay drain lines (with counts and exit reason) at the start and end of a drain. -debug adds aggregate counts of Initials dropped for missing tickets (at most every 10s), failed connector admissions (admission failed), and undeliverable return datagrams (drop return datagram).

Starting the terminal…