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:
1 parent
a8edd59059
commit
e633169a00
11 files changed
+143
-111
No files matched your search
@@ -403,3 +403,11 @@ Apply: every Storage call in later steps (documents, logos), every `returns tabl
|
||||
- Rootless bind mounts: a 600 file owned by the user is unreadable by the container's non-root user (subordinate uid) → nginx 500 "open() htpasswd failed (13)". Make hash-only files 644, keep clear secrets 600 outside the mount.
|
||||
- Probing "closed" vs "open" with curl: exit 7 (refused) / 28 (timeout) = closed; a non-HTTP TCP service (PostgreSQL) gives exit 52/56 = OPEN. HTTP 000 alone proves nothing.
|
||||
Apply: any DEV service exposure on this machine; future staging compose.
|
||||
|
||||
## LRN-053 | 2026-10-13 | Correction of LRN-052: Supabase CLI 2.120 binds 0.0.0.0 explicitly; rootless container probes cannot see the host LAN firewall
|
||||
|
||||
- Owner applied `~/.config/docker/daemon.json {"ip":"127.0.0.1"}` + restart: the CLI still published 54321-54324 on 0.0.0.0 and prints "All services bind to 0.0.0.0" → it sets the host IP explicitly; the daemon default never applies. LRN-052 bullet 1 is wrong for the CLI (still true for address-less ports of other containers). Only a host firewall closes PG/Studio/raw Mailpit; UFW rules scoped `in on <lan-iface>` work on rootless listeners.
|
||||
- A gateway cannot share a port with a 0.0.0.0 listener whatever its own address ("port is already allocated") → serve the authenticated Mailpit on another port (54325).
|
||||
- Rootless (slirp/pasta) containers reach the host's own LAN IP by local delivery, never through the LAN interface → firewall refusals on that interface are invisible to any probe run on the host; prove them from another device (`nc -zv -w 3 <ip> <port>`).
|
||||
- Lesson: an "it should apply" assumption about a third-party tool's binding must be tested before handing a procedure to the owner (I flagged it as a hypothesis, but the owner still spent a daemon restart on it).
|
||||
Apply: any exposure work on this machine; staging compose (bind explicitly there).
|
||||
@@ -76,7 +76,7 @@ below runs from the repository root and delegates to the packages.
|
||||
# Development (DEV origin = this machine's LAN address, scripts/dev-env.sh; tests run from other devices)
|
||||
pnpm dev # Vite on http://<FAUNOSTEO_DEV_HOST>:5173 wired to the local stack (needs pnpm db:start)
|
||||
pnpm dev:offline # the local tool without backend
|
||||
pnpm dev:gateway # LAN entry: API :54321 + Mailpit :54324 (basic auth) on FAUNOSTEO_DEV_HOST; dev:gateway:stop
|
||||
pnpm dev:gateway # Mailpit behind basic auth on FAUNOSTEO_DEV_HOST:54325; dev:gateway:stop
|
||||
pnpm dev:net-check # allowed / refused probes from a distinct Docker network
|
||||
|
||||
# Production build (typecheck + vite build)
|
||||
@@ -445,11 +445,10 @@ Database (Supabase)
|
||||
(app, Supabase API, Mailpit, Studio) is addressed by the DEV origin (`scripts/dev-env.sh`, `FAUNOSTEO_DEV_HOST`),
|
||||
never by `127.0.0.1` / `localhost`, never hard-coded in a source. The Supabase CLI runs only through
|
||||
`scripts/supabase.sh` (`pnpm db:*`, `pnpm supabase`): config.toml reads the origin with `env()`.
|
||||
- Exposure (least privilege, `pnpm dev:net-check`): the rootless daemon binds published ports on loopback
|
||||
(`~/.config/docker/daemon.json` `{"ip":"127.0.0.1"}`); the DEV gateway (`pnpm dev:gateway`, nginx,
|
||||
`faunosteo_dev_gateway`) re-publishes only the API (54321) and Mailpit behind basic auth (54324) on the LAN
|
||||
address; Vite 5173 on all interfaces; Studio 54323 and PostgreSQL 54322 loopback only (SSH tunnel for
|
||||
Studio); the worker publishes no port. Nothing is exposed to the Internet; no production infrastructure
|
||||
- Exposure (least privilege, `pnpm dev:net-check`): LAN gets Vite 5173, the Supabase API 54321 and Mailpit
|
||||
behind basic auth through the DEV gateway (`pnpm dev:gateway`, nginx, `faunosteo_dev_gateway`, 54325). The CLI
|
||||
forces 0.0.0.0 on 54322 PostgreSQL, 54323 Studio, 54324 raw Mailpit: closed on the LAN interface by host UFW
|
||||
rules (owner action, ENVIRONMENTS.md §3.2); SSH tunnel for Studio; the worker publishes no port. Nothing is exposed to the Internet; no production infrastructure
|
||||
is touched from this repository. Rust is built natively; Docker runs services, the worker, sandbox tests and images.
|
||||
|
||||
### Files and Storage (migration 20261013100000, docs/development/STORAGE.md)
|
||||
|
||||
+5
-7
@@ -40,11 +40,10 @@ services:
|
||||
- supabase
|
||||
restart: unless-stopped
|
||||
|
||||
# DEV gateway (docs/development/ENVIRONMENTS.md §3): with the rootless daemon binding
|
||||
# published ports on loopback by default, this is the only entry of the private
|
||||
# network into the stack: the Supabase API on <DEV host>:54321 and Mailpit behind
|
||||
# basic auth on <DEV host>:54324. Started by `pnpm dev:gateway` (profile `dev`),
|
||||
# which exports FAUNOSTEO_DEV_HOST and generates docker/dev-gateway/htpasswd.
|
||||
# DEV gateway (docs/development/ENVIRONMENTS.md §3): Mailpit behind basic auth on
|
||||
# <DEV host>:54325, the only LAN entry to the DEV mails (the CLI's raw Mailpit port
|
||||
# 54324 is closed to the LAN by the host firewall rule). Started by `pnpm dev:gateway`
|
||||
# (profile `dev`), which exports FAUNOSTEO_DEV_HOST and generates the htpasswd.
|
||||
dev-gateway:
|
||||
container_name: faunosteo_dev_gateway
|
||||
profiles: ["dev"]
|
||||
@@ -53,8 +52,7 @@ services:
|
||||
- ./docker/dev-gateway/nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
- ./docker/dev-gateway/htpasswd:/etc/nginx/htpasswd:ro
|
||||
ports:
|
||||
- "${FAUNOSTEO_DEV_HOST:-127.0.0.1}:54321:54321"
|
||||
- "${FAUNOSTEO_DEV_HOST:-127.0.0.1}:54324:54324"
|
||||
- "${FAUNOSTEO_DEV_HOST:-127.0.0.1}:54325:54325"
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
networks:
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# DEV gateway (docs/development/ENVIRONMENTS.md §3): the only two Supabase surfaces
|
||||
# re-published on the private network once the rootless Docker daemon binds published
|
||||
# ports on loopback by default. Upstreams are resolved through Docker's DNS on every
|
||||
# request (variables + resolver) so a restarted stack is followed without a restart here.
|
||||
# DEV gateway (docs/development/ENVIRONMENTS.md §3): Mailpit behind HTTP basic auth on
|
||||
# the LAN address, port 54325. The Supabase CLI publishes Mailpit itself on
|
||||
# 0.0.0.0:54324 with no authentication; that raw port is closed to the LAN by the host
|
||||
# firewall rule of §3.2, so this gateway is the only way to read DEV mails from another
|
||||
# device. The upstream is resolved through Docker's DNS on every request (variable +
|
||||
# resolver), so a restarted stack is followed without restarting the gateway.
|
||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
@@ -9,28 +11,8 @@ map $http_upgrade $connection_upgrade {
|
||||
'' close;
|
||||
}
|
||||
|
||||
# Supabase API (Kong: Auth, PostgREST, Storage) for the browsers of the LAN.
|
||||
server {
|
||||
listen 54321;
|
||||
server_name _;
|
||||
client_max_body_size 16m; # avatar uploads are capped at 5 MiB by the bucket
|
||||
location / {
|
||||
set $kong http://supabase_kong_faunosteo:8000;
|
||||
proxy_pass $kong;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_request_buffering off;
|
||||
proxy_read_timeout 120s;
|
||||
}
|
||||
}
|
||||
|
||||
# Mailpit (DEV mails: confirmation and recovery links) behind HTTP basic auth.
|
||||
server {
|
||||
listen 54324;
|
||||
listen 54325;
|
||||
server_name _;
|
||||
auth_basic "Faunosteo DEV mail";
|
||||
auth_basic_user_file /etc/nginx/htpasswd;
|
||||
|
||||
@@ -31,7 +31,7 @@ never hard-coded in the sources.
|
||||
| Variable | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `FAUNOSTEO_DEV_HOST` | the first non-loopback IPv4 of the host (`hostname -I`) | address or name of this machine on the private network; `127.0.0.1` for a host-only session; a production host is refused |
|
||||
| derived | `FAUNOSTEO_DEV_API_URL` `http://<host>:54321`, `FAUNOSTEO_DEV_SITE_URL` `http://<host>:5173`, `FAUNOSTEO_DEV_API_ORIGIN`, `FAUNOSTEO_DEV_STUDIO_URL` `:54323`, `FAUNOSTEO_DEV_MAILPIT_URL` `:54324` | read by `supabase/config.toml` (`env()`) and by the Vite dev server |
|
||||
| derived | `FAUNOSTEO_DEV_API_URL` `http://<host>:54321`, `FAUNOSTEO_DEV_SITE_URL` `http://<host>:5173`, `FAUNOSTEO_DEV_API_ORIGIN`, `FAUNOSTEO_DEV_STUDIO_URL` `:54323`, `FAUNOSTEO_DEV_MAILPIT_URL` `:54325` (gateway) | read by `supabase/config.toml` (`env()`) and by the Vite dev server |
|
||||
|
||||
Consumers: `scripts/supabase.sh` (every CLI call: `pnpm supabase …`,
|
||||
`pnpm db:start|stop|reset|test|types`), `scripts/dev.sh` (`pnpm dev`),
|
||||
@@ -62,54 +62,84 @@ the LAN, the administration tools and the database are not.
|
||||
| Service | Port | LAN | How it is enforced |
|
||||
|---|---|---|---|
|
||||
| Application (Vite) | 5173 | open | Vite listens on every interface (`server.host: true`); dev build, anon key only |
|
||||
| Supabase API (Kong: Auth, PostgREST, Storage) | 54321 | open | the DEV gateway re-publishes it on `<DEV host>:54321`; RLS, policies and the anon key protect the data; the service key never reaches a browser |
|
||||
| Mailpit (DEV mails) | 54324 | open **with credentials** | the DEV gateway re-publishes it behind HTTP basic auth (user `dev`, generated password in `docker/dev-gateway/mailpit-password`, never committed) |
|
||||
| Studio | 54323 | **closed** | loopback only; from another device: SSH tunnel (below) |
|
||||
| PostgreSQL | 54322 | **closed** | loopback only; tests and the CLI use `127.0.0.1:54322` on the host |
|
||||
| Supabase API (Kong: Auth, PostgREST, Storage) | 54321 | open | published by the CLI; RLS, policies and the anon key protect the data; the service key never reaches a browser |
|
||||
| Mailpit for other devices | 54325 | open **with credentials** | the DEV gateway (nginx, `faunosteo_dev_gateway`, `pnpm dev:gateway`) on `<DEV host>:54325`, HTTP basic auth: user `dev`, generated password in `docker/dev-gateway/mailpit-password` (never committed) |
|
||||
| Mailpit raw | 54324 | **closed** | host firewall rule on the LAN interface (§3.2) |
|
||||
| Studio | 54323 | **closed** | host firewall rule; from another device: SSH tunnel (§3.4) |
|
||||
| PostgreSQL | 54322 | **closed** | host firewall rule; the CLI and the tests use it on the host |
|
||||
| Worker | none | — | internal, Supabase compose network, read-only, no capability |
|
||||
| PostgREST, GoTrue, Storage, pg-meta | none | — | behind Kong |
|
||||
|
||||
### 3.1 Mechanism (no privileges, no firewall)
|
||||
### 3.1 Why a host firewall is required
|
||||
|
||||
The Supabase CLI publishes its ports with no host address and offers no bind
|
||||
option, so Docker uses the daemon's default address. Two pieces:
|
||||
The Supabase CLI 2.120 binds every published port on `0.0.0.0` and `[::]`
|
||||
explicitly ("All services bind to 0.0.0.0" at start) and has no bind option:
|
||||
the rootless daemon's default address (`daemon.json` `"ip"`) does not apply
|
||||
to it (tried 2026-10-13). No user-level setting can close PostgreSQL, Studio
|
||||
or the raw Mailpit port. With Docker rootless the published ports are plain
|
||||
listening sockets of the rootlesskit process in the host network namespace,
|
||||
so host INPUT rules apply to them (unlike rootful Docker, whose DNAT bypasses
|
||||
UFW). The rules below are scoped to the LAN interface: loopback, the Docker
|
||||
networks and every other port of the machine are untouched.
|
||||
|
||||
1. **The rootless daemon binds published ports on loopback by default**:
|
||||
`~/.config/docker/daemon.json` = `{"ip": "127.0.0.1"}` (user-level file of
|
||||
Docker rootless, no sudo). Every port published without an explicit
|
||||
address, the CLI's included, then listens on `127.0.0.1` only.
|
||||
2. **The DEV gateway** (`docker/dev-gateway/nginx.conf`, Compose service
|
||||
`dev-gateway`, profile `dev`, container `faunosteo_dev_gateway`): an nginx
|
||||
on the Supabase network, published on `<FAUNOSTEO_DEV_HOST>:54321` (proxy
|
||||
to Kong) and `<FAUNOSTEO_DEV_HOST>:54324` (proxy to Mailpit behind basic
|
||||
auth). `pnpm dev:gateway` starts it (and generates the Mailpit password on
|
||||
first use), `pnpm dev:gateway:stop` stops it.
|
||||
### 3.2 Firewall rules (owner action, sudo)
|
||||
|
||||
Why not UFW: with Docker rootless, published ports are ordinary listening
|
||||
sockets of the rootlesskit process in the host network namespace, so host
|
||||
INPUT rules would apply (unlike rootful Docker, whose DNAT bypasses UFW);
|
||||
but a firewall rule needs sudo, and binding to loopback removes the
|
||||
listener instead of filtering it. A host firewall stays a possible second
|
||||
layer, the owner's decision.
|
||||
```bash
|
||||
sudo ufw status verbose # note whether it is active and its default policy
|
||||
|
||||
### 3.2 Check
|
||||
# A. UFW inactive (keeps today's behaviour for every other port, adds three refusals)
|
||||
sudo ufw default allow incoming
|
||||
sudo ufw default allow outgoing
|
||||
sudo ufw deny in on enp89s0 to any port 54322 proto tcp comment 'faunosteo dev postgres'
|
||||
sudo ufw deny in on enp89s0 to any port 54323 proto tcp comment 'faunosteo dev studio'
|
||||
sudo ufw deny in on enp89s0 to any port 54324 proto tcp comment 'faunosteo dev mailpit raw'
|
||||
sudo ufw enable
|
||||
|
||||
`pnpm dev:net-check` probes from a throwaway container on its own Docker
|
||||
network (a distinct origin that reaches the host by its LAN address only):
|
||||
app 200, API health 200, REST without key 401, Mailpit 401 without and 200
|
||||
with the credentials, PostgreSQL and Studio closed; it prints the published
|
||||
ports of the stack. Exit 1 on any deviation.
|
||||
# B. UFW already active with "deny (incoming)": the three ports are already refused
|
||||
# unless a rule opens them; open what the devices need, from the private subnet only
|
||||
sudo ufw allow in on enp89s0 from 192.168.1.0/24 to any port 5173,54321,54325 proto tcp comment 'faunosteo dev browser'
|
||||
```
|
||||
|
||||
### 3.3 Studio from another device
|
||||
`enp89s0` and `192.168.1.0/24` are this machine's interface and subnet
|
||||
(`ip -4 -o addr show`); adapt them if they change. Rules cover IPv4 and IPv6
|
||||
(UFW `IPV6=yes`, the Ubuntu default).
|
||||
|
||||
Rollback:
|
||||
|
||||
```bash
|
||||
sudo ufw status numbered # then, for each faunosteo rule, highest number first:
|
||||
sudo ufw delete <n>
|
||||
sudo ufw disable # only in case A, if UFW was inactive before
|
||||
```
|
||||
|
||||
Impact: case A changes nothing for SSH, RDP or any other service (default
|
||||
allow incoming); only the three ports stop answering on the LAN interface.
|
||||
Case B adds an allow rule limited to the subnet.
|
||||
|
||||
### 3.3 Check
|
||||
|
||||
`pnpm dev:net-check`:
|
||||
|
||||
1. probes the allowed surfaces from a throwaway container on its own Docker
|
||||
network (app 200, API health 200, REST without key 401, Mailpit gateway
|
||||
401 without and 200 with the credentials);
|
||||
2. prints the refusal checks to run **from another device** (`nc -zv -w 3
|
||||
<host> 54322 / 54323 / 54324` must fail, `54321` must succeed): with Docker
|
||||
rootless a container's traffic to the host's own address is delivered
|
||||
locally and never crosses the LAN interface, so this machine cannot see its
|
||||
own LAN firewall;
|
||||
3. lists the published ports of the stack.
|
||||
|
||||
### 3.4 Studio from another device
|
||||
|
||||
```bash
|
||||
ssh -L 54323:127.0.0.1:54323 <user>@<DEV host> # then http://localhost:54323 on that device
|
||||
```
|
||||
|
||||
Studio's own API calls go to `http://<DEV host>:54321` (the gateway), which
|
||||
the device reaches directly.
|
||||
Studio's own API calls go to `http://<DEV host>:54321` (Kong), which the
|
||||
device reaches directly.
|
||||
|
||||
### 3.4 HTTP on a private address
|
||||
### 3.5 HTTP on a private address
|
||||
|
||||
The auth flows (PKCE, session in localStorage, no cookie) work over HTTP.
|
||||
What would not: browser features that need a secure context on a
|
||||
@@ -122,7 +152,8 @@ or a private name with a certificate), never the production domain.
|
||||
|
||||
On the Ubuntu machine: `pnpm db:start`, `pnpm dev:gateway`, the worker
|
||||
(`docker compose --profile worker up -d worker`), `pnpm dev`, then
|
||||
`pnpm dev:net-check` (all OK). From the computer, then from the phone on the
|
||||
`pnpm dev:net-check` (part 1 all OK), then the part 2 commands from the
|
||||
computer. From the computer, then from the phone on the
|
||||
same network:
|
||||
|
||||
1. `http://<host>:5173/` opens the Faunosteo home.
|
||||
@@ -138,7 +169,8 @@ same network:
|
||||
9. Se déconnecter returns to the home; `/app` redirects to `/login`.
|
||||
10. Same steps on the phone; no horizontal scroll.
|
||||
|
||||
A sign-up from the device: Mailpit at `http://<host>:54324` (user `dev`,
|
||||
A sign-up from the device: Mailpit at `http://<host>:54325` (user `dev`,
|
||||
password: `cat docker/dev-gateway/mailpit-password` on the Ubuntu machine),
|
||||
the link opened in the same browser as the form. Refused from the device:
|
||||
`http://<host>:54323` (Studio) and anything on `:54322` (PostgreSQL).
|
||||
`http://<host>:54323` (Studio), `http://<host>:54324` (raw Mailpit) and
|
||||
anything on `:54322` (PostgreSQL).
|
||||
@@ -99,7 +99,7 @@ holding a platform role.
|
||||
## 5. Manual validation (local stack)
|
||||
|
||||
```bash
|
||||
pnpm db:start # stack on the DEV origin (LAN address); Mailpit at http://<host>:54324
|
||||
pnpm db:start # stack on the DEV origin (LAN address); Mailpit at http://<host>:54325 (basic auth, pnpm dev:gateway)
|
||||
VITE_AUTH_PROVIDERS=google pnpm dev # http://<host>:5173 from any device of the private network (ENVIRONMENTS.md)
|
||||
```
|
||||
|
||||
|
||||
@@ -59,10 +59,10 @@ Every CLI call goes through `scripts/supabase.sh` (`pnpm db:*`, `pnpm supabase
|
||||
<args>`): it exports the DEV origin that `config.toml` reads with `env()`
|
||||
(`api.external_url`, `auth.site_url`, `studio.api_url`). A direct
|
||||
`node_modules/.bin/supabase start` would leave the literal `env(...)` text in
|
||||
GoTrue's mail links. Published ports: API 54321, PostgreSQL 54322, Studio
|
||||
54323, Mailpit 54324, on loopback once the rootless daemon defaults to
|
||||
`127.0.0.1`; the DEV gateway re-publishes the API and Mailpit (basic auth) on
|
||||
the LAN address (`ENVIRONMENTS.md` §3).
|
||||
GoTrue's mail links. The CLI publishes API 54321, PostgreSQL 54322, Studio
|
||||
54323 and Mailpit 54324 on `0.0.0.0` (no bind option); the host firewall
|
||||
closes 54322-54324 on the LAN interface and the DEV gateway serves Mailpit
|
||||
behind basic auth on 54325 (`ENVIRONMENTS.md` §3).
|
||||
|
||||
```bash
|
||||
pnpm db:start # supabase start: pulls images, applies migrations + seed, prints URLs and keys
|
||||
@@ -79,6 +79,10 @@ Local endpoints (`config.toml`):
|
||||
| Studio | `http://127.0.0.1:54323` |
|
||||
| Mail catcher (confirmation / OTP mails) | `http://127.0.0.1:54324` |
|
||||
|
||||
Addresses on the host itself. From another device of the network: app `:5173`,
|
||||
API `:54321`, Mailpit through the gateway `:54325` (basic auth); Studio by SSH
|
||||
tunnel; PostgreSQL not at all (`ENVIRONMENTS.md` §3).
|
||||
|
||||
`pnpm db:start` prints the `anon` and `service_role` keys. Only the anon key
|
||||
ever reaches the browser.
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ works as `corepack pnpm <cmd>`.
|
||||
| `pnpm install` | installs the whole workspace from the lockfile |
|
||||
| `pnpm dev` | Vite dev server of `apps/app` on `http://<FAUNOSTEO_DEV_HOST>:5173`, wired to the local Supabase stack by the DEV origin (`scripts/dev.sh`, `ENVIRONMENTS.md`) |
|
||||
| `pnpm dev:offline` | the same server without backend (local tool only) |
|
||||
| `pnpm dev:gateway` / `dev:gateway:stop` | the DEV gateway: Supabase API and Mailpit (basic auth) on the LAN address (`ENVIRONMENTS.md` §3) |
|
||||
| `pnpm dev:net-check` | allowed / refused access probes from a distinct Docker network |
|
||||
| `pnpm dev:gateway` / `dev:gateway:stop` | the DEV gateway: Mailpit behind basic auth on the LAN address, port 54325 (`ENVIRONMENTS.md` §3) |
|
||||
| `pnpm dev:net-check` | allowed surfaces probed from a distinct Docker network; refusal checks printed for another device |
|
||||
| `pnpm supabase <args>` / `pnpm db:*` | the Supabase CLI with the DEV origin exported (`scripts/supabase.sh`) |
|
||||
| `pnpm preview` | serves `apps/app/dist` on :4173 |
|
||||
| `pnpm typecheck` | `tsc --noEmit` in every package |
|
||||
|
||||
+2
-1
@@ -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"
|
||||
@@ -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
@@ -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"
|
||||
Reference in new issue
Block a user