M8: NPM-vHost research.* robust — alles in host-level advanced_config (locations brechen NPM-Conf-Generierung), DELETE+POST bei Drift
NPM 2.15.1: custom locations + advanced_config oder locations mit eigenem advanced_config lassen die proxy_host/<id>.conf still aus (SNI alert 112); PUT loescht die conf ohne neu zu schreiben. Jetzt: komplette location-Bloecke (/, /api/, /ws, /oauth2/, = /oauth2/auth) im host-level advanced_config, locations: [], Drift via DELETE+POST. Verifiziert: 36.conf, nginx -t ok, TLS CN=research, unauth / /api/docs /ws -> 302 Keycloak, idempotent changed=0. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -207,3 +207,14 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy
|
||||
proxy_set_header Connection "upgrade";` + lange Timeouts (3600 s) im eigenen
|
||||
advanced_config. Verifiziert via NPM-API: locations `/`→8085, `/api`→8086,
|
||||
`/ws`→8086 (upgrade: true, auth: true), host ws_upgrade=true, cert=22.
|
||||
|
||||
- **Befund 19.11. (SSL_ERROR_UNRECOGNIZED_NAME_ALERT / 502 callback):** NPM
|
||||
2.15.1 generiert `proxy_host/<id>.conf` nur zuverlässig, wenn die Config
|
||||
komplett im host-level `advanced_config` steht (custom `locations` +
|
||||
advanced_config zusammen, oder Locations mit eigenem advanced_config,
|
||||
brechen die Generierung still — DB-Row existiert, conf fehlt → SNI alert).
|
||||
Lösung: alles in advanced_config inkl. eigener `location /`, `/api/`, `/ws`
|
||||
(NPM verzichtet dann auf seine generierte location /), `locations: []`;
|
||||
Drift-Update via DELETE+POST (PUT löscht die conf ohne neu zu schreiben).
|
||||
Verifiziert: 36.conf generiert, nginx -t ok, TLS CN=research, unauth /,
|
||||
/api/docs, /ws → 302 Keycloak.
|
||||
|
||||
+38
-16
@@ -19,9 +19,14 @@ reverse_proxy_research_letsencrypt_email: ma-koenig@gmx.net
|
||||
# oauth2-proxy on this host, loopback only (role reverse_proxy_oauth2proxy)
|
||||
reverse_proxy_research_iap_upstream: http://127.0.0.1:4180
|
||||
|
||||
# Host-level advanced config: only the /oauth2/ routes to the IAP.
|
||||
# Only /oauth2/auth is internal; sign_in/start/callback stay externally
|
||||
# reachable through /oauth2/.
|
||||
# Host-level advanced config ONLY (NPM 2.15.1 quirk: host-level advanced_config
|
||||
# AND custom locations together silently break conf generation; a location /
|
||||
# inside advanced_config makes NPM skip its own generated location /).
|
||||
# - /oauth2/* -> IAP (loopback), /oauth2/auth internal for auth_request
|
||||
# - /, /api/, /ws each carry auth_request + error_page redirect (per-location,
|
||||
# server-level inheritance did NOT redirect in practice)
|
||||
# - big proxy buffers on /oauth2/ (IAP callback Set-Cookie, else 502)
|
||||
# - /ws websocket upgrade headers + long timeouts; /api 600 s
|
||||
reverse_proxy_research_advanced_config: |
|
||||
location /oauth2/ {
|
||||
proxy_pass {{ reverse_proxy_research_iap_upstream }};
|
||||
@@ -29,9 +34,6 @@ reverse_proxy_research_advanced_config: |
|
||||
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;
|
||||
# the IAP's callback 302 carries a big Set-Cookie (session with id/access/
|
||||
# refresh token); nginx default buffers (4k/8k) reject it with
|
||||
# "upstream sent too big header" -> 502 (same finding as GNMON-000 M6)
|
||||
proxy_buffer_size 32k;
|
||||
proxy_buffers 8 32k;
|
||||
proxy_busy_buffers_size 64k;
|
||||
@@ -44,13 +46,33 @@ reverse_proxy_research_advanced_config: |
|
||||
proxy_set_header X-Original-URI $request_uri;
|
||||
proxy_set_header X-Original-URL $scheme://$host$request_uri;
|
||||
}
|
||||
|
||||
# NPM quirk (2026 guides): auth_request/error_page must NOT go into the
|
||||
# host-level advanced tab (server level) — they belong into a CUSTOM
|
||||
# LOCATION "/" (NPM then skips generating its own location /). The location
|
||||
# carries the auth directives in its own advanced_config.
|
||||
reverse_proxy_research_root_location_advanced_config: |
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
auth_request_set $auth_user $upstream_http_x_auth_request_user;
|
||||
auth_request_set $auth_email $upstream_http_x_auth_request_email;
|
||||
location / {
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
auth_request_set $auth_user $upstream_http_x_auth_request_user;
|
||||
auth_request_set $auth_email $upstream_http_x_auth_request_email;
|
||||
proxy_pass http://{{ reverse_proxy_research_upstream_host }}:{{ reverse_proxy_research_upstream_port }};
|
||||
proxy_set_header Host $host;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $http_connection;
|
||||
}
|
||||
location /api/ {
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
proxy_pass http://{{ reverse_proxy_research_upstream_host }}:{{ reverse_proxy_research_api_port }};
|
||||
proxy_set_header Host $host;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_send_timeout 600s;
|
||||
}
|
||||
location /ws {
|
||||
auth_request /oauth2/auth;
|
||||
error_page 401 =302 /oauth2/sign_in?rd=$scheme://$host$request_uri;
|
||||
proxy_pass http://{{ reverse_proxy_research_upstream_host }}:{{ reverse_proxy_research_api_port }};
|
||||
proxy_set_header Host $host;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $http_connection;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
}
|
||||
|
||||
+8
-32
@@ -91,34 +91,7 @@ host_body = {
|
||||
"block_exploits": True,
|
||||
"allow_websocket_upgrade": True,
|
||||
"advanced_config": spec["advanced_config"],
|
||||
"locations": [
|
||||
{
|
||||
"path": "/",
|
||||
"forward_scheme": spec["upstream_scheme"],
|
||||
"forward_host": spec["upstream_host"],
|
||||
"forward_port": spec["upstream_port"],
|
||||
"advanced_config": spec["root_location_advanced_config"],
|
||||
},
|
||||
{
|
||||
# backend API (gptr backend :8000 published as 8086), same IAP auth
|
||||
"path": "/api",
|
||||
"forward_scheme": spec["upstream_scheme"],
|
||||
"forward_host": spec["upstream_host"],
|
||||
"forward_port": spec["api_port"],
|
||||
"advanced_config": spec["root_location_advanced_config"] + "\nproxy_read_timeout 600s;\nproxy_send_timeout 600s;\n",
|
||||
},
|
||||
{
|
||||
# websocket endpoint of the harness (wss://…/ws), same IAP auth,
|
||||
# long-lived connection: no read timeout
|
||||
"path": "/ws",
|
||||
"forward_scheme": spec["upstream_scheme"],
|
||||
"forward_host": spec["upstream_host"],
|
||||
"forward_port": spec["api_port"],
|
||||
# NPM custom locations do NOT get the websocket upgrade headers —
|
||||
# add them explicitly, otherwise wss://…/ws fails
|
||||
"advanced_config": spec["root_location_advanced_config"] + "\nproxy_http_version 1.1;\nproxy_set_header Upgrade $http_upgrade;\nproxy_set_header Connection \"upgrade\";\nproxy_read_timeout 3600s;\nproxy_send_timeout 3600s;\n",
|
||||
},
|
||||
],
|
||||
"locations": [],
|
||||
}
|
||||
|
||||
if not host:
|
||||
@@ -126,12 +99,15 @@ if not host:
|
||||
assert st == 201, f"proxy-host create failed: {st} {host}"
|
||||
changed = True
|
||||
else:
|
||||
# PUT only the writable fields — sending the read object back (id,
|
||||
# created_on, owner_user_id, ...) is rejected with 400.
|
||||
# NPM 2.15.1 quirk: PUT does NOT regenerate the nginx conf (it even
|
||||
# deletes it) — only POST/create writes proxy_host/<id>.conf. So on drift
|
||||
# we delete and re-create the host (cert id stays).
|
||||
drift = any(host.get(k) != v for k, v in host_body.items())
|
||||
if drift:
|
||||
st, _ = req("PUT", f"/nginx/proxy-hosts/{host['id']}", host_body, token=token)
|
||||
assert st == 200, f"proxy-host update failed: {st}"
|
||||
st, _ = req("DELETE", f"/nginx/proxy-hosts/{host['id']}", token=token)
|
||||
assert st == 200, f"proxy-host delete failed: {st}"
|
||||
st, host = req("POST", "/nginx/proxy-hosts", host_body, token=token)
|
||||
assert st == 201, f"proxy-host recreate failed: {st} {host}"
|
||||
changed = True
|
||||
|
||||
print("CHANGED" if changed else "UNCHANGED")
|
||||
|
||||
+1
-2
@@ -5,6 +5,5 @@
|
||||
"upstream_port": {{ reverse_proxy_research_upstream_port | int }},
|
||||
"api_port": {{ reverse_proxy_research_api_port | int }},
|
||||
"letsencrypt_email": {{ reverse_proxy_research_letsencrypt_email | to_json }},
|
||||
"advanced_config": {{ reverse_proxy_research_advanced_config | to_json }},
|
||||
"root_location_advanced_config": {{ reverse_proxy_research_root_location_advanced_config | to_json }}
|
||||
"advanced_config": {{ reverse_proxy_research_advanced_config | to_json }}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user