Docs

Features

Lock down a server

Close every port on a Linux server to the internet, Docker's included, so it's only reachable over Underpass. Safely, with an undo and an emergency key.

A server on the internet usually has ports open that nobody outside should reach: SSH, a database, an admin panel. And if it runs Docker, the ports containers publish (-p 5432:5432) are open to the whole internet even with ufw on: Docker writes its own firewall rules, which get there before ufw's.

underpass lockdown closes all of them in one command. The server stays reachable from your devices over Underpass, and from nowhere else.

What you need

  • A Linux server with Underpass 0.8.8 or later, connected.
  • nftables (nft). Most current distributions have it; otherwise apt install nftables or dnf install nftables.
  • Another of your devices online, the one you'll SSH from. Lockdown refuses to start otherwise, since nobody could reach the server afterwards.

Turn it on

On the server:

sudo underpass lockdown on

It closes the server, then asks you to prove it still works:

Check you can still reach this server over Underpass: open a new SSH session to web-1.your-workspace.underpass.internal and run sudo underpass lockdown confirm within 5 minutes, or the lockdown is undone.

So keep your current session open, and from your own computer, SSH to the server's Underpass name or address. In that new session:

sudo underpass lockdown confirm

The confirm has to come from a session over Underpass (lockdown checks), so you know that way in works. If nobody confirms within 5 minutes, or the server restarts before then, the lockdown is undone by itself. That runs in the Underpass service, so it happens even if your SSH session dropped, and a systemd timer outside the service does it too (a little later), in case the service itself hangs.

Once confirmed, the lockdown stays, and comes back after every restart.

Keep some ports open

  • --web keeps the web ports, TCP 80 and 443, open to the internet (a website or an API).
  • --allow keeps others open: --allow 25,8443/tcp,53/udp (TCP unless you say /udp).
sudo underpass lockdown on --web --allow 25

Running lockdown on again with other choices replaces them, and asks for a new confirm. If that isn't confirmed, the server goes back to the lockdown you confirmed before (not to no lockdown at all).

What stays reachable

From the internet, only:

  • Underpass itself (its UDP port, 41642 unless you chose another, so devices connect directly). If that port was taken when Underpass started, it uses a random one, which lockdown doesn't open: devices then connect through the relay, which still works, only slower. Free the port and restart the service (sudo systemctl restart tailnetd) to connect directly again;
  • --web and --allow ports, when you chose them;
  • the error messages networks need (ICMP, and for IPv6 neighbour discovery and multicast listener messages), and DHCP, so the server keeps its address;
  • SSH from an address the emergency key opened.

Everything else is closed, Docker's published ports included (unless you allowed that port). Over Underpass, everything is reachable as before, as your access controls allow.

What keeps working: the server's own connections out, replies to them, containers' connections out and to each other, and the server as a subnet router or exit node.

The server's own bridges to containers and VMs are treated like Underpass, so containers keep reaching the server's services: Docker's docker0 and br- followed by its network's 12-character ID, and bridges named podman…, cni…, virbr… (libvirt), lxdbr… (LXD) and incusbr… (Incus), each followed by a number. Never the interface the server's default route uses, whatever its name, and not other bridges such as br0 or br-lan (a bridge to a real network). A bridge made later (a new Docker network) is let in within a minute.

ufw and firewalld

  • ufw: lockdown works alongside it. ufw still drops what it drops, so lockdown adds ufw allow in on underpass0, so traffic over Underpass gets through, and removes it when you turn lockdown off. If you turn ufw on after lockdown, lockdown adds the rule within a minute.
  • firewalld: lockdown refuses to start while firewalld runs, since firewalld rebuilds its rules on its own. Do the same with firewalld instead: put underpass0 in the trusted zone (firewall-cmd --permanent --zone=trusted --add-interface=underpass0), remove what you don't want open from the public zone, and firewall-cmd --reload. Docker's published ports still bypass firewalld's zones.

Check it

underpass lockdown status

shows whether it's on, the ports listening for everyone and whether the internet reaches them, Docker containers' published ports and whether they're blocked, the emergency key, and whether ufw is on.

The dashboard shows it on the machine's page (Lockdown), and an agent's Diagnose a machine reports it. Without lockdown, they warn when Docker exposes a port to the internet: "Docker is exposing port 5432 to the internet; your firewall doesn't block it." Turn lockdown on, or publish the port on the server only: -p 127.0.0.1:5432:5432.

From 0.8.9, the machine's page also shows Who can reach it: which ports the internet, your Underpass devices and only the server itself can reach, with lockdown on or off. See Who can reach a machine.

The emergency key

What if Underpass stops working on the server? Lockdown keeps restarting the Underpass service if it crashes, forever. And for anything else, the first lockdown on makes an emergency key, shown once:

upk_ABCDE-FGHIJ-…

with the command to use it:

underpass emergency open 203.0.113.7 --key upk_ABCDE-FGHIJ-…

Print it, or keep it in a password manager. It's shown only this once; the server keeps it in /var/lib/tailnetd/emergency.key (the service's state folder), which only root can read, and sudo underpass emergency rotate makes a new one if you lose it. From any computer with Underpass installed (no sign-in needed), the command opens SSH on the server for your IP address, for 15 minutes. Then connect over SSH as usual, by the server's public address.

  • Your IP address is signed into the knock, so the server opens SSH only if the knock comes from it: someone who captures the packet on the way can't use it from somewhere else. The command finds your public address by asking Underpass's relay (a STUN request); if it can't, give it yourself: --ip 198.51.100.4.

  • Behind carrier-grade NAT (some mobile and home connections), your outside address can change between packets. Then use --any-source: the knock opens SSH for whatever address it comes from. That's weaker: someone who captures it on the way could use it first.

  • It works only while lockdown is on. Without lockdown, SSH is as your own firewall leaves it.

  • It sends one small UDP packet to port 62201, signed with the key and good for 90 seconds, a few times over. The server hears it before its firewall drops it, so the port never answers and doesn't show as open; nothing tells you it worked, by design. Check the clock of the computer you send it from: it must be within 90 seconds of the server's.

  • The server ignores knocks for 3 minutes after the Underpass service starts (or lockdown is turned on), so a knock captured before a restart can't be replayed after it. If the server just restarted, wait a few minutes.

  • Knocking again while SSH is open starts the 15 minutes again.

  • Each use goes in the audit log ("opened SSH with its emergency key") and the workspace owner gets an email, as soon as the server can reach Underpass. If that wasn't you, make a new key: sudo underpass emergency rotate (the old one stops working).

  • SSH's port comes from /etc/ssh/sshd_config (Port), 22 otherwise.

The last resort

The key is heard by a small separate program, underpass-rescue, so it works even when the main Underpass service is stuck or stopped (sudo underpass lockdown status shows it as Rescue listener: active). If even that isn't running, nothing hears the key. Then use your hosting provider's emergency console (Hetzner, DigitalOcean, AWS and others have one in their web dashboard, often called "console" or "serial console"), sign in there, and run sudo underpass lockdown off.

Turn it off

sudo underpass lockdown off

The server's ports are as your own firewall leaves them again. Uninstalling Underpass turns lockdown off too.

While lockdown is on, underpass down and underpass logout need sudo too: they'd cut the server off.

If Underpass stops on a server

A locked-down server depends on Underpass, so Underpass looks after itself there (on every device, see When something goes wrong):

  • It restarts if it gets stuck. systemd restarts the service if it stops answering for two minutes, and however often it crashes.
  • The emergency key doesn't need the service. A separate small program listens for it, with no network access beyond hearing the knock, and opens SSH by itself. The service tells Underpass about it (and the owner gets the email) once it's back.
  • It repairs a stale connection. If the coordination server stops answering, or no device has been reachable for 10 minutes while some are online, it reconnects or rebuilds its tunnel by itself. underpass status says when it last did.
  • Your devices still reach it when the coordination server is down, even after a restart: it uses the device list it saved last until the server answers again.
  • You get an email if it goes quiet. When a locked-down server hasn't checked in for 10 minutes, the workspace owner gets one email with the command for its emergency key, and another when it's back.

If none of that brings it back, use the emergency key, then the last resort.