Dough Git

commit

aaaa

commit
08fbb620d2c4808f2619cb1a1398fac55bcdb3fd
author
Clove Twilight <[email protected]>
date
2026-09-05 15:56

diff --git a/docker-compose.yml b/docker-compose.yml
index de1f838..743cc34 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -71,17 +71,17 @@ services:
     # rather than reuse whatever is in the local image cache.
     pull_policy: always
     restart: unless-stopped
-    # The only thing reachable from outside. Published on every interface, not
-    # just loopback, because the reverse proxy is not on this host's loopback.
+    # The way in. Published on every interface, not just loopback, because a
+    # loopback bind is unreachable from another container or another machine --
+    # and the reference deployment has no public IP: Cloudflare Tunnel dials
+    # out and forwards here, so nothing is inbound-reachable at the edge.
     #
-    # This is NOT firewalled by ufw or firewalld: Docker publishes through
-    # DOCKER-USER and nat PREROUTING, which run before the INPUT chain those
-    # tools manage, so `ufw deny 3000` has no effect. Whatever keeps 3000 off
-    # the public internet has to live outside this file — a cloud security
-    # group, or an explicit DOCKER-USER rule.
+    # Plain http on that hop is fine. TLS terminates at Cloudflare, and `Secure`
+    # is set unconditionally rather than inferred from the request, so no
+    # forwarded-proto trust needs configuring.
     #
-    # Reaching it over plain http also breaks sign-in: cookies are `__Host-`
-    # and `Secure`, so only the https origin can hold a session.
+    # On a host that DOES have a public IP, note that Docker publishes ahead of
+    # ufw's chain, so `ufw deny 3000` would not close this.
     ports:
       - "3000:3000"
     environment:
diff --git a/docs/decisions.md b/docs/decisions.md
index b11bba4..39f0784 100644
--- a/docs/decisions.md
+++ b/docs/decisions.md
@@ -517,11 +517,13 @@ belongs to someone else are indistinguishable — and every management page is
 writer, so it is the only container with the data volume. It is `expose`d to the
 compose network and never `ports:`-published: the browser reaches it only
 through the web tier's proxy, so publishing 3001 would put the management API on
-the host network. The web tier publishes `3000:3000` on every interface — the
-reverse proxy is not on the host's loopback, so a loopback bind could not reach
-it — and TLS terminates at that proxy. Docker publishes ahead of the chain `ufw`
-manages, so keeping 3000 off the public internet is a host or security-group
-concern that compose cannot enforce. Guarded by `apps/web/test/docker.test.ts`.
+the host network. The web tier publishes `3000:3000` on every interface: the
+reference deployment has no public IP and gets its traffic through a Cloudflare
+Tunnel, which dials out and forwards inward, and a loopback bind is unreachable
+from another container or machine. TLS terminates at Cloudflare. The http hop
+from tunnel to container is safe because `Secure` is set unconditionally rather
+than inferred from the request, so no forwarded-proto trust is configured
+anywhere. Guarded by `apps/web/test/docker.test.ts`.
 
 **D2. Compose runs images, it never builds them.** There is one
 `docker-compose.yml` with no `build:` section at all;
diff --git a/docs/deployment.md b/docs/deployment.md
index d684999..e4588dc 100644
--- a/docs/deployment.md
+++ b/docs/deployment.md
@@ -185,11 +185,10 @@ Four details in `docker-compose.yml` are deliberate:
 - **`api` has no `ports:`, only `expose:`.** Publishing 3001 would put the
   management API straight onto the host network, reachable without going through
   the web tier. It is addressable only as `http://api:3001` from inside.
-- **`web` publishes `3000:3000`, on every interface.** The reverse proxy is not
-  on this host's loopback, so a loopback-only bind cannot reach it. Put a
-  TLS-terminating proxy in front; the container itself should not be the thing
-  facing the internet, and keeping it off the public internet is now the host's
-  job rather than compose's — see below.
+- **`web` publishes `3000:3000`, on every interface.** A loopback-only bind is
+  unreachable from another container or another machine, which is what
+  Cloudflare Tunnel needs. TLS terminates at Cloudflare; the container is never
+  the thing facing the internet. See below.
 - **`pull_policy: always`.** A pinned tag is only a pin if a restart actually
   fetches it rather than reusing whatever is in the local image cache.
 - **The named volume `pkviewer-data` is the whole of pkviewer's state.** Back
@@ -205,23 +204,29 @@ docker compose exec api sh -c \
 or more simply, stop the stack and copy the volume. Never `cp` a live WAL
 database.
 
-### Port 3000 is not covered by ufw
-
-Docker publishes ports through the `DOCKER-USER` chain and `nat PREROUTING`,
-both of which run **before** the `INPUT` chain that `ufw` and `firewalld`
-manage. `ufw deny 3000` therefore does nothing: the port stays open to anything
-that can route to the host.
-
-Restrict it outside this file, with whichever applies:
-
-- a cloud provider security group allowing 3000 only from the proxy's address;
-- an explicit rule, e.g.
-  `iptables -I DOCKER-USER -p tcp --dport 3000 ! -s <proxy-ip> -j DROP`.
-
-Leaving 3000 open to the internet is not a data leak — it serves the same pages
-the proxy does — but it is reachable over plain http, where `__Host-` `Secure`
-cookies cannot be set, so sign-in fails and the origin in links is wrong. Check
-it with `curl http://<public-ip>:3000/` from off the host.
+### Getting traffic in: Cloudflare Tunnel
+
+The reference deployment has no public IP. `cloudflared` dials out to
+Cloudflare, which terminates TLS and forwards to the container, so nothing is
+inbound-reachable and no ports need opening at the network edge.
+
+Point the tunnel at `http://<host-lan-ip>:3000` — or `http://web:3000` if
+`cloudflared` runs as a container on the same compose network, which avoids
+publishing the port at all. `3000:3000` rather than `127.0.0.1:3000:3000` is
+what makes the first form work: a loopback bind is not reachable from another
+container or another machine.
+
+**Plain http on that hop is fine.** The browser talks https to Cloudflare, and
+`Secure` is set unconditionally rather than inferred from the request
+(`apps/api/src/http/cookies.ts`), so no forwarded-proto trust needs configuring.
+`PUBLIC_ORIGIN` must still be the https URL: it is what the CSRF check compares
+the `Origin` header against, and what every absolute link is built from.
+
+One thing to be aware of if this ever runs on a host that *does* have a public
+IP: Docker publishes through the `DOCKER-USER` chain and `nat PREROUTING`, which
+run **before** the `INPUT` chain `ufw` and `firewalld` manage, so `ufw deny 3000`
+does nothing. Restricting it then means a security group, or
+`iptables -I DOCKER-USER -p tcp --dport 3000 ! -s <source> -j DROP`.
 
 ## Publishing images