Skip to main content

Tailscale (optional, TAILSCALE=1)

Disabled by default. Runs the official tailscale/tailscale image with tailscale serve as an HTTP reverse proxy to nginx on port 4000. Access is tailnet-only, with no public exposure or port forwarding.

HTTP proxying supplies the real caller IP. nginx accepts it only from the dedicated ingress network and passes one sanitized address to LiteLLM. MCP can then distinguish tailnet callers from public callers without trusting client-supplied headers.

State is bind-mounted at ${DATA_DIR_TAILSCALE:-${DATA_DIR:-.data}/tailscale} so the node identity survives container recreates. After the first auth, the node stays logged in even if TS_AUTHKEY is rotated.

Setup (hosted Tailscale)​

  1. Generate an auth key at login.tailscale.com/admin/settings/keys (reusable + ephemeral both work).

  2. Set:

    TAILSCALE=1
    TS_AUTHKEY=tskey-auth-...
    TS_HOSTNAME=aigate
  3. make run-bg. The node joins your tailnet under TS_HOSTNAME.

  4. From any tailnet-joined device: http://aigate.tailXXXX.ts.net → aigate's nginx.

Find your tailnet name with docker compose exec tailscale tailscale status after first connect.

Setup (Headscale or other custom control server)​

Add --login-server to TS_EXTRA_ARGS:

TAILSCALE=1
TS_AUTHKEY=hskey-auth-...
TS_HOSTNAME=aigate
TS_EXTRA_ARGS=--login-server=https://your-headscale.example.com
TS_SERVE_FQDN=aigate.your-tailnet.example.com

Set TS_SERVE_FQDN to the actual node DNS name from docker compose exec tailscale tailscale status --json. Headscale determines its suffix through base_domain. Hosted Tailscale can substitute its certificate domain when the variable is unset; tailnets without a certificate domain must also set it explicitly. Use that hostname or its short MagicDNS name in requests, not the numeric IP.

Custom port​

Default HTTP port is 80 (http://<host>.<tailnet>/). Change with TS_SERVE_PORT=8080 etc.

Notes​

  • Serve uses HTTP over the WireGuard-encrypted tailnet. Browser OAuth outside localhost requires HTTPS; configure a TLS reverse proxy and set PROXY_BASE_URL to its browser-facing origin. See MCP OAuth setup.
  • The container needs NET_ADMIN, NET_RAW, and /dev/net/tun for kernel networking.
  • Forwarding sysctls (net.ipv4.ip_forward=1, net.ipv6.conf.all.forwarding=1) are set so subnet-routing and exit-node modes work if you add --advertise-routes=... or --advertise-exit-node via TS_EXTRA_ARGS.
  • Joins aigate-public for outbound connectivity and aigate-ingress to reach nginx-edge:4000. Persistent node identity and agent egress remain unchanged.

Tailnet egress for the agent containers​

tailscale serve covers the inbound direction: tailnet devices reaching aigate. The reverse, letting the agent containers reach machines on your tailnet, is off by default and turns on when TAILSCALE=1 runs alongside CLAUDEBOX=1, PIBOX_ZAI=1, or PIBOX=1. The Makefile then loads the docker-compose.tailscale.yml overlay, which routes tailnet traffic out through the existing tailscale node. Each container stays on the bridge, so nginx and LiteLLM still reach them as before.

Each enabled agent gets its own route helper, so the wiring does not depend on the Docker host being a tailnet node itself. On a host that already routes 100.64.0.0/10 the containers would reach the tailnet regardless; the overlay is what makes it work when the host does not.

With the overlay active, from inside any of those agent containers you can resolve tailnet names and connect to tailnet peers over any protocol (SSH, HTTP, whatever the peer serves), while container names and public names keep resolving as usual.

How it works:

  • The tailscale container becomes a NAT gateway for the tailnet CGNAT range. A small sidecar keeps a MASQUERADE rule on tailscale0 so replies find their way back to the bridge clients.
  • Each agent container gets a route for 100.64.0.0/10 (the range Tailscale assigns every node) pointed at the tailscale container. A per-container sidecar sharing that container's network namespace installs the route and re-adds it after a restart, since Compose has no static-route field.
  • DNS is split. Tailscale MagicDNS (100.100.100.100) answers tailnet names and returns SERVFAIL for everything else; Docker's embedded resolver falls through to a public resolver for public names and still answers sibling container names.

Two settings, both optional:

# Your tailnet's MagicDNS suffix, from `tailscale status` (hosted: tailXXXX.ts.net;
# Headscale: your base_domain). Lets the containers resolve bare tailnet names in
# addition to FQDNs. Leave unset to require fully-qualified names.
TS_MAGICDNS_SUFFIX=tailXXXX.ts.net

# Resolver for non-tailnet names, since MagicDNS only answers tailnet names.
# Defaults to 1.1.1.1; set your own to keep public DNS on your infrastructure.
TS_FALLBACK_DNS=1.1.1.1

Scope and limits:

  • Covers IPv4 tailnet peers by their 100.64.0.0/10 address or MagicDNS name. That is the complete range for node-to-node tailnet access.
  • A LAN behind a subnet router is not in 100.64.0.0/10, so it is not reached by this route. Add that subnet as a separate route if you need it.
  • IPv4 only. Tailnet IPv6 (fd7a:115c:a1e0::/48) is not routed.
  • The egress sidecars carry no-new-privileges:true and cap_drop: [ALL], adding back only NET_ADMIN (and NET_RAW on the gateway sidecar for the NAT rule).