fix(workspace): LAN exposure via host firewall — the Supabase CLI forces 0.0.0.0, so PostgreSQL / Studio / raw Mailpit close by UFW rules on the LAN interface; gateway reduced to Mailpit behind basic auth on 54325

Owner run: the CLI prints 'All services bind to 0.0.0.0' and ignored the
rootless daemon's default address; the gateway could not share 54321/54324
with 0.0.0.0 listeners. Now: Kong serves the API directly; the DEV gateway
serves only Mailpit with basic auth on <DEV host>:54325; ENVIRONMENTS.md §3
gives the exact UFW rules (interface-scoped deny on 54322-54324, two cases
by current UFW state), rollback and impact; dev:net-check proves the
allowed surfaces from a distinct Docker network (5/5 OK) and prints the
refusal checks to run from another device, since a rootless container's
traffic to the host is delivered locally and cannot see the LAN firewall.
LRN-053 corrects LRN-052.
This commit is contained in:
bchanot committed 2026-10-13 23:01:19 +02:00
1 parent a8edd59059
commit e633169a00
11 files changed
+143 -111

No files matched your search

+2 -1
View File
@@ -23,4 +23,5 @@ export FAUNOSTEO_DEV_API_ORIGIN="http://$FAUNOSTEO_DEV_HOST"
export FAUNOSTEO_DEV_API_URL="http://$FAUNOSTEO_DEV_HOST:54321"
export FAUNOSTEO_DEV_SITE_URL="http://$FAUNOSTEO_DEV_HOST:5173"
export FAUNOSTEO_DEV_STUDIO_URL="http://$FAUNOSTEO_DEV_HOST:54323"
export FAUNOSTEO_DEV_MAILPIT_URL="http://$FAUNOSTEO_DEV_HOST:54324"
# Mailpit for other devices goes through the DEV gateway (basic auth), never the raw 54324.
export FAUNOSTEO_DEV_MAILPIT_URL="http://$FAUNOSTEO_DEV_HOST:54325"
+3 -3
View File
@@ -2,9 +2,9 @@
# DEV gateway on the private network (docs/development/ENVIRONMENTS.md §3).
# pnpm dev:gateway # up: generates the Mailpit credentials once, starts faunosteo_dev_gateway
# pnpm dev:gateway:stop # down
# Prerequisite: the rootless Docker daemon binds published ports on loopback by default
# (~/.config/docker/daemon.json {"ip": "127.0.0.1"}, ENVIRONMENTS.md §3.1), so the
# gateway is the only listener of the stack on the LAN address.
# Serves Mailpit behind basic auth on <FAUNOSTEO_DEV_HOST>:54325; the raw ports the
# Supabase CLI publishes on 0.0.0.0 (54322 PostgreSQL, 54323 Studio, 54324 Mailpit) are
# closed to the LAN by the host firewall rules of ENVIRONMENTS.md §3.2.
set -euo pipefail
cd "$(dirname "$0")/.."
. scripts/dev-env.sh
+33 -25
View File
@@ -1,9 +1,12 @@
#!/usr/bin/env bash
# Allowed / refused access check of the DEV surfaces from a distinct network origin:
# a throwaway container on its own Docker bridge reaches the host only through its LAN
# address, like another device would (never through loopback).
# Access check of the DEV surfaces (docs/development/ENVIRONMENTS.md §3.3).
# pnpm dev:net-check # expects the stack, pnpm dev and the gateway running
# Exit 1 when an expectation fails. docs/development/ENVIRONMENTS.md §3.
# Part 1 probes the ALLOWED surfaces from a throwaway container on its own Docker network,
# which reaches the host by its LAN address only. Part 2 cannot be proven from this machine:
# with Docker rootless a container's traffic to the host's own address is delivered
# locally, never through the LAN interface, so the firewall rules that close 54322-54324
# on that interface are invisible here. It prints the commands to run on another device.
# Exit 1 when an allowed surface fails.
set -euo pipefail
cd "$(dirname "$0")/.."
. scripts/dev-env.sh
@@ -15,40 +18,45 @@ docker network create "$net" >/dev/null 2>&1 || true
cleanup() { docker network rm "$net" >/dev/null 2>&1 || true; }
trap cleanup EXIT
probe() { # probe <label> <expected> <curl args...>; expected = an HTTP code, "closed" or "open"
failed=0
probe() { # probe <label> <expected HTTP code> <curl args...>
local label="$1" expected="$2"; shift 2
local code status=0
code="$(docker run --rm --network "$net" "$image" -s -o /dev/null -w '%{http_code}' --connect-timeout 4 "$@" 2>/dev/null)" || status=$?
# curl exit 7 = connection refused, 28 = timeout (filtered): nothing listens for the LAN.
# A TCP service that is not HTTP (PostgreSQL) answers with exit 52/56: the port is open.
case "$status" in
0) ;;
7|28) code=closed ;;
*) code=open ;;
esac
# curl exit 7 = refused, 28 = timeout: nothing answers; other non-zero = a non-HTTP service.
case "$status" in 0) ;; 7|28) code=closed ;; *) code=open ;; esac
if [ "$code" = "$expected" ]; then
printf 'OK %-52s %s\n' "$label" "$code"
printf 'OK %-50s %s\n' "$label" "$code"
else
printf 'FAIL %-52s %s (expected %s)\n' "$label" "$code" "$expected"
printf 'FAIL %-50s %s (expected %s)\n' "$label" "$code" "$expected"
failed=1
fi
}
failed=0
password=""
[ -s docker/dev-gateway/mailpit-password ] && password="$(cat docker/dev-gateway/mailpit-password)"
echo "== from a separate Docker network towards $host"
probe "app :5173 (Vite) allowed" 200 "http://$host:5173/login"
probe "API :54321 auth health (gateway) allowed" 200 "http://$host:54321/auth/v1/health"
probe "API :54321 rest without key 401" 401 "http://$host:54321/rest/v1/profiles"
probe "Mailpit :54324 without credentials 401" 401 "http://$host:54324/"
echo "== 1. allowed surfaces, from a separate Docker network towards $host"
probe "app :5173 (Vite)" 200 "http://$host:5173/login"
probe "Supabase API :54321 auth health" 200 "http://$host:54321/auth/v1/health"
probe "Supabase API :54321 REST without key" 401 "http://$host:54321/rest/v1/profiles"
probe "Mailpit gateway :54325 without credentials" 401 "http://$host:54325/"
if [ -n "$password" ]; then
probe "Mailpit :54324 with credentials allowed" 200 -u "dev:$password" "http://$host:54324/"
probe "Mailpit gateway :54325 with credentials" 200 -u "dev:$password" "http://$host:54325/"
else
echo "SKIP Mailpit gateway with credentials (run pnpm dev:gateway first)"
fi
probe "PostgreSQL :54322 closed" closed "http://$host:54322/"
probe "Studio :54323 closed" closed "http://$host:54323/"
echo "== published ports of the stack (loopback expected except the gateway)"
echo "== 2. refused surfaces: run on ANOTHER device of the network (this machine cannot see its LAN firewall)"
cat <<EOF
nc -zv -w 3 $host 54322 # PostgreSQL -> must fail (timeout or refused)
nc -zv -w 3 $host 54323 # Studio -> must fail
nc -zv -w 3 $host 54324 # raw Mailpit -> must fail
nc -zv -w 3 $host 54321 # Supabase API -> must succeed (control)
(phone: http://$host:54323 must not load; http://$host:5173 must)
EOF
echo "== 3. listeners published by the stack (the CLI forces 0.0.0.0; the firewall closes 54322-54324 on the LAN)"
for c in supabase_kong_faunosteo supabase_db_faunosteo supabase_studio_faunosteo supabase_inbucket_faunosteo faunosteo_dev_gateway; do
printf '%-30s %s\n' "$c" "$(docker port "$c" 2>/dev/null | grep -v '::' | tr '\n' ' ')"
printf ' %-30s %s\n' "$c" "$(docker port "$c" 2>/dev/null | grep -v '::' | tr '\n' ' ')"
done
exit "$failed"