Files
buryan-infra/ops/n8n/nginx_patch2.py
buryan-agent 23fcd27a01 n8n: единый вход через Authentik, второй пароль убран
Внутренний логин n8n отключить штатно нельзя (OIDC/SAML — платные).
Сделан авто-вход: nginx видит отсутствие cookie n8n-auth и отправляет на
/hub-login; там auth_request проверяет сессию Authentik, сервис n8n-auto-login
логинится служебной учёткой и отдаёт браузеру готовую cookie n8n-auth.

Маршруты продублированы на VPS — домен указывает туда, а не на домашний сервер
(это выяснилось при отладке).

Сервис слушает только 127.0.0.1, cookie HttpOnly/Secure/SameSite=Lax.
Бэкапы конфигов nginx сохранены.
2026-10-20 23:52:39 +03:00

32 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Добавляет автоматический редирект с / на /hub-login, если нет сессии n8n."""
P = "/etc/nginx/conf.d/buryans-all.conf"
src = open(P, encoding="utf-8").read()
if "n8n-auth" in src:
print("уже есть")
raise SystemExit(0)
start = src.find("server_name n8n.buryans.ru;")
loc = src.find("location = /hub-login {", start)
if loc < 0:
print("нет /hub-login — сначала основной патч")
raise SystemExit(1)
insert = '''location = / {
if ($http_cookie !~* "n8n-auth=") {
return 302 /hub-login;
}
proxy_pass http://192.168.1.108:9105;
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;
proxy_read_timeout 3600s;
}
'''
src = src[:loc] + insert + src[loc:]
open(P, "w", encoding="utf-8").write(src)
print("добавлен location = / с проверкой cookie")