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
@@ -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 |
|
||||
|
||||
Reference in new issue
Block a user