Guides

Put a self-hosted admin UI behind Cloudflare Tunnel and Access

Keep an admin panel off the public internet: no open port, and Cloudflare checks who you are before the login page loads. Works for any self-hosted UI, with Echowa as the example.

Updated

An admin UI on the public internet gets password-guessing traffic from the day it goes up, whether it's a deploy tool, a database console or a dashboard. Limiting it to your own IP address breaks the first time you work from somewhere else. Cloudflare Tunnel and Cloudflare Access fix both: the server opens no port for the UI, and Cloudflare checks who you are before a single request reaches it.

How it fits together

cloudflared runs on your server and makes an outbound connection to Cloudflare. Requests for your hostname reach Cloudflare's edge first, where Access asks the visitor to sign in. Only signed-in visitors on your allow list are passed down the tunnel to the UI on localhost. Nothing on the server listens publicly for the UI, so there's no port to scan or attack directly.

What you need

  • A domain on Cloudflare, as an active zone in your account.
  • Cloudflare Zero Trust set up on the account. Cloudflare has a free plan.
  • The admin UI running on the server, listening on 127.0.0.1.

1. Bind the UI to localhost

The tunnel only helps if the UI can't be reached any other way. If it listens on 0.0.0.0, anyone who finds the server's address can skip Access entirely. The following command lists listening sockets and the programs behind them:

sudo ss -ltnp

The UI's line should show 127.0.0.1:<port>, not 0.0.0.0:<port> or *:<port>. For a container, publish the port on loopback only, as in -p 127.0.0.1:3000:3000. Docker writes its own firewall rules for published ports, so a ufw rule won't close a port Docker has published to everyone.

2. Create the Access application first

Cloudflare's docs warn that a published application without an Access application in front of it is available to anyone on the internet. So set up Access before the tunnel:

  1. In the Cloudflare dashboard, go to Zero Trust, Access controls, Applications, and choose Create new application, then Self-hosted and private.
  2. Choose Add public hostname and enter the hostname you'll use, such as admin.example.com.
  3. Add a policy with the action Allow, and include the Emails selector with your own address. Only visitors who match an Allow policy get in.
  4. Choose how people sign in. Without an identity provider, Cloudflare emails a one-time code. Adding GitHub or Google makes it one click. A longer session duration means you sign in less often.
  5. Choose Create.

3. Create the tunnel

  1. Go to Networking, Tunnels, choose Create a tunnel, and give it a name.
  2. Pick your server's operating system, and run the install command Cloudflare shows on the server. On Debian and Ubuntu, it installs cloudflared from Cloudflare's repository and runs sudo cloudflared service install <token>.
  3. When the tunnel shows as connected, choose Continue.

The long token in that command lets whoever has it run your tunnel. Treat it like a password.

4. Route the hostname to the UI

Open the tunnel, go to its Routes tab, choose Add route, then Published application. Set the subdomain and domain to the hostname from step 2, and Service URL to the UI's local address, such as http://localhost:3000. Cloudflare creates the DNS record for you.

Open the hostname in a browser. Cloudflare's sign-in comes first, and the UI's own login after it. If the browser says the server can't be found right after you add the route, your network has cached the failed lookup from before the record existed. A phone on mobile data shows the page straight away.

5. Harden it

Keep the token out of the unit file

cloudflared service install <token> writes the token into the systemd unit's command line, where local users can read it in the unit file and in ps. From cloudflared 2025.4.0, --token-file reads it from a file instead. The following commands store the token in a file only root can read:

sudo mkdir -p /etc/cloudflared
sudo install -m 600 /dev/null /etc/cloudflared/tunnel-token
sudo nano /etc/cloudflared/tunnel-token
systemctl cat cloudflared

Paste the token into the file and save it. Then copy the ExecStart line that systemctl cat prints, run sudo systemctl edit cloudflared, and add an override that repeats it with --token-file in place of --token <token>. The empty ExecStart= clears the original:

/etc/systemd/system/cloudflared.service.d/override.conf
[Service]
ExecStart=
ExecStart=/usr/bin/cloudflared --no-autoupdate tunnel run --token-file /etc/cloudflared/tunnel-token

Use the binary path and options from your own ExecStart line, then run sudo systemctl restart cloudflared and check the tunnel still shows as healthy in the dashboard.

Use the real client address

Every request now arrives from cloudflared on loopback, so to the UI every visitor has the same address. Cloudflare sends the visitor's address in the CF-Connecting-IP header. If the UI limits login attempts per address, have it read that header, and only on requests from loopback, so nobody else can set it.

Check the Access token in the app

Access adds a signed token to every request it lets through, in the Cf-Access-Jwt-Assertion header. An app that checks it refuses any request that didn't come through Access, even if someone later adds a route without an Access application. Check the signature against the keys at https://<your-team-name>.cloudflareaccess.com/cdn-cgi/access/certs, and that the token's aud matches the application's Audience tag, which is under the application's Additional settings.

Give machines their own way in

A CI webhook or an API client can't complete an Access sign-in. Don't add a Bypass policy to the UI's hostname for it: Bypass enforces no Access controls and isn't logged. Use a separate hostname for the machine endpoint, ideally with a Service Auth policy and a service token.

With Echowa

Echowa, a self-hosted deploy tool for one server, offers this as one of three ways to reach its UI, and the safest. Choose Cloudflare Tunnel when the installer asks, or pass the token as a flag:

curl -fsSL https://get.echowa.dev/install.sh | sudo bash -s -- --access tunnel --tunnel-token <token>

The installer installs cloudflared from Cloudflare's repository and runs the service install with your token. Echowa listens on 127.0.0.1:3000, and trusts CF-Connecting-IP only on requests from loopback, so its login limit applies to each real visitor. Create the Access application first, as in step 2, then route the hostname to http://127.0.0.1:3000.

Because the UI stays on loopback, an SSH tunnel or Tailscale also works alongside it. The installer uses cloudflared service install <token> today, so apply the token-file step above after installing. The install guide covers the other two ways to reach the UI, and how to switch between them.