diff --git a/.env.example b/.env.example index 622785a..7e61dd0 100644 --- a/.env.example +++ b/.env.example @@ -291,6 +291,12 @@ RECEIPT_WEB_UPSTREAM=100.107.152.119:8765 # `openssl rand -hex 32`. Changing it needs `docker compose up -d caddy`. RECEIPT_WEB_TOKEN= +# --- Partner Radar (radar.DOMAIN) ---------------------------------------------- +# A separate compose project on this host (adamf/cto, `make stpvm`), whose web +# container joins app-network as `radar-web`. Only set this to point +# radar.DOMAIN somewhere else. +# RADAR_UPSTREAM=radar-web:80 + # TfL Unified API key (500 req/min); used by the Python hotel finder TFL_APP_KEY= diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index 2e1e177..b1ca0e3 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -67,6 +67,7 @@ backend icecast2 gitea sb sb-pub python | | | cloudflared | `cloudflared` | — (fixed IP `172.28.255.250`) | all of Caddy, via Cloudflare | no (outbound only) | | dozzle (log viewer) | `dozzle` | 8080 | `/dozzle/` (admin-gated by Caddy `forward_auth`; reads the Docker socket) | no | | receipt printer (`receipt serve`, adamf/receipt_maker) | — (runs on **stppi**, not in this stack) | 8765 on stppi's Tailscale IP (`RECEIPT_WEB_UPSTREAM`) | `/receipt/`, prefix stripped (permission-gated on `receipt` by Caddy `forward_auth`; Caddy adds `X-Receipt-Token` and `X-Remote-User`). The only upstream off this host; 503 "offline" when stppi is down | no | +| Partner Radar (adamf/cto, its own compose project) | `radar-web` (alias of that project's `web`, on app-network) | 80 | `radar.`, the whole host (its own login, no gate; zones `radar` and `radar_login`). Started from the cto checkout with `make stpvm`; 503 "offline" when that stack is down | no | | traffic (tails the payload log) | `traffic` | — (no network) | none; its stdout is what Dozzle shows | no | | autoheal (restarts unhealthy caddy) | `autoheal` | — (no network) | none; reads the Docker socket | no | | garage (S3 object store) | `garage` | 3900 S3, 3902 web, 3903 admin | none directly; `/uploads/` falls back to its web endpoint for files not on the volume | no | @@ -310,6 +311,8 @@ Setup, once: - `www.` → `https://www.`: the site. - `` → `https://`: Caddy redirects it to www, and it serves Gitea's registry at `/v2/`. + - `radar.` → `https://radar.`: the Partner Radar demo + (Caddy's `radar.{$DOMAIN}` site, `sites/prod.caddy`). Creating each hostname replaces the existing A record for that name with a CNAME to the tunnel. **That is the cutover**: until then the tunnel carries nothing. @@ -467,6 +470,8 @@ gets its own zone, as `/receipt/` does. | `upload` | 30 / 1m | `/api/uploads` | Bounds how fast one IP fills the bucket or the volume. Generous because uploaders must be signed in (accounts are admin-created) and a batch of pictures dropped on a canvas page uploads at once. | | `hotel_search` | 3 / 1m | `/py/hotels/(search\|scan)` | Each request holds an upstream call for minutes and the Python side has one search slot — concurrency protection more than abuse protection. | | `receipt` | 10 / 1s | `/receipt/` | Prints are slow and physical; ten a second is far above any real use. | +| `radar` | 30 / 1s | all of `radar.` | The Partner Radar demo: an abuse ceiling like `api`, in its own zone because it is a different app. | +| `radar_login` | 5 / 1m | `radar./api/auth/login` | Brute-force defence on the demo's login, on top of `radar` and the app's own login throttling. | The WebSocket endpoint is deliberately unlimited: a socket is one long-lived request, and a limit there would drop reconnect storms rather than abuse. diff --git a/caddy/Caddyfile b/caddy/Caddyfile index 6c1f5ca..5ce38c5 100644 --- a/caddy/Caddyfile +++ b/caddy/Caddyfile @@ -292,13 +292,14 @@ respond "Too many requests from your address. Wait a moment and retry." 503 } - # An upstream that could not be reached or timed out. Two routes turn that + # An upstream that could not be reached or timed out. Three routes turn that # into something better than a bare 502, each keyed on a variable its # route sets (error routes keep the request's vars, and a variable cannot # be spoofed the way a path can be dressed up): # uploads_fallback Garage is down: serve the file from disk instead. # receipt_upstream set only once the permission gate has passed, so a # backend outage is not reported as the printer's. + # radar_upstream the Partner Radar stack (radar.DOMAIN) is down. handle_errors 502 504 { @uploads_fallback vars uploads_fallback yes handle @uploads_fallback { @@ -308,6 +309,10 @@ handle @receipt_offline { respond "The receipt printer machine is offline." 503 } + @radar_offline vars radar_upstream yes + handle @radar_offline { + respond "Partner Radar is offline." 503 + } } } diff --git a/caddy/sites/prod.caddy b/caddy/sites/prod.caddy index 9104f75..f010b00 100644 --- a/caddy/sites/prod.caddy +++ b/caddy/sites/prod.caddy @@ -131,3 +131,49 @@ www.{$DOMAIN} { } } } + +# ---- Partner Radar (radar.DOMAIN) ---- +# The adamf/cto "Partner Radar" demo: its own docker compose project on this +# host (`make stpvm` there), whose `web` container (its own Caddy, serving the +# React app and proxying its API) joins app-network as `radar-web`. A +# subdomain, not a /radar/ path, because the app assumes it owns `/` and its +# session cookie then stays apart from www's. +# +# No admin gate: the app has its own login and accounts. No security_headers +# either: the app's Caddy sends its own, and www's CSP would block the React +# app. Two zones of its own (see DEPLOYMENT.md §6): `radar` on every request, +# and `radar_login` on top of it for the login endpoint. radar_upstream lets +# `errors` answer "offline" when the stack is down instead of a bare 502. +(radar_proxy) { + reverse_proxy {$RADAR_UPSTREAM} { + import proxy + # Caddy's default, spelt out: when the stack is down, fail fast and + # let `errors` answer. + transport http { + dial_timeout 3s + } + } +} + +radar.{$DOMAIN} { + import prod_tls + import common + header Strict-Transport-Security "max-age=63072000; includeSubDomains" + + route { + import limit radar 30 1s + request_body { + max_size 10MB + } + vars radar_upstream yes + handle /api/auth/login { + route { + import limit radar_login 5 1m + import radar_proxy + } + } + handle { + import radar_proxy + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml index b4a5422..ea25512 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -150,6 +150,11 @@ services: # A dead port by default, so /receipt/ reads "offline". - RECEIPT_WEB_UPSTREAM=${RECEIPT_WEB_UPSTREAM:-127.0.0.1:9} - RECEIPT_WEB_TOKEN=${RECEIPT_WEB_TOKEN:-} + # Partner Radar (radar.DOMAIN): the adamf/cto stack's `web` container, + # which joins app-network under this alias (its docker-compose.stpvm.yml). + # While that stack is down the name does not resolve and radar.DOMAIN + # answers "offline". + - RADAR_UPSTREAM=${RADAR_UPSTREAM:-radar-web:80} # Zone -> Zone -> Read and Zone -> DNS -> Edit; see .env.example. - CLOUDFLARE_DNS_API_TOKEN=${CLOUDFLARE_DNS_API_TOKEN:-} networks: @@ -164,6 +169,7 @@ services: aliases: - ${DOMAIN} - www.${DOMAIN} + - radar.${DOMAIN} # Fixed for cloudflared's extra_hosts (see there): an alias only # exists while Caddy is running, and this address is pinned to the # same names for when it is not. Top of the /16 beside cloudflared's, @@ -238,6 +244,7 @@ services: extra_hosts: - "${DOMAIN}:172.28.255.251" - "www.${DOMAIN}:172.28.255.251" + - "radar.${DOMAIN}:172.28.255.251" networks: app-network: ipv4_address: 172.28.255.250