diff --git a/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md b/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md index 639651b..76e68a1 100644 --- a/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md +++ b/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md @@ -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/.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. diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/defaults/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/defaults/main.yml index 1a85e77..5f68bdc 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/defaults/main.yml +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/defaults/main.yml @@ -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; + } diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/files/npm_research_vhost.py b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/files/npm_research_vhost.py index b3050dd..e3bd459 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/files/npm_research_vhost.py +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/files/npm_research_vhost.py @@ -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/.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") diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/templates/spec.json.j2 b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/templates/spec.json.j2 index a153a51..393cee5 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/templates/spec.json.j2 +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_research_vhost/templates/spec.json.j2 @@ -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 }} }