From abd815be60f7a0580ef506cc8dc8461ec27af3b2 Mon Sep 17 00:00:00 2001 From: spektr Date: Mon, 16 Nov 2026 01:31:27 +0100 Subject: [PATCH] M8 Vorbereitung: Rolle reverse_proxy_oauth2proxy (oauth2-proxy v7.15.5 auf CT 103) - Quadlet Network=host, bind 127.0.0.1:4180 (kein publish; LAN/WAN blocked, per Task verifiziert) - Keycloak-OIDC (provider oidc, issuer realm Ghost.net, client gnai-research), cookie/client secrets als Podman-Secrets, Haertung: cookie secure/httponly/lax, 24h expiry, reverse-proxy, set-xauthrequest, allowed-group via groups-claim, whitelist-domain, skip-auth-regex ^/ping$ - image digest placeholder (Pin nach erstem Pull), site.yml um Rolle erweitert - GNAI-023 M8-T1: exakte Keycloak-Admin-UI-Schritte fuer Client gnai-research + Rolle gnai-research-user Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- .../ai/GNAI-023-PLAN_GPT-Researcher-IAP.md | 2 +- .../ansible/playbooks/site.yml | 1 + .../roles/reverse_proxy_oauth2proxy/README.md | 28 +++++ .../defaults/main.yml | 45 ++++++++ .../handlers/main.yml | 11 ++ .../reverse_proxy_oauth2proxy/tasks/main.yml | 104 ++++++++++++++++++ .../templates/oauth2-proxy.container.j2 | 50 +++++++++ 7 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/README.md create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/defaults/main.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/handlers/main.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/tasks/main.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/templates/oauth2-proxy.container.j2 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 725b428..9036594 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 @@ -124,7 +124,7 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy | # | Paket | Ziel | Wo | | --- | --- | --- | --- | -| M8-T1 | Keycloak-Client `gnai-research` (confidential, Redirect `https://research.ghostnet.selfhost.eu/oauth2/callback`, Scopes openid email profile groups) + Realm-Rolle `gnai-research-user` + Mapper auf `groups`-Claim; Secret als Podman-Secret | CT 102 (Ansible oder Admin-UI) | Keycloak | +| M8-T1 | Keycloak-Client `gnai-research` + Realm-Rolle + Claim-Mapper; Secret als Podman-Secret. **Betreiberschritte (Admin-UI `https://auth.ghostnet.selfhost.eu`, Realm Ghost.net):** 1) Realm Roles → Create role `gnai-research-user`. 2) Clients → Create client: id `gnai-research`, **confidential**, Standard Flow, Valid Redirect URIs `https://research.ghostnet.selfhost.eu/oauth2/callback`, Web Origins `https://research.ghostnet.selfhost.eu`. 3) Client Scopes `gnai-research-dedicated` anlegen mit Mapper „realm roles" (claim name `groups`, add to access/id token ON) — oder `groups` direkt. 4) Secret kopieren → auf CT 103: `printf '%s' '' \| podman secret create oauth2-proxy-client-secret -`. 5) User `ghost` die Rolle `gnai-research-user` zuweisen (Users → Role Mappings). | CT 102 (Admin-UI) + CT 103 (Secret) | Keycloak | | M8-T2 | oauth2-proxy v7.15.5 (quay.io, digest-gepinnt) als Quadlet auf CT 103 in eigenem Podman-Netz mit NPM, **kein** publish; Env: provider `oidc`, issuer, client-id/secret + cookie-secret als Podman-Secrets, `--email-domain`, `--whitelist-domain=.ghostnet.selfhost.eu`, `--allowed-group=gnai-research-user`, `--oidc-groups-claim=groups`, `--skip-auth-regex=^/ping$`, `--reverse-proxy=true`, `--set-xauthrequest` | CT 103, Rolle im CT-103-Ansible-Projekt | IAP | | M8-T3 | NPM-vHost `research.ghostnet.selfhost.eu` (LE-TLS, Force SSL) mit Advanced-Snippet `auth_request /oauth2/auth` + interne `location /oauth2/`; Split-DNS-Record auf CT 100; NPM-API via CT-103-Ansible | CT 103 + CT 100 | Ingress | | M8-T4 | GPT Researcher (digest-gepinnt) als Quadlet auf `ghostnet-ki` im Production-Netz, Port `10.0.0.90:8085` (Firewall: nur NPM); Env: `OPENAI_BASE_URL=http://llama-cpp:8080/v1`, `OPENAI_API_KEY`=Placeholder-Secret, `FAST_LLM`/`SMART_LLM`=Production-Alias, Search via SearXNG (custom retriever, `SEARXNG_URL=http://searxng:8080`) | `llm-server/llm/ansible` (neue Rolle `gpt_researcher`, Playbook `research.yml`) | Harness | diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml index 268f418..0bcd1a6 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml @@ -23,4 +23,5 @@ - role: podman_runtime - role: reverse_proxy_firewall - role: reverse_proxy_npm + - role: reverse_proxy_oauth2proxy - role: reverse_proxy_fail2ban diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/README.md b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/README.md new file mode 100644 index 0000000..f550264 --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/README.md @@ -0,0 +1,28 @@ +# reverse_proxy_oauth2proxy + +oauth2-proxy v7.15.5 als Identity-Aware Proxy auf CT 103 (GNAI-023, Roadmap +M8). Schützt `research.ghostnet.selfhost.eu` (GPT Researcher) über nginx +`auth_request` gegen Keycloak-OIDC (Realm Ghost.net, Client `gnai-research`). + +- **Netzwerk:** `Network=host`, gebunden auf `127.0.0.1:4180` (kein + `PublishPort`) — von LAN/WAN nicht direkt erreichbar; NPM erreicht den + IAP via `auth_request` auf `http://127.0.0.1:4180/oauth2/auth` (202 = ok, + 401 = an Keycloak weiterleiten). Verifiziert durch Task „LAN blocked". +- **Secrets** als rootful Podman-Secrets, nie in Git: + - `oauth2-proxy-cookie-secret` — random 32 B, wird von der Rolle auto-legt. + - `oauth2-proxy-client-secret` — Secret des Keycloak-Clients `gnai-research` + (Operator legt Client in Keycloak an, dann + `printf '%s' '' | podman secret create oauth2-proxy-client-secret -`). +- **Image** digest-gepinnt; beim ersten Rollout Tag pullen, Digest ermitteln + (`podman image inspect --format '{{.Digest}}'`) und in + `reverse_proxy_oauth2proxy_image_ref` eintragen. +- **Härtung** (Env im Quadlet): cookie secure/httponly/samesite=lax, + 24 h Expiry, Session-Store cookie, `--reverse-proxy` (nur loopback-Vertrauen), + `--set-xauthrequest`, kein Access-Token-Pass-Through, `--skip-provider-button`, + `--whitelist-domain=.ghostnet.selfhost.eu`, `--allowed-group=gnai-research-user` + über `--oidc-groups-claim=groups`, `--skip-auth-regex=^/ping$`. +- **NPM-Seite** (M8-T3): vHost `research.ghostnet.selfhost.eu` mit Advanced-Snippet: + interne `location /oauth2/` → `proxy_pass http://127.0.0.1:4180;`, + `location / { auth_request /oauth2/auth; error_page 401 =302 /oauth2/sign_in?rd=$request_uri; … }`, + `location = /oauth2/auth { internal; proxy_pass …; proxy_pass_request_body off; + proxy_set_header Content-Length ""; proxy_set_header X-Original-URI $request_uri; }`. diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/defaults/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/defaults/main.yml new file mode 100644 index 0000000..1ef819b --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/defaults/main.yml @@ -0,0 +1,45 @@ +--- +# oauth2-proxy (Identity-Aware Proxy) for the research harness route +# (GNAI-023, Roadmap M8). Runs on CT 103 with Network=host, bound to +# 127.0.0.1 only — NPM's generated nginx reaches it via auth_request on +# http://127.0.0.1:4180/oauth2/auth. No published port: not reachable from +# LAN/WAN directly. +# +# Image: pin by digest after the first pull on CT 103: +# podman pull quay.io/oauth2-proxy/oauth2-proxy:v7.15.5 +# podman image inspect ... --format '{{.Digest}}' +reverse_proxy_oauth2proxy_image: quay.io/oauth2-proxy/oauth2-proxy +reverse_proxy_oauth2proxy_image_tag: v7.15.5 +reverse_proxy_oauth2proxy_image_ref: "{{ reverse_proxy_oauth2proxy_image }}@sha256:REPLACE_WITH_PINNED_DIGEST" + +reverse_proxy_oauth2proxy_container_name: oauth2-proxy +reverse_proxy_oauth2proxy_service_name: oauth2-proxy.service +reverse_proxy_oauth2proxy_quadlet_path: /etc/containers/systemd/oauth2-proxy.container +reverse_proxy_oauth2proxy_quadlet_mode: "0644" + +reverse_proxy_oauth2proxy_http_address: 127.0.0.1:4180 +reverse_proxy_oauth2proxy_metrics_address: 127.0.0.1:4181 + +# Keycloak (CT 102, realm Ghost.net) as OIDC IdP. Client `gnai-research` +# (confidential) must exist first — created by the operator in the Keycloak +# admin UI (GNAI-023 M8-T1); its secret goes into the Podman secret below. +reverse_proxy_oauth2proxy_provider: oidc +reverse_proxy_oauth2proxy_oidc_issuer_url: https://auth.ghostnet.selfhost.eu/realms/Ghost.net +reverse_proxy_oauth2proxy_client_id: gnai-research +reverse_proxy_oauth2proxy_redirect_url: https://research.ghostnet.selfhost.eu/oauth2/callback +reverse_proxy_oauth2proxy_scopes: "openid email profile groups" + +# Authorization: Keycloak realm role mapped onto the `groups` claim. +reverse_proxy_oauth2proxy_allowed_group: gnai-research-user +reverse_proxy_oauth2proxy_oidc_groups_claim: groups +reverse_proxy_oauth2proxy_email_domains: "*" +reverse_proxy_oauth2proxy_whitelist_domain: .ghostnet.selfhost.eu +reverse_proxy_oauth2proxy_skip_auth_regex: "^/ping$" + +reverse_proxy_oauth2proxy_cookie_expire: 24h + +# Podman secrets (rootful store on CT 103), never in git: +# podman secret create oauth2-proxy-cookie-secret - (random 32 bytes, auto-created by this role) +# podman secret create oauth2-proxy-client-secret - (Keycloak client secret of gnai-research, operator) +reverse_proxy_oauth2proxy_cookie_secret_name: oauth2-proxy-cookie-secret +reverse_proxy_oauth2proxy_client_secret_name: oauth2-proxy-client-secret diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/handlers/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/handlers/main.yml new file mode 100644 index 0000000..2d245e5 --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/handlers/main.yml @@ -0,0 +1,11 @@ +--- +- name: Daemon reload CT 103 + ansible.builtin.command: + argv: [systemctl, daemon-reload] + changed_when: false + when: not ansible_check_mode + +- name: Restart oauth2-proxy unit + ansible.builtin.command: + argv: [systemctl, restart, "{{ reverse_proxy_oauth2proxy_service_name }}"] + when: not ansible_check_mode diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/tasks/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/tasks/main.yml new file mode 100644 index 0000000..16e0212 --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/tasks/main.yml @@ -0,0 +1,104 @@ +--- +- name: Verify oauth2-proxy role declarations + ansible.builtin.assert: + that: + - reverse_proxy_oauth2proxy_image_ref is match('^quay\.io/oauth2-proxy/oauth2-proxy@sha256:[0-9a-f]{64}$') + - reverse_proxy_oauth2proxy_http_address is match('^127\.0\.0\.1:') + fail_msg: >- + oauth2-proxy must be digest-pinned and bound to loopback only. + Pin: podman pull quay.io/oauth2-proxy/oauth2-proxy:v7.15.5, then + podman image inspect --format '{{ '{{' }}.Digest{{ '}}' }}' . + +- name: Check whether the oauth2-proxy cookie secret exists + ansible.builtin.command: + argv: [podman, secret, exists, "{{ reverse_proxy_oauth2proxy_cookie_secret_name }}"] + register: oauth2proxy_cookie_secret_exists + changed_when: false + failed_when: oauth2proxy_cookie_secret_exists.rc not in [0, 1] + check_mode: false + +- name: Create the cookie secret (random 32 bytes, host-local only) + ansible.builtin.shell: | + set -euo pipefail + head -c 32 /dev/urandom | base64 | podman secret create {{ reverse_proxy_oauth2proxy_cookie_secret_name }} - + args: + executable: /bin/bash + when: oauth2proxy_cookie_secret_exists.rc == 1 + no_log: true + +- name: Check whether the Keycloak client secret exists + # Created by the operator from the Keycloak client `gnai-research` + # (GNAI-023 M8-T1): podman secret create oauth2-proxy-client-secret - + ansible.builtin.command: + argv: [podman, secret, exists, "{{ reverse_proxy_oauth2proxy_client_secret_name }}"] + register: oauth2proxy_client_secret_exists + changed_when: false + failed_when: false + check_mode: false + +- name: Fail with instructions when the Keycloak client secret is missing + ansible.builtin.fail: + msg: >- + Podman secret {{ reverse_proxy_oauth2proxy_client_secret_name }} missing. + Create the Keycloak client `gnai-research` first (GNAI-023 M8-T1), then: + printf '%s' '' | podman secret create {{ reverse_proxy_oauth2proxy_client_secret_name }} - + when: oauth2proxy_client_secret_exists.rc != 0 + +- name: Check whether the pinned oauth2-proxy image is in the store + ansible.builtin.command: + argv: [podman, image, exists, "{{ reverse_proxy_oauth2proxy_image_ref }}"] + register: oauth2proxy_image_present + changed_when: false + failed_when: oauth2proxy_image_present.rc not in [0, 1] + check_mode: false + +- name: Pull the pinned oauth2-proxy image + ansible.builtin.command: + argv: [podman, pull, "{{ reverse_proxy_oauth2proxy_image_ref }}"] + when: + - not ansible_check_mode + - oauth2proxy_image_present.rc != 0 + +- name: Render the oauth2-proxy quadlet + ansible.builtin.template: + src: oauth2-proxy.container.j2 + dest: "{{ reverse_proxy_oauth2proxy_quadlet_path }}" + mode: "{{ reverse_proxy_oauth2proxy_quadlet_mode }}" + notify: + - Daemon reload CT 103 + - Restart oauth2-proxy unit + +- name: Read the current state of the oauth2-proxy unit + ansible.builtin.command: + argv: [systemctl, is-active, "{{ reverse_proxy_oauth2proxy_service_name }}"] + register: oauth2proxy_unit_state + changed_when: false + failed_when: oauth2proxy_unit_state.rc not in [0, 3] + check_mode: false + +- name: Start the oauth2-proxy unit + ansible.builtin.command: + argv: [systemctl, start, "{{ reverse_proxy_oauth2proxy_service_name }}"] + when: + - not ansible_check_mode + - oauth2proxy_unit_state.rc != 0 + +- name: Wait for the oauth2-proxy ping endpoint (loopback only) + ansible.builtin.uri: + url: "http://{{ reverse_proxy_oauth2proxy_http_address }}/ping" + status_code: 200 + timeout: 5 + register: oauth2proxy_ping + retries: 12 + delay: 5 + until: oauth2proxy_ping.status == 200 + when: not ansible_check_mode + +- name: Verify the IAP is NOT reachable from the LAN address + # The quadlet binds 127.0.0.1 only; a connect to 10.0.0.10:4180 must fail. + ansible.builtin.command: + argv: [sh, -c, "curl -s -o /dev/null --max-time 3 http://10.0.0.10:4180/ping && exit 1 || exit 0"] + register: oauth2proxy_lan_blocked + changed_when: false + failed_when: oauth2proxy_lan_blocked.rc != 0 + when: not ansible_check_mode diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/templates/oauth2-proxy.container.j2 b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/templates/oauth2-proxy.container.j2 new file mode 100644 index 0000000..5181fec --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_oauth2proxy/templates/oauth2-proxy.container.j2 @@ -0,0 +1,50 @@ +[Unit] +Description=oauth2-proxy identity-aware proxy (GNAI-023 M8, Keycloak OIDC) +After=network-online.target +Wants=network-online.target + +[Container] +Image={{ reverse_proxy_oauth2proxy_image_ref }} +Pull=never +ContainerName={{ reverse_proxy_oauth2proxy_container_name }} +# host network, but bound to loopback only (see OAUTH2_PROXY_HTTP_ADDRESS): +# no PublishPort, so the IAP is unreachable from LAN/WAN; NPM reaches it via +# auth_request on 127.0.0.1:4180. +Network=host +Secret={{ reverse_proxy_oauth2proxy_client_secret_name }},type=env,target=OAUTH2_PROXY_CLIENT_SECRET +Secret={{ reverse_proxy_oauth2proxy_cookie_secret_name }},type=env,target=OAUTH2_PROXY_COOKIE_SECRET +Environment=OAUTH2_PROXY_PROVIDER={{ reverse_proxy_oauth2proxy_provider }} +Environment=OAUTH2_PROXY_OIDC_ISSUER_URL={{ reverse_proxy_oauth2proxy_oidc_issuer_url }} +Environment=OAUTH2_PROXY_CLIENT_ID={{ reverse_proxy_oauth2proxy_client_id }} +Environment=OAUTH2_PROXY_REDIRECT_URL={{ reverse_proxy_oauth2proxy_redirect_url }} +Environment=OAUTH2_PROXY_SCOPE={{ reverse_proxy_oauth2proxy_scopes }} +Environment=OAUTH2_PROXY_HTTP_ADDRESS={{ reverse_proxy_oauth2proxy_http_address }} +Environment=OAUTH2_PROXY_METRICS_ADDRESS={{ reverse_proxy_oauth2proxy_metrics_address }} +# upstream is never used directly; nginx auth_request only asks /oauth2/auth +Environment=OAUTH2_PROXY_UPSTREAM=static://200 +# behind NPM: trust X-Forwarded-* from loopback only (reverse-proxy mode) +Environment=OAUTH2_PROXY_REVERSE_PROXY=true +Environment=OAUTH2_PROXY_SET_XAUTHREQUEST=true +Environment=OAUTH2_PROXY_PASS_ACCESS_TOKEN=false +Environment=OAUTH2_PROXY_PASS_AUTHORIZATION_HEADER=false +Environment=OAUTH2_PROXY_SET_AUTHORIZATION_HEADER=false +# hardening +Environment=OAUTH2_PROXY_COOKIE_SECURE=true +Environment=OAUTH2_PROXY_COOKIE_HTTPONLY=true +Environment=OAUTH2_PROXY_COOKIE_SAMESITE=lax +Environment=OAUTH2_PROXY_COOKIE_EXPIRE={{ reverse_proxy_oauth2proxy_cookie_expire }} +Environment=OAUTH2_PROXY_SESSION_STORE_TYPE=cookie +Environment=OAUTH2_PROXY_SKIP_PROVIDER_BUTTON=true +Environment=OAUTH2_PROXY_EMAIL_DOMAINS={{ reverse_proxy_oauth2proxy_email_domains }} +Environment=OAUTH2_PROXY_WHITELIST_DOMAIN={{ reverse_proxy_oauth2proxy_whitelist_domain }} +Environment=OAUTH2_PROXY_ALLOWED_GROUP={{ reverse_proxy_oauth2proxy_allowed_group }} +Environment=OAUTH2_PROXY_OIDC_GROUPS_CLAIM={{ reverse_proxy_oauth2proxy_oidc_groups_claim }} +Environment=OAUTH2_PROXY_SKIP_AUTH_REGEX={{ reverse_proxy_oauth2proxy_skip_auth_regex }} + +[Service] +Restart=on-failure +RestartSec=5 +TimeoutStartSec=120 + +[Install] +WantedBy=multi-user.target