Deploy path: X-Forwarded-For is the append form here, not $remote_addr
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
I changed this to $remote_addr when the resolver fix went in, on the reasoning that appending lets a client put its own address in front of the real one. That reasoning is right for web/nginx.conf.template and wrong here, and the deployment's own access log shows why: this nginx is NOT the edge. Traefik terminates TLS in front of it, logs the web container's peer as 10.0.1.182, and carries the real client (66.98.33.30) in the header it sends. $remote_addr therefore records Traefik's own address, and $proxy_add_x_forwarded_for — which puts the incoming header first — is what preserves the person's. The API reads the first entry, so the append form is the correct one in this shape. Comment 4 now spells out both directions: append here because a trusted proxy is in front, $remote_addr in the registry template because there the container answers the internet directly, where an incoming header is exactly what cannot be trusted. Nothing recorded was wrong in the meantime — AUDIT_IP is off unless an operator asks for it — but this is the setting to get right before anybody turns it on.
This commit is contained in:
1 parent
41b004fea7
commit
4222e8d86b
1 file changed
+11
-3
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user