feat: put telemetry backends, LB metrics and Grafana behind mTLS gateways

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 10:20:27 +03:00
co-authored by Claude Opus 5.5
parent 8349a454db
commit 1722fb0c35
40 changed files with 3915 additions and 279 deletions
+67
View File
@@ -0,0 +1,67 @@
# TLS-шлюз Prometheus (сервис prometheus-gateway, change telemetry-backends-tls,
# design, решения 2–4, 10; правила — .claude/rules/telemetry.md и tls.md).
# Образ — HAProxy балансировщика. Родной TLS Prometheus (--web.config.file)
# с client_allowed_sans пускает сертификат с несколькими именами, CRL не
# знает, а busybox wget healthcheck сертификата не предъявит — поэтому шлюз:
# Grafana (grafana-client) ──mTLS──→ prometheus-gateway :9090
# ──loopback (закрытый hop)──→ Prometheus 127.0.0.1:19090
# Шлюз владеет сетевым пространством Prometheus (network_mode:
# service:prometheus-gateway): свой порт Prometheus из сетей стенда
# недоступен; собственные метрики и healthcheck Prometheus — по этому
# loopback, scrape Collector, Loki и Tempo — исходящие mTLS из пространства.
# Файлы — secrets compose (CA, CRL, prometheus.pem), читаются при старте: новый
# CRL — docker compose restart prometheus-gateway (с ним — Prometheus).
global
log stdout format raw local0 info
nbthread 1
maxconn 256
defaults
mode http
log global
option dontlog-normal
# соединение без запроса, закрытое клиентом, строк не даёт; отказы
# рукопожатия и identity пишутся (проба apply)
option http-ignore-probes
# Prometheus — на loopback: остановлен — 503 сразу, без повторов
timeout connect 250ms
retries 0
# больше срока запроса proxy Grafana (30 с)
timeout server 60s
timeout client 60s
timeout http-keep-alive 60s
timeout http-request 10s
# health шлюза — только loopback, без обращения к Prometheus
frontend health
bind 127.0.0.1:8405
no log
monitor-uri /ready
http-request deny deny_status 404
frontend prometheus_in
bind :9090 ssl crt /run/secrets/prometheus.pem ca-file /run/secrets/ca.crt crl-file /run/secrets/crl.pem verify required ssl-min-ver TLSv1.3 alpn http/1.1
# allowlist порта — DNS SAN строки grafana-client infra/pki/identities.conf;
# вся строка SAN равна одному имени
tcp-request session set-var(sess.refusal) str(identity_not_allowed) unless { ssl_c_san -m str DNS:grafana }
tcp-request session reject if { var(sess.refusal) -m found }
# права (решение 4): Grafana — GET и POST HTTP API /api/v1/ (запросы,
# метки, серии, цели, правила, оповещения, status), кроме
# административного API, remote write и приёма OTLP (флаги их и так
# выключают — шлюз страхует от смены флагов). /federate, /-/reload,
# /-/quit, /metrics — ни у кого
acl id_grafana ssl_c_san -m str DNS:grafana
acl api_path path_beg /api/v1/
acl closed_path path_beg /api/v1/admin/ /api/v1/write /api/v1/otlp/
http-request allow if id_grafana METH_GET api_path !closed_path
http-request allow if id_grafana METH_POST api_path !closed_path
http-request deny deny_status 403 hdr X-Gateway-Refused prometheus-gateway
log-format "prometheus-gateway %ci:%cp san=%[ssl_c_san] tls=%[ssl_fc_protocol] %HM %HPO status=%ST bytes=%B term=%tsc backend=%b/%s time=%Ta"
error-log-format "prometheus-gateway-refused %ci:%cp san=%[ssl_c_san] tls=%[ssl_fc_protocol] reason=%[var(sess.refusal)] conn_err=%[fc_err_str] ssl_err=%[ssl_fc_err_str] cert_err=%[ssl_c_err,x509_v_err_str] ca_err=%[ssl_c_ca_err,x509_v_err_str] term=%tsc"
default_backend prometheus
# Prometheus в том же сетевом пространстве: открытый текст только на loopback
backend prometheus
option abortonclose
server prometheus 127.0.0.1:19090