chore(workspace): DEV least-privilege exposure — nginx DEV gateway (API on the LAN, Mailpit behind basic auth), network check from a distinct origin, loopback default for the rootless daemon documented
The Supabase CLI publishes 54321-54324 on every interface with no bind
option. Design: the rootless daemon binds published ports on loopback by
default (~/.config/docker/daemon.json {"ip":"127.0.0.1"}, owner action,
not applied), and the DEV gateway (Compose service dev-gateway, profile
dev, container faunosteo_dev_gateway) re-publishes only the API (Kong) and
Mailpit behind HTTP basic auth on FAUNOSTEO_DEV_HOST; Studio and PostgreSQL
stay loopback (SSH tunnel for Studio). pnpm dev:gateway generates the Mailpit
credentials (gitignored; htpasswd 644 because the rootless container user
cannot read a 600 file, hash only). pnpm dev:net-check probes from a
throwaway container on its own Docker network: app, API health, REST 401,
Mailpit 401/200, PostgreSQL and Studio closed. Gateway proven on alternate
ports (health 200, password login 200, Mailpit 401 / 200).
This commit is contained in:
1 parent
5a12596195
commit
3e48b0d848
11 files changed
+246
-36
No files matched your search
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
. scripts/dev-env.sh
|
||||
dir=docker/dev-gateway
|
||||
htpasswd="$dir/htpasswd"
|
||||
secret="$dir/mailpit-password"
|
||||
|
||||
case "${1:-up}" in
|
||||
up)
|
||||
if [ ! -s "$htpasswd" ]; then
|
||||
password="$(openssl rand -base64 18 | tr -d '/+=' | cut -c1-20)"
|
||||
printf 'dev:%s\n' "$(openssl passwd -apr1 "$password")" > "$htpasswd"
|
||||
printf '%s\n' "$password" > "$secret"
|
||||
# Rootless Docker: the container's nginx user maps to a subordinate uid and cannot
|
||||
# read a 600 file of this account; the htpasswd holds only a hash. The clear
|
||||
# password stays 600.
|
||||
chmod 644 "$htpasswd"
|
||||
chmod 600 "$secret"
|
||||
echo "== Mailpit credentials generated: user dev, password in $secret (not committed)"
|
||||
fi
|
||||
docker compose --profile dev up -d dev-gateway
|
||||
echo "== gateway: api $FAUNOSTEO_DEV_API_URL mailpit $FAUNOSTEO_DEV_MAILPIT_URL (user dev, password: cat $secret)"
|
||||
;;
|
||||
down)
|
||||
docker compose --profile dev rm -sf dev-gateway
|
||||
;;
|
||||
*)
|
||||
echo "usage: dev-gateway.sh [up|down]" >&2; exit 2 ;;
|
||||
esac
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/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).
|
||||
# pnpm dev:net-check # expects the stack, pnpm dev and the gateway running
|
||||
# Exit 1 when an expectation fails. docs/development/ENVIRONMENTS.md §3.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
. scripts/dev-env.sh
|
||||
host="$FAUNOSTEO_DEV_HOST"
|
||||
net=faunosteo_net_check
|
||||
image=curlimages/curl:8.11.1
|
||||
docker network create "$net" >/dev/null 2>&1 || true
|
||||
# shellcheck disable=SC2329 # invoked by the trap
|
||||
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"
|
||||
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
|
||||
if [ "$code" = "$expected" ]; then
|
||||
printf 'OK %-52s %s\n' "$label" "$code"
|
||||
else
|
||||
printf 'FAIL %-52s %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/"
|
||||
if [ -n "$password" ]; then
|
||||
probe "Mailpit :54324 with credentials allowed" 200 -u "dev:$password" "http://$host:54324/"
|
||||
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)"
|
||||
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' ' ')"
|
||||
done
|
||||
exit "$failed"
|
||||
Reference in new issue
Block a user