Web pages from anywhere: the password gateway

Agents on the host serve web pages: Lavish boards, dev previews, and other local services. These pages listen on loopback, so you cannot open them from a phone or a laptop without help.

The password gateway is the way in for hosts that turn it on. It puts one password in front of every local web page and serves the pages over a Cloudflare Quick Tunnel. The tunnel gives an https://….trycloudflare.com address and needs no Cloudflare account, no open port, and no DNS change. Tailscale stays available as an option.

Open a page

  1. Find the address printed by the installer or ./ship.sh launch. On the host, this command prints it again:

    crewship-gateway url
    
  2. Open the address in any browser and enter the password.

  3. Open a local page as /PORT/path. For example, a Lavish board on port 9525 is https://….trycloudflare.com/9525/. A dev server such as Vite or Next.js loads its files from root paths, for example /@vite/client or /_next/static/…. The gateway sends such a path to the port of the page that asked for it. It takes the port from the Referer header, or else from the __Host-crewship-port cookie, which lasts as long as the sign-in (24 hours by default). Only a page that you open in a tab sets this cookie; the files and requests of a page never change it. The path / stays the start page unless the Referer names a port or the request opens a WebSocket. With two different dev apps of this kind open in two tabs at once, reload the tab you switch to. A root path that starts with a number, such as /2024/hello, goes to the page's own port when nothing listens on port 2024. When something listens on that port, the path goes there. The page that such a path opens can still send its own root-path files and links to the wrong port. Open such an app at a /PORT/ path: start it with a base path, for example vite --base /3000/.

After the right password, your IP address is allowed for 24 hours. The browser also gets a cookie that lasts as long. The cookie keeps a phone signed in when its mobile network changes its address.

The password

The first apply makes a random password, for example k3m9x-4tqhe-p7rwn-a2bcd. It writes the password only to ~/.config/crewship/gateway/initial-password (mode 600). The launch summary and the installer name that file. They never show the password. Read the file yourself over SSH, keep the password in your password manager, then delete the file:

cat ~/.config/crewship/gateway/initial-password

Never let an agent read, print, or relay the password. The host keeps only an scrypt hash of it, in ~/.config/crewship/gateway/password.hash (directory 700, file 600). The hash stays on this host: each host has its own password, and scripts/fetch-secrets.sh does not touch it.

To set a new password, run this in your own terminal on the host. It writes the new password to initial-password in the same way, prints only the path of that file, and signs out every address and every browser:

crewship-gateway password
cat ~/.config/crewship/gateway/initial-password

Settings

Set the allow window in hours in .local/host.yml, then run ./ship.sh launch:

crewship:
  gateway:
    allow_hours: 24    # the default; 1 to 8760

Sign out

Five wrong passwords from one address within 15 minutes lock that address out for 15 minutes. Other addresses can still sign in.

Turn it on or off

How it works

Browser requests pass through Cloudflare and the tunnel to the password gateway, which routes them to loopback web pages

The tunnel gets a new address each time it starts, for example after a reboot. Apply restarts the tunnel only when its unit file changes. Run crewship-gateway url to see the current address.

Quick Tunnel limits

Cloudflare offers Quick Tunnels for testing and development, without an uptime guarantee. A Quick Tunnel proxies at most 200 requests at the same time, and it does not support Server-Sent Events (SSE). WebSocket connections work. The gateway refuses a request body without a Content-Length (chunked upload) with 411. For a fixed address or SSE, use a named Cloudflare Tunnel on your own account, or Tailscale.

Tailscale instead

Tailscale gives a private network with a fixed name for the host. It needs a Tailscale account and a sign-in on each device.

  1. Set profiles.tailscale: true in .local/host.yml and run ./ship.sh launch. The apply installs the daemon only.

  2. Join the tailnet: sudo tailscale up.

  3. Open a local page from a device on the tailnet, for example with tailscale serve.

Security has the Tailscale details. You can use both: the gateway and Tailscale do not affect each other.

Tests