Skip to content
FlyCockpit
Tunnel/ Server Setup & Domains
Tunnel logo

Server Setup, Domains & Accounts

TunnelRustMIT
Repository

Install tunnel-server in system or rootless mode, configure DNS providers and multi-user preview domains, understand config.toml, and manage web UI accounts and limits.

Platforms: Linux (server & client) · macOS (client)

tunnel-server setup is an idempotent install and reconfiguration wizard. Re-running it keeps existing values as defaults, preserves generated secrets, rewrites files only when changed, and restarts the service only when needed.

System vs Rootless Install

Running tunnel-server setup as root (via sudo) performs a system install; running it as an ordinary user performs a rootless install.

Aspect System install (sudo) Rootless install (unprivileged user)
Binary location /usr/local/bin/tunnel-server ~/.local/bin/tunnel-server
Config file /etc/tunnel-server/config.toml (root:tunnel-server, 0640) $XDG_CONFIG_HOME/tunnel-server/config.toml (default ~/.config/tunnel-server/config.toml, 0600)
Data directory /var/lib/tunnel (required path as root) $XDG_DATA_HOME/tunnel (default ~/.local/share/tunnel)
Service unit System systemd unit tunnel-server.service (NoNewPrivileges, ProtectSystem=strict) User systemd unit under $XDG_CONFIG_HOME/systemd/user/tunnel-server.service
Host firewall Configures active ufw or firewalld automatically Prints the required firewall rules for you to apply
Root privileges Needed for setup and admin commands One-time sudo sh -c '...' preflight (unprivileged ports from 80, systemd lingering); zero root thereafter

Setup refuses to take over unrelated system resources: it will not reuse an existing tunnel-server user unless it is a no-login account with home /var/lib/tunnel, nor an existing tunnel-server.service whose ExecStart is not tunnel-server.

Interactive and Non-Interactive Setup

For scripted deployments, pass --yes (-y) along with the required flags:

# Single-user setup on one hostname (API/tunnel on tunnel.example.com, UI on tunnel-ui.example.com, previews on *.tunnel.example.com)
tunnel-server setup --yes \
  --host tunnel.example.com \
  --email you@example.com \
  --dns-provider cloudflare \
  --dns-token-file ~/cf-token \
  --frame-ancestors 'none' \
  --webrtc true
# Multi-user setup with a separate preview domain at another DNS provider
tunnel-server setup --yes \
  --host tunnel.example.com \
  --email you@example.com \
  --dns-provider cloudflare \
  --dns-token-file ~/cf-token \
  --multi-user true \
  --preview-zone previews.example-previews.com \
  --preview-dns-provider hetzner \
  --preview-dns-zone example-previews.com \
  --preview-dns-token-file ~/hetzner-token

tunnel-server setup Flags

Flag Description
--host <fqdn> Primary server hostname (API, WSS control plane, default preview zone *.<host>, default TURN turn.<host>).
--preview-zone <fqdn> Override the wildcard preview zone (default: --host).
--turn-host <fqdn> Override the TURN hostname (default: turn.<host>).
--ui-host <fqdn|none> Web UI hostname (default: <first-label>-ui.<rest>), or none to disable the web UI. Never on or under preview_zone.
--multi-user <true|false> Enable multi-user mode; enforces that preview_zone sits on a separate registrable domain from ui_host.
--email <email> Let’s Encrypt ACME contact email.
--dns-provider <name> Primary DNS provider: cloudflare, hetzner, digitalocean, or route53.
--dns-zone <zone> Primary DNS zone at the provider (auto-detected for Cloudflare).
--dns-token-file <path> File containing the primary DNS provider API token (keeps secrets out of argv and history).
--preview-dns-provider, --preview-dns-zone, --preview-dns-token-file Separate DNS provider settings for preview_zone (stored under [[extra_dns]]).
--skip-dns Do not create DNS records automatically (you create them manually; setup still verifies resolution).
--own-certificate <true|false> Bring your own TLS certificate (certs/fullchain.pem and certs/privkey.pem inside data_dir). Server reloads replacements within 1 minute and never runs ACME.
--frame-ancestors <list> Comma-separated HTTPS sites allowed to iframe previews (https://app.example.com,https://*.example.com), * for any site, or none (default: preview’s own origin only).
--webrtc <true|false> Enable or disable the built-in STUN/TURN relay.
--staging Use Let’s Encrypt staging directory for testing without hitting production rate limits.
--skip-self-test Skip live HTTPS checks against the running service at the end of setup.
--smtp-host, --smtp-port, --smtp-user, --smtp-from, --smtp-test-to Optional SMTP setup (reads password from $SMTP_PASS, never a CLI flag).
--yes, -y Non-interactive mode; fails if any required value is missing.

DNS Providers and Custom Certificates

  • Cloudflare: Create an API token with both Zone → Zone → Read (required for zone discovery via GET /zones) and Zone → DNS → Edit for the target zone.
  • Hetzner, DigitalOcean, and Route53: Supported for both primary [dns] and secondary [[extra_dns]] zones. Each hostname automatically uses the most specific configured zone for A/AAAA records and DNS-01 ACME challenges.
  • Unsupported DNS providers: Pass --skip-dns --own-certificate true, create the DNS records setup prints, and place fullchain.pem and privkey.pem (covering api_host, tunnel_host, ui_host, turn_host, preview_zone, and *.preview_zone) into <data_dir>/certs/.

Domain Layouts: Single-User vs Multi-User

ui_host and preview_zone are independent, and tunnel-server refuses to start if ui_host equals preview_zone or sits beneath it (because untrusted preview pages would be same-origin or child origins of the dashboard).

Layout Example Recommended Use
Separate registrable domain (recommended) UI tunnel.example.com, previews *.example-previews.com Required when anyone other than you uses the server (--multi-user true).
Subdomain on a separate registrable domain UI tunnel.example.com, previews *.p.example-previews.com Multi-user when the second domain also hosts other services.
Same registrable domain UI tunnel.example.com, previews *.previews.example.com Single-user only (the Status page displays a warning).

On a single registrable domain, preview pages are still same-site with the UI: even though the UI defends against CSRF, a malicious preview could flood the shared cookie jar (signing you out), prompt browser password managers to autofill UI credentials, or spoof your brand domain. Putting previews on a separate registrable domain eliminates all three risks.

Important (Public Suffix List): Operators running public multi-tenant Tunnel servers should submit their preview_zone to the Public Suffix List (like github.io). That instructs browsers to treat every {port}-{id}.<preview_zone> host as a distinct eTLD+1 site, isolating cookies and storage between different previews.

Web UI Defenses

  • Session cookie is __Host-tunnel-ui (host-only, Secure, HttpOnly, SameSite=Strict) and is never forwarded to preview origins.
  • Every /ui/api/* request requires X-Tunnel-CSRF (forcing a CORS preflight that the server never grants), exact Origin: https://<ui_host> on writes, and Sec-Fetch-Site: same-origin when sent.
  • Pages enforce a strict CSP (script-src 'self' 'wasm-unsafe-eval', no inline scripts, frame-ancestors 'none').
  • Every HTTPS response sets Strict-Transport-Security: max-age=31536000 (without includeSubDomains).

config.toml Structure

config.toml holds server hosts, secrets (ui_secret, DNS tokens, TURN secret, optional SMTP password), listener addresses, and limits. Parse errors deliberately omit raw values so secrets never leak into system journals.

preview_zone = "previews.example-previews.com"
api_host = "tunnel.example.com"
tunnel_host = "tunnel.example.com"
turn_host = "turn.tunnel.example.com"
ui_host = "tunnel-ui.example.com"          # omit to disable web UI
ui_secret = "<at-least-32-random-chars>"   # required even without web UI
# ui_secret_previous = "<old-secret>"      # set automatically by `secret rotate`
# abuse_contact = "abuse@example.com"      # optional, shown on server pages
frame_ancestors = []                       # [] = own origin only; ["*"] = any site

listen_https = "[::]:443"
listen_http = "[::]:80"
metrics_listen = "127.0.0.1:9464"
data_dir = "/var/lib/tunnel"

admin_token_hash = "<sha256-hex>"
# health_token_hash = "<sha256-hex>"       # set via `tunnel-server health-token set`

[acme]
email = "you@example.com"
staging = false
own_certificate = false

[dns]
provider = "cloudflare"                    # cloudflare | hetzner | digitalocean | route53
zone = "example.com"
api_token = "<token>"                      # or aws_access_key_id / aws_secret_access_key / route53_hosted_zone_id

# Optional additional DNS zones (e.g. separate multi-user preview domain):
# [[extra_dns]]
# provider = "hetzner"
# zone = "example-previews.com"
# api_token = "<token>"

[webrtc]
enabled = true
static_auth_secret = "<secret>"
passthrough_no_sni = true                  # treat TLS on 443 without SNI as TURN-over-TLS
browser_ttl_s = 3600
sandbox_ttl_s = 86400
stun_port = 3478
relay_min_port = 49160
relay_max_port = 49999

[limits]
max_tunnels_per_client = 20
default_max_ports = 8
hard_max_ports = 32
access_rate_per_min = 30
default_session_ttl_s = 43200              # 12 hours
max_tunnel_ttl_s = 2592000                 # 30 days
tombstone_retention_s = 2592000            # 30 days
allow_public_for_clients = false
member_max_tunnels = 10
member_max_clients = 5
member_max_tunnel_ttl_s = 604800           # 7 days (at most max_tunnel_ttl_s)
# member_monthly_traffic_gb = 100          # unset = no monthly cap
login_rate_per_min = 10

# Optional outgoing email (configured via `tunnel-server mail setup`):
# [smtp]
# host = "smtp.example.com"
# port = 587
# user = "apikey"
# pass = "<secret>"
# from = "Tunnel <tunnel@example.com>"

Web UI Accounts, Roles, 2FA, and Limits

Roles and Onboarding

  • Owner: Single super-account created (or recovered) via tunnel-server admin link (15-minute one-time URL). Never subject to account limits. Only the owner can invite or modify admins.
  • Admin: Can invite and manage members, view all tunnels, set member limits, and issue member sign-in resets.
  • Member: Sees and manages only their own machines, tunnels, and access links within assigned limits. Cannot create public tunnels unless granted can_public by an admin or limits.allow_public_for_clients = true. Revoking can_public (or demoting an admin without it) immediately switches their existing public tunnels to link-only.

There is no open registration. Invites (https://<ui_host>/invite#<token>, 7 days by default) and sign-in resets (tunnel-server user reset <name> [--hours N], 1 hour default) carry their single-use token in the URL fragment so it never hits server access logs.

Authentication, 2FA, and Recovery

  • Passwords use Argon2id sealed with AES-256-GCM under a key derived from ui_secret (bound to row ID and purpose).
  • Optional TOTP two-factor authentication issues 10 single-use recovery codes (stored as AES-256-GCM-sealed SHA-256 digests). Five consecutive invalid codes lock 2FA for 15 minutes, doubling up to 24 hours.
  • Sign-in is rate-limited both per IP (limits.login_rate_per_min, default 10/min) and per username (3× that) before password hashing.
  • Approving or adding a machine requires re-confirming with a 2FA code (or current password if 2FA is off) whenever the last check is older than 10 minutes.
  • Accepting a sign-in reset (admin link, user reset, or mailed Forgot password) ends all sessions, revokes every machine login (tncli_), and closes all of that user’s live tunnels. (An admin/owner user reset also disables 2FA; self-service emailed Forgot password requires a 2FA/recovery code if 2FA is enabled and keeps 2FA turned on.)
  • All account, machine, tunnel, and limit changes are written to a 90-day audit log.

Per-Account Limits and Monthly Traffic Caps

Admins set four limits per member (and the owner sets them per admin). Each limit can be Server default, a custom Number, or Unlimited:

Limit Member Default Admin Default Exceeded Behavior
Live tunnels (across all machines) limits.member_max_tunnels (10) Unlimited HTTP 429 tunnel_quota on new tunnels; existing tunnels stay up.
Enrolled machines limits.member_max_clients (5) Unlimited HTTP 429 client_quota on new machines.
Longest tunnel lifetime limits.member_max_tunnel_ttl_s (7d) limits.max_tunnel_ttl_s (30d) HTTP 422 tunnel_ttl_limit; lowering shortens existing tunnels that would outlive the new cap. Unlimited permits tunnel share --ttl never.
Monthly traffic (UTC calendar month, both directions, bodies + WS) limits.member_monthly_traffic_gb (none) Unlimited Immediate HTTP 503 “Traffic limit reached” and active streams/WebSockets are cut at once. Lifted by raising the cap, admin “Reset month”, or next UTC month.

Note: Service credentials (tnsvc_) and the admin token are separate from user accounts and follow their own quotas (max_tunnels, max_tunnel_ttl_s) with no monthly traffic cap.

Server Administration CLI

tunnel-server status
tunnel-server admin link
tunnel-server user list
tunnel-server user invite [--role member|admin] [--hours 168]
tunnel-server user reset <username> [--hours 1]
tunnel-server user delete <username>
tunnel-server client add <name> [--user <username>]
tunnel-server client list
tunnel-server client rename <name> <new-name>
tunnel-server client delete <name>