diff --git a/deploy/compose-build-at-deploy.yml b/deploy/compose-build-at-deploy.yml index 3da792f..8f15621 100644 --- a/deploy/compose-build-at-deploy.yml +++ b/deploy/compose-build-at-deploy.yml @@ -6,7 +6,7 @@ # registry, so `scripts/build-images.sh` and `.gitea/workflows/docker-publish.yml` are not part # of this path at all. # -# Four things here are easy to get wrong, and all four are load-bearing: +# Five things here are easy to get wrong, and all five are load-bearing: # # 1. `web-build` copies the WHOLE repository into /app and builds from /app/frontend, not # frontend/ on its own. The frontend imports the Coach's core from outside its own directory @@ -36,7 +36,15 @@ # the registry-image path (docker-compose.yml) and is NOT read here. A change to the limits # has to be made in both, or the two deployment shapes diverge. # -# 4. nginx resolves `api` through a VARIABLE, not by name. A plain `proxy_pass http://api:3000` +# 4. X-Forwarded-For uses the APPEND form here, unlike web/nginx.conf.template. In this shape +# nginx is NOT the edge: Traefik terminates TLS in front of it, so `$remote_addr` is Traefik's +# own address and the real client only survives in the header Traefik sends. +# `$proxy_add_x_forwarded_for` carries that one through as the first entry, which is exactly +# what the API reads (see clientIp in api/server.js). The registry template does the opposite +# for the opposite reason — there the web container answers the internet directly, so the +# incoming header can be forged and only $remote_addr can be trusted. +# +# 5. nginx resolves `api` through a VARIABLE, not by name. A plain `proxy_pass http://api:3000` # is resolved once, when nginx starts, and the address is then pinned for the life of the # container: recreate the api — a deploy that changes its configuration, a `--force-recreate`, # a manual restart that gives it a new IP — and every /api call answers 502 until the web @@ -200,7 +208,7 @@ services: command: - /bin/sh - -c - - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; resolver 127.0.0.11 valid=10s ipv6=off; set $$api_upstream http://api:3000; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location /api/ { proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$remote_addr; proxy_set_header X-Forwarded-Proto $$scheme; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" + - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; resolver 127.0.0.11 valid=10s ipv6=off; set $$api_upstream http://api:3000; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $$scheme; } location /api/ { proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header Host $$host; proxy_set_header X-Real-IP $$remote_addr; proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $$scheme; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" restart: unless-stopped volumes: