PortGate

Blueprints · Server Hardening

Zero-Trust 20 min · cloudflared

Cloudflare Tunnel zero-open-port ingress

Publishes a local app through an outbound cloudflared tunnel. Removing public firewall allows is a separate script and does not run until the tunnel is active. SSH is removed only when you set CLOSE_SSH to yes.

Live config

Baked-in protections

Step 1 · bash

Install and start cloudflared

/root/portgate-blueprints/cloudflared-install.sh

Use a remotely managed tunnel token from Cloudflare. The local service is the app port.

#!/bin/sh
set -eu
if ! command -v cloudflared >/dev/null 2>&1; then
  curl -fsSL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
  chmod 755 /usr/local/bin/cloudflared
fi
cloudflared service install "paste-from-cloudflare"
systemctl enable --now cloudflared

Step 2 · yaml

Ingress config

/etc/cloudflared/config.yml

Use this file for a locally managed tunnel. A token install ignores it.

ingress:
  - hostname: app.example.com
    service: http://127.0.0.1:8080
  - service: http_status:404

Step 3 · bash

Close public allows after the tunnel works

/root/portgate-blueprints/cloudflared-close-ports.sh

Not run by the bundle. Confirm a second session through the tunnel before you run it. CLOSE_SSH defaults to no.

#!/bin/sh
set -eu
systemctl is-active --quiet cloudflared
ufw delete allow 80/tcp || true
ufw delete allow 443/tcp || true
if [ "no" = "yes" ]; then
  echo "Removing the SSH allow. You need a working tunnel or VPN session first."
  ufw delete allow 22/tcp || true
else
  echo "SSH allow was left in place. Set CLOSE_SSH=yes only after another admin path works."
fi