TermlessDocs

Guides

Putting Termless on your own domain

Serve the dashboard and the API at an address such as https://termless.example.com. The DNS record, then one of Caddy, nginx, a Cloudflare Tunnel or Tailscale, the settings termlessd needs behind each, an optional sign-in in front, and how to check it worked.

termlessd speaks plain HTTP on 127.0.0.1:8780. To open it at https://termless.example.com, something in front of it must hold the certificate and pass requests on. Pick one of the four ways below; each carries the dashboard, the API and both kinds of streams. Running Termless in Docker? The first and third ways come as ready-made compose files: see Running in Docker.

WayPorts to openCertificatePick it when
Caddy80 and 443automaticthe box has a public IP address; the fewest steps
nginx80 and 443certbotnginx already runs on the box
Cloudflare TunnelnoneCloudflare'sthe box has no public address, or should stay hidden; the domain is on Cloudflare
Tailscale ServenoneTailscale'sonly your own devices should reach it (a ts.net name, not your domain)

Before you start#

  • A domain you control, and a name for Termless under it. A subdomain such as termless.example.com is the easy choice; it can live beside anything else on the domain.
  • termlessd running on the box and answering there: curl -s http://127.0.0.1:8780/api/v1/health.
  • For Caddy and nginx, the box's public address: curl -4 https://ifconfig.me on the box (and curl -6 https://ifconfig.me if it has IPv6).

What termlessd needs behind a proxy#

Behind a proxy every request arrives from the proxy, so termlessd has to be told where to find the real visitor, or its lockout (5 wrong passwords lock an address out for 15 minutes) would count everyone as one address and one stranger could lock you out.

SettingValueWhy
TERMLESS_TRUST_PROXY1Read the visitor's address from a header, and https from X-Forwarded-Proto (for the cookie's Secure flag).
TERMLESS_PROXY_HEADERX-Forwarded-For (the default) behind Caddy and nginx; CF-Connecting-IP behind a Cloudflare TunnelThe one header holding the visitor's address.
TERMLESS_LISTEN127.0.0.1:8780 (the default)Nothing but the proxy may reach the port. Otherwise anyone could connect directly and write that header themselves.
TERMLESS_TRUSTED_PROXIES127.0.0.0/8,::1 (the default)Where the proxy connects from. The default fits every way on this page when the proxy runs on the same machine; set the proxy's address if it runs elsewhere.

On a systemd install, set them with sudo systemctl edit termlessd, which opens an override file:

override.conf
[Service]
Environment=TERMLESS_TRUST_PROXY=1
Environment=TERMLESS_PROXY_HEADER=X-Forwarded-For

then sudo systemctl restart termlessd. (In Docker these are lines in .env; the Docker guide shows them.)

Caddy#

Caddy gets and renews the certificate by itself.

  1. DNS. Add an A record: name termless, value the box's IPv4 address. Add an AAAA record with its IPv6 address if it has one. On Cloudflare, set the record to DNS only (grey cloud); the reason is below.
  2. Open ports 80 and 443 in the box's firewall (for example sudo ufw allow 80,443/tcp) and in the cloud provider's firewall, which is separate (a security group or security list in its console). Caddy needs port 80 to prove the domain and 443 to serve it.
  3. Install Caddy from caddyserver.com/docs/install (Debian and Ubuntu have a package repository there).
  4. Add the site to /etc/caddy/Caddyfile:
Caddyfile
termless.example.com {
    reverse_proxy 127.0.0.1:8780 {
        # Overwrite whatever the caller sent with the address Caddy sees.
        header_up X-Forwarded-For {remote_host}
    }
}
  1. sudo systemctl reload caddy, then set TERMLESS_TRUST_PROXY=1 as above.

The certificate arrives on the first request, within a few seconds. Caddy passes streams through as they are written, so SSE and WebSocket need nothing more. If it fails, journalctl -u caddy -n 50 says why; the usual cause is port 80 closed in the provider's firewall, or the DNS record not pointing at the box yet (dig +short termless.example.com).

nginx#

  1. Steps 1 and 2 of Caddy: the DNS record and ports 80 and 443.
  2. Add the site, for example /etc/nginx/sites-available/termless (linked into sites-enabled):
termless.conf
server {
    listen 80;
    server_name termless.example.com;

    location / {
        proxy_pass http://127.0.0.1:8780;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_buffering off;
        proxy_read_timeout 1h;
    }
}

$connection_upgrade comes from this map, once, in the http block of /etc/nginx/nginx.conf:

nginx.conf
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
  1. sudo nginx -t && sudo systemctl reload nginx.
  2. Get the certificate: sudo certbot --nginx -d termless.example.com (install certbot from certbot.eff.org). Certbot adds the listen 443 ssl lines and renews the certificate on its own; when it asks, choose to redirect http to https. Until this step is done the site is plain http: do not sign in or send a key over it.
  3. Set TERMLESS_TRUST_PROXY=1 as above.

X-Forwarded-For $remote_addr replaces whatever the caller sent, which is what the trust setting relies on. proxy_buffering off and the long read timeout keep streams flowing; termlessd also sends X-Accel-Buffering: no on them.

Cloudflare Tunnel#

cloudflared on the box opens a connection out to Cloudflare, and Cloudflare serves your hostname over it with its own certificate. No port is opened, and the box's address never appears in DNS. The domain must use Cloudflare's nameservers.

  1. In the Cloudflare dashboard: Zero Trust > Networks > Tunnels > Create a tunnel, type Cloudflared, give it a name.
  2. Install the connector on the box with the command the page shows for your system (it looks like sudo cloudflared service install <token>). The page shows the connector as healthy once it runs.
  3. Add a public hostname: subdomain termless, domain example.com, service type HTTP, URL 127.0.0.1:8780 (in Docker, termless:8780). Cloudflare creates the DNS record itself.
  4. Tell termlessd where Cloudflare puts the visitor's address:
override.conf
[Service]
Environment=TERMLESS_TRUST_PROXY=1
Environment=TERMLESS_PROXY_HEADER=CF-Connecting-IP
Environment=TERMLESS_COOKIE_SECURE=1

then sudo systemctl restart termlessd. Cloudflare writes CF-Connecting-IP on every request itself, so a visitor cannot choose it, and the cookie is always Secure because every visitor arrives over https.

Tailscale Serve#

For a Termless only you use: Tailscale gives the box an https address that only devices signed in to your tailnet can open, such as https://my-box.tail1234.ts.net. It is Tailscale's name, not your domain.

  1. Install Tailscale on the box and on your devices, signed in to the same tailnet.
  2. In Tailscale's admin console, under DNS, turn on MagicDNS and HTTPS Certificates.
  3. On the box: sudo tailscale serve --bg 8780. It prints the address. sudo tailscale serve status shows it again; sudo tailscale serve reset undoes it.

termlessd needs no trust setting here: every visitor reaches it from 127.0.0.1, so the lockouts count your whole tailnet as one address, which is fine when only your own devices can connect. Add TERMLESS_COOKIE_SECURE=1 if you only ever open it over that https address. Tailscale's own guide: tailscale.com/kb/1312/serve.

A sign-in in front (optional)#

With the hostname on Cloudflare (a Tunnel, or a proxied record), Cloudflare Access can ask for a one-time code sent to your email before the Termless page even loads, so the password page is not open to the internet at all.

  1. Zero Trust > Access > Applications > Add an application > Self-hosted, application domain termless.example.com.
  2. Add a policy: action Allow, include Emails, with your address (and anyone else's who should get in).
  3. If programs outside your network call the API, give them a service token rather than opening a path: Zero Trust > Access > Service credentials > Service Tokens > Create, then add a second policy to the same application with action Service Auth that includes that token. Each program then sends two more headers with every request, beside its Termless key:
curl
curl -s "https://termless.example.com/api/v1/accounts" \
  -H "Authorization: Bearer $TERMLESS_KEY" \
  -H "CF-Access-Client-Id: $CF_ACCESS_CLIENT_ID" \
  -H "CF-Access-Client-Secret: $CF_ACCESS_CLIENT_SECRET"

Do not make a Bypass for api/: the dashboard signs in through /api/v1/session, so a bypass would put the password check back on the open internet.

Why not Cloudflare's orange cloud?#

With Cloudflare's proxy turned on for a record that points at your box, every request reaches Caddy or nginx from a Cloudflare address. The last hop of X-Forwarded-For is then Cloudflare, not the visitor, so all visitors share a handful of addresses and one person's wrong passwords lock everyone out. Reading CF-Connecting-IP instead fixes that only if the box refuses every connection that does not come from Cloudflare; otherwise anyone who learns the box's address can send that header themselves. A Cloudflare Tunnel gives you Cloudflare in front without either problem.

Check it worked#

From any computer:

curl
curl -s https://termless.example.com/api/v1/health
# {"accounts":[],"status":"ok",...}
curl -s -o /dev/null -w '%{http_code}\n' https://termless.example.com/api/v1/accounts
# 401: nothing is readable without a key or a session
curl -s --max-time 5 http://<the box's address>:8780/api/v1/health || echo "closed, good"
# the port itself must not answer from outside

Then sign in to the dashboard and open Activity: the signin row must show your own public address (curl -4 https://ifconfig.me on your computer). If it shows 127.0.0.1, TERMLESS_TRUST_PROXY is not on (expected only with Tailscale Serve). If it shows an address of the proxy or of Cloudflare, the proxy header is the wrong one for your setup.

Before you open it to the internet#

  • A long admin password that you do not use anywhere else (15 to 200 characters with a lowercase letter, a capital, a digit and a symbol). openssl rand -base64 18 makes one; check it has all four kinds. Change it in the dashboard: the account menu at the bottom of the sidebar, Change password.
  • One API key per app, with the narrowest scope (read unless it trades) and only the accounts it needs, so one leaked key is revoked without touching the rest.
  • Port 8780 closed to the internet (check above).
  • Look at Activity now and then for auth_failed and lockout rows.
  • Consider a sign-in in front, above all for accounts with real money.