M8-T3 Vorbereitung: Split-DNS research.ghostnet.selfhost.eu + Firewall-Port 8085 + NPM-vHost-Rolle

- CT 100: dns_pihole_hosts_records um research.ghostnet.selfhost.eu -> 10.0.0.10
  in allen 3 Inventaren + Rollendefault; live verifiziert (dig @10.0.0.14), site.yml konvergent
- KI-Server: gnmon_firewall_npm_only_ports um 8085 erweitert; monitor.yml deployt, idempotent changed=0
- CT 103: neue Rolle reverse_proxy_research_vhost (NPM-API 127.0.0.1:81, idempotent):
  LE-Cert + Proxy-Host research.* -> 10.0.0.90:8085 mit auth_request-advanced_config
  gegen oauth2-proxy (127.0.0.1:4180); NPM-Admin-Creds als /etc/nginx-proxy-manager/api.env (0600, Operator)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-17 15:06:24 +01:00
parent 73a8a59813
commit 8488a75b4d
11 changed files with 278 additions and 0 deletions
@@ -24,6 +24,8 @@ gnmon_firewall_dashboard_allowed_ip: 10.0.0.10
gnmon_firewall_npm_only_ports:
- 8080
- 8081
# GNAI-023 M8: GPT Researcher behind NPM + oauth2-proxy (IAP)
- 8085
# Monitoring APIs bind to 127.0.0.1 (GNMON-000 M5); deny non-loopback
# access to them anyway (defense in depth, GNMON-001 section 7).
@@ -34,6 +34,8 @@ dns_pihole_hosts_records:
- "10.0.0.10 mon.ghostnet.selfhost.eu"
# GNAI-001 M6: OpenWebUI via NPM (CT-103).
- "10.0.0.10 chat.ghostnet.selfhost.eu"
# GNAI-023 M8: GPT Researcher via NPM (CT-103) + oauth2-proxy.
- "10.0.0.10 research.ghostnet.selfhost.eu"
dns_pihole_timezone: Europe/Berlin
dns_pihole_database_max_db_days: 30
dns_pihole_secret_name: pihole_web_password
@@ -34,6 +34,8 @@ dns_pihole_hosts_records:
- "10.0.0.10 mon.ghostnet.selfhost.eu"
# GNAI-001 M6: OpenWebUI via NPM (CT-103).
- "10.0.0.10 chat.ghostnet.selfhost.eu"
# GNAI-023 M8: GPT Researcher via NPM (CT-103) + oauth2-proxy.
- "10.0.0.10 research.ghostnet.selfhost.eu"
dns_pihole_timezone: Europe/Berlin
dns_pihole_database_max_db_days: 30
dns_pihole_secret_name: pihole_web_password
@@ -34,6 +34,8 @@ dns_pihole_hosts_records:
- "10.0.0.10 mon.ghostnet.selfhost.eu"
# GNAI-001 M6: OpenWebUI via NPM (CT-103).
- "10.0.0.10 chat.ghostnet.selfhost.eu"
# GNAI-023 M8: GPT Researcher via NPM (CT-103) + oauth2-proxy.
- "10.0.0.10 research.ghostnet.selfhost.eu"
dns_pihole_timezone: Europe/Berlin
dns_pihole_database_max_db_days: 30
dns_pihole_secret_name: pihole_web_password
@@ -15,6 +15,8 @@ dns_pihole_hosts_records:
- "10.0.0.10 mon.ghostnet.selfhost.eu"
# GNAI-001 M6: OpenWebUI via NPM (CT-103).
- "10.0.0.10 chat.ghostnet.selfhost.eu"
# GNAI-023 M8: GPT Researcher via NPM (CT-103) + oauth2-proxy.
- "10.0.0.10 research.ghostnet.selfhost.eu"
dns_pihole_database_max_db_days: 30
dns_pihole_service_name: pihole.service
dns_pihole_quadlet_path: /etc/containers/systemd/pihole.container
@@ -24,4 +24,5 @@
- role: reverse_proxy_firewall
- role: reverse_proxy_npm
- role: reverse_proxy_oauth2proxy
- role: reverse_proxy_research_vhost
- role: reverse_proxy_fail2ban
@@ -0,0 +1,33 @@
# reverse_proxy_research_vhost
NPM-Proxy-Host `research.ghostnet.selfhost.eu` → `10.0.0.90:8085` (GPT
Researcher, M8-T4), geschützt durch oauth2-proxy via `auth_request`
(GNAI-023 M8-T3). Idempotent über die NPM-API (127.0.0.1:81), inkl. LE-Cert.
## Einmalig durch den Operator auf CT 103
NPM-Admin-Zugang als Datei (nie in Git):
```
install -d -m 0700 /etc/nginx-proxy-manager
install -m 0600 /dev/null /etc/nginx-proxy-manager/api.env
# eintragen:
# NPM_API_EMAIL=<admin-email der NPM-UI>
# NPM_API_PASSWORD=<admin-passwort>
```
## Danach
`site.yml` deployt/aktualisiert Cert + Proxy-Host idempotent (`changed=0` beim
zweiten Lauf; der Verify-Task erwartet `UNCHANGED`). Split-DNS-Record
`research.ghostnet.selfhost.eu → 10.0.0.10` kommt aus dem CT-100-Projekt
(`dns_pihole_hosts_records`).
## auth_request-Muster (advanced_config)
`auth_request`, `error_page 401` und `auth_request_set` liegen auf **server**-
Ebene (nginx erlaubt das und vererbt es an die generierte `location /`).
Nur `location = /oauth2/auth` ist `internal`; der Rest von `/oauth2/`
(sign_in/start/callback) bleibt extern erreichbar. Identität-Header
(X-Auth-Request-*) werden aktuell nicht an den Upstream durchgereicht —
GPT Researcher braucht sie nicht.
@@ -0,0 +1,44 @@
---
# NPM proxy host for the GPT Researcher harness behind the IAP
# (GNAI-023 M8-T3). Managed idempotently via the NPM API (127.0.0.1:81).
#
# NPM admin credentials are read from this root-only file on CT 103
# (created once by the operator, never in git):
# /etc/nginx-proxy-manager/api.env mode 0600, content:
# NPM_API_EMAIL=admin@example.com
# NPM_API_PASSWORD=...
reverse_proxy_research_npm_api: http://127.0.0.1:81/api
reverse_proxy_research_api_env_file: /etc/nginx-proxy-manager/api.env
reverse_proxy_research_domain: research.ghostnet.selfhost.eu
reverse_proxy_research_upstream_host: 10.0.0.90
reverse_proxy_research_upstream_port: 8085
reverse_proxy_research_upstream_scheme: http
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
# Injected at server level into the NPM proxy host's advanced config.
# auth_request/error_page/auth_request_set are valid at server level and are
# inherited by the generated location /. Only /oauth2/auth is internal; the
# rest of /oauth2/ (sign_in/start/callback) must stay externally reachable.
reverse_proxy_research_advanced_config: |
location /oauth2/ {
proxy_pass {{ reverse_proxy_research_iap_upstream }};
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 = /oauth2/auth {
internal;
proxy_pass {{ reverse_proxy_research_iap_upstream }}/oauth2/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Original-URL $scheme://$host$request_uri;
}
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;
@@ -0,0 +1,112 @@
#!/usr/bin/env python3
"""Idempotent NPM proxy-host + LE certificate for research.ghostnet.selfhost.eu
behind the oauth2-proxy IAP. Usage:
npm_research_vhost.py <npm_api_base> <api_env_file> <spec.json>
Prints CHANGED/UNCHANGED. stdlib only.
"""
import json
import sys
import urllib.error
import urllib.parse
import urllib.request
api, env_file, spec_file = sys.argv[1:4]
spec = json.load(open(spec_file))
env = {}
for line in open(env_file):
line = line.strip()
if line and not line.startswith("#") and "=" in line:
k, v = line.split("=", 1)
env[k.strip()] = v.strip()
email = env["NPM_API_EMAIL"]
password = env["NPM_API_PASSWORD"]
changed = False
def req(method, path, body=None, token=None):
url = f"{api}{path}"
data = None
headers = {}
if token:
headers["Authorization"] = f"Bearer {token}"
if body is not None:
data = json.dumps(body).encode()
headers["Content-Type"] = "application/json"
r = urllib.request.Request(url, data=data, headers=headers, method=method)
try:
with urllib.request.urlopen(r, timeout=30) as resp:
raw = resp.read()
return resp.status, json.loads(raw) if raw else None
except urllib.error.HTTPError as e:
raw = e.read()
try:
return e.code, json.loads(raw) if raw else None
except json.JSONDecodeError:
return e.code, raw[:300]
st, tok = req("POST", "/tokens", {"identity": email, "secret": password})
assert st == 200 and tok and tok.get("token"), f"npm token failed: {st} {tok}"
token = tok["token"]
domain = spec["domain"]
# --- 1) letsencrypt certificate ---
st, certs = req("GET", "/nginx/certificates", token=token)
assert st == 200, f"cert list failed: {st}"
cert = next((c for c in certs if domain in (c.get("domain_names") or [])), None)
if not cert:
st, cert = req("POST", "/nginx/certificates", {
"provider": "letsencrypt",
"domain_names": [domain],
"meta": {
"letsencrypt_email": spec["letsencrypt_email"],
"letsencrypt_agree": True,
},
}, token=token)
assert st == 201, f"cert create failed: {st} {cert}"
changed = True
cert_id = cert["id"]
else:
cert_id = cert["id"]
# --- 2) proxy host ---
st, hosts = req("GET", "/nginx/proxy-hosts", token=token)
assert st == 200, f"proxy-host list failed: {st}"
host = next((h for h in hosts if domain in (h.get("domain_names") or [])), None)
host_body = {
"domain_names": [domain],
"forward_scheme": spec["upstream_scheme"],
"forward_host": spec["upstream_host"],
"forward_port": spec["upstream_port"],
"access_list_id": 0,
"certificate_id": cert_id,
"ssl_forced": True,
"hsts_enabled": True,
"http2_support": True,
"block_exploits": True,
"allow_websocket_upgrade": True,
"advanced_config": spec["advanced_config"],
"locations": [],
}
if not host:
st, host = req("POST", "/nginx/proxy-hosts", host_body, token=token)
assert st == 201, f"proxy-host create failed: {st} {host}"
changed = True
else:
wanted = {k: host_body[k] for k in host_body}
drift = any(host.get(k) != v for k, v in wanted.items())
if drift:
merged = dict(host)
merged.update(wanted)
st, _ = req("PUT", f"/nginx/proxy-hosts/{host['id']}", merged, token=token)
assert st == 200, f"proxy-host update failed: {st}"
changed = True
print("CHANGED" if changed else "UNCHANGED")
@@ -0,0 +1,70 @@
---
- name: Check the NPM API credentials file (mode 0600)
ansible.builtin.stat:
path: "{{ reverse_proxy_research_api_env_file }}"
register: research_npm_api_env
- name: Fail with instructions when NPM API credentials are missing
ansible.builtin.fail:
msg: >-
{{ reverse_proxy_research_api_env_file }} missing or mode != 0600.
Create it once on CT 103 (root) with NPM_API_EMAIL / NPM_API_PASSWORD
of the NPM admin user; never in git.
when: >-
not research_npm_api_env.stat.exists
or research_npm_api_env.stat.mode != '0600'
- name: Stage the NPM vhost sync script
ansible.builtin.copy:
src: files/npm_research_vhost.py
dest: /tmp/npm_research_vhost.py
mode: "0600"
changed_when: false
when: not ansible_check_mode
- name: Render the vhost spec
ansible.builtin.template:
src: spec.json.j2
dest: /tmp/research_vhost_spec.json
mode: "0600"
changed_when: false
when: not ansible_check_mode
- name: Sync the research proxy host + LE cert idempotently via the NPM API
ansible.builtin.command:
argv:
- python3
- /tmp/npm_research_vhost.py
- "{{ reverse_proxy_research_npm_api }}"
- "{{ reverse_proxy_research_api_env_file }}"
- /tmp/research_vhost_spec.json
register: research_vhost_sync
changed_when: research_vhost_sync.stdout_lines | first == 'CHANGED'
when: not ansible_check_mode
no_log: true
- name: Verify the sync reports UNCHANGED on a second run (idempotence)
ansible.builtin.command:
argv:
- python3
- /tmp/npm_research_vhost.py
- "{{ reverse_proxy_research_npm_api }}"
- "{{ reverse_proxy_research_api_env_file }}"
- /tmp/research_vhost_spec.json
register: research_vhost_verify
changed_when: false
failed_when: >-
research_vhost_verify.rc != 0
or (research_vhost_verify.stdout_lines | first) != 'UNCHANGED'
when: not ansible_check_mode
no_log: true
- name: Remove the staged script and spec
ansible.builtin.file:
path: "/tmp/{{ item }}"
state: absent
loop:
- npm_research_vhost.py
- research_vhost_spec.json
changed_when: false
when: not ansible_check_mode
@@ -0,0 +1,8 @@
{
"domain": {{ reverse_proxy_research_domain | to_json }},
"upstream_scheme": {{ reverse_proxy_research_upstream_scheme | to_json }},
"upstream_host": {{ reverse_proxy_research_upstream_host | to_json }},
"upstream_port": {{ reverse_proxy_research_upstream_port | int }},
"letsencrypt_email": {{ reverse_proxy_research_letsencrypt_email | to_json }},
"advanced_config": {{ reverse_proxy_research_advanced_config | to_json }}
}