Files
mtusi2026lab7/infra/otel/prometheus-gateway.cfg
T

67 lines
4.2 KiB
INI
Raw 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.
# TLS-шлюз Prometheus (сервис prometheus-gateway, лаба 7, перенос
# telemetry-backends-tls; правила — infra/otel/AGENTS.md, «TLS хранилищ
# телеметрии»). Родной TLS Prometheus (--web.config.file) CRL не знает, пускает
# сертификат с несколькими именами, а busybox wget его healthcheck сертификата не
# предъявит — поэтому шлюз, как у Loki и Tempo:
# Grafana (grafana-client) ──mTLS──→ prometheus-gateway :9090
# ──loopback──→ Prometheus 127.0.0.1:19090
# Шлюз владеет сетевым пространством Prometheus (network_mode:
# service:prometheus-gateway): его порт из сетей стенда недоступен; себя Prometheus
# забирает и проверяется healthcheck по этому loopback, scrape Collector, Loki и
# Tempo — исходящие mTLS из пространства. Файлы — secrets compose, читаются при
# старте: новый 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
option http-ignore-probes
# Prometheus — на loopback: остановлен — 503 сразу, без повторов
timeout connect 250ms
retries 0
# больше срока запроса прокси 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 (вся строка 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 }
# первым: роутер Prometheus сравнивает раскодированный и исправленный путь (%XX,
# //, сегменты . и .., регистр — 307) — такой путь отвергается до прав
acl unsafe_path path_sub % //
acl unsafe_path path_reg /[.][.]?(/|$)
http-request deny deny_status 403 hdr X-Gateway-Refused prometheus-gateway if unsafe_path
# права: Grafana — GET и POST чтения, явный список. Административного API, remote
# write и приёма OTLP (флаги их и так выключают — шлюз страхует от смены флагов),
# /federate, /-/reload, /-/quit, /metrics — ни у кого
acl id_grafana ssl_c_san -m str DNS:grafana
acl read_path path_reg ^/api/v1/(query|query_range|query_exemplars|format_query|parse_query|series|labels|label/[^/]+/values|metadata|targets|targets/metadata|scrape_pools|rules|alerts|alertmanagers|status/(buildinfo|config|flags|runtimeinfo|tsdb|walreplay))$
http-request allow if id_grafana METH_GET read_path
http-request allow if id_grafana METH_POST read_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