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
+222 -13
View File
@@ -845,8 +845,10 @@ services:
- api
healthcheck:
# healthy — через LB можно обслужить запрос: /lb/ready отвечает 200,
# пока есть хотя бы одна готовая реплика. curl в образе нет, bash есть
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8404 && printf 'GET /lb/ready HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
# пока есть хотя бы одна готовая реплика. curl в образе нет, bash есть.
# С change telemetry-backends-tls — loopback-слушатель статистики
# 127.0.0.1:8405 (порт метрик :8404 — только mTLS для Collector)
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8405 && printf 'GET /lb/ready HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
interval: 5s
timeout: 3s
retries: 3
@@ -925,7 +927,10 @@ services:
memory: 64M
# OTel Collector contrib: OTLP/HTTP от api, worker и relay через шлюз
# otel-gateway, метрики для scrape и экспорт в Loki и Tempo. Секретов нет. В
# otel-gateway, метрики для scrape и экспорт в Loki и Tempo. Из секретов —
# только свои файлы PKI (change telemetry-backends-tls, design, решение 6):
# CA стенда и клиентский leaf otel-collector-client (экспорт в Loki и Tempo
# и scrape порта метрик LB по mTLS); CRL ему не нужен (клиент). В
# образе нет ни оболочки, ни HTTP-клиента: healthcheck нет, живость — цель
# otel-collector в Prometheus. С change telemetry-mtls (design, решение 3)
# работает в сетевом пространстве шлюза: своих сетей и алиасов нет, приёмник
@@ -948,6 +953,10 @@ services:
read_only: true
bind:
create_host_path: false
secrets:
- ca.crt
- otel-collector-client.crt
- otel-collector-client.key
network_mode: service:otel-gateway
depends_on:
otel-gateway:
@@ -960,12 +969,147 @@ services:
cpus: "0.5"
memory: 256M
# TLS-шлюзы хранилищ телеметрии (change telemetry-backends-tls, design,
# решения 2–4, 10): образ LB (тег и digest те же), конфигурации
# infra/otel/<хранилище>-gateway.cfg. Принимают только TLS 1.3 с
# сертификатом клиента CA стенда и CRL, пускают на порт только identity его
# allowlist (DNS SAN: otel-collector, grafana, prometheus) с правами по
# методу и пути (запрос вне прав — 403 шлюза, хранилище его не видит).
# Каждый владеет сетевым пространством своего хранилища: алиас хранилища в
# сети telemetry, хранилище слушает только loopback (закрытый hop). Из
# секретов — только свои файлы PKI (CA, CRL, пара своей identity), читаются
# при старте: новый CRL — docker compose restart <шлюз> (с ним —
# хранилище). Health — loopback :8405 без проверки хранилища. Портов наружу
# нет. Рестарт шлюза политикой Docker или пересоздание одного шлюза
# оставляют хранилище без сети — runbook TelemetryTargetDown
loki-gateway:
image: haproxy:3.4.6-trixie@sha256:e273915691a8eab3f105bf3e39fd4c29a4ecf334e33421903b5589d25e14db26
restart: unless-stopped
environment:
OPENSSL_CONF: /usr/local/etc/haproxy/openssl.cnf
networks:
telemetry:
aliases:
- loki
secrets:
- ca.crt
- crl.pem
- loki.pem
volumes:
- type: bind
source: ./infra/otel/loki-gateway.cfg
target: /usr/local/etc/haproxy/haproxy.cfg
read_only: true
bind:
create_host_path: false
- type: bind
source: ./infra/haproxy/openssl.cnf
target: /usr/local/etc/haproxy/openssl.cnf
read_only: true
bind:
create_host_path: false
healthcheck:
# healthy — шлюз загрузил конфигурацию и файлы TLS; Loki не проверяется
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8405 && printf 'GET /ready HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
start_interval: 1s
deploy:
resources:
limits:
# nbthread 1, maxconn 256; пик — evidence/telemetry/budget.md
cpus: "0.25"
memory: 64M
tempo-gateway:
image: haproxy:3.4.6-trixie@sha256:e273915691a8eab3f105bf3e39fd4c29a4ecf334e33421903b5589d25e14db26
restart: unless-stopped
environment:
OPENSSL_CONF: /usr/local/etc/haproxy/openssl.cnf
networks:
telemetry:
aliases:
- tempo
secrets:
- ca.crt
- crl.pem
- tempo.pem
volumes:
- type: bind
source: ./infra/otel/tempo-gateway.cfg
target: /usr/local/etc/haproxy/haproxy.cfg
read_only: true
bind:
create_host_path: false
- type: bind
source: ./infra/haproxy/openssl.cnf
target: /usr/local/etc/haproxy/openssl.cnf
read_only: true
bind:
create_host_path: false
healthcheck:
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8405 && printf 'GET /ready HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
start_interval: 1s
deploy:
resources:
limits:
cpus: "0.25"
memory: 64M
prometheus-gateway:
image: haproxy:3.4.6-trixie@sha256:e273915691a8eab3f105bf3e39fd4c29a4ecf334e33421903b5589d25e14db26
restart: unless-stopped
environment:
OPENSSL_CONF: /usr/local/etc/haproxy/openssl.cnf
networks:
telemetry:
aliases:
- prometheus
secrets:
- ca.crt
- crl.pem
- prometheus.pem
volumes:
- type: bind
source: ./infra/otel/prometheus-gateway.cfg
target: /usr/local/etc/haproxy/haproxy.cfg
read_only: true
bind:
create_host_path: false
- type: bind
source: ./infra/haproxy/openssl.cnf
target: /usr/local/etc/haproxy/openssl.cnf
read_only: true
bind:
create_host_path: false
healthcheck:
test: ["CMD", "bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/8405 && printf 'GET /ready HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
interval: 5s
timeout: 3s
retries: 3
start_period: 10s
start_interval: 1s
deploy:
resources:
limits:
cpus: "0.25"
memory: 64M
# Prometheus — метрики: scrape Collector и собственных метрик конвейера;
# срок и предел объёма хранения — флаги. Без remote write, OTLP, admin API и
# lifecycle. Правила записи и оповещения — файл rules.yml (design change
# slo-alerts, решения 1, 3, 4); доставки оповещений наружу нет. Время начала
# cumulative-рядов экспортёра Collector (protobuf) — ноль в момент начала
# ряда нового процесса (решение 6)
# ряда нового процесса (решение 6). С change telemetry-backends-tls — в
# сетевом пространстве шлюза prometheus-gateway, слушает только
# 127.0.0.1:19090; scrape Collector, Loki и Tempo — mTLS с leaf
# prometheus-client (свои файлы PKI — единственные секреты)
prometheus:
image: prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2
restart: unless-stopped
@@ -975,6 +1119,8 @@ services:
- --storage.tsdb.retention.time=7d
- --storage.tsdb.retention.size=1GB
- --enable-feature=created-timestamp-zero-ingestion
# только loopback пространства шлюза: :9090 в сеть выводит шлюз
- --web.listen-address=127.0.0.1:19090
environment:
GOMEMLIMIT: 300MiB
volumes:
@@ -992,11 +1138,18 @@ services:
read_only: true
bind:
create_host_path: false
networks:
- telemetry
secrets:
- ca.crt
- prometheus-client.crt
- prometheus-client.key
network_mode: service:prometheus-gateway
depends_on:
prometheus-gateway:
condition: service_healthy
restart: true
healthcheck:
# busybox wget есть в образе
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:9090/-/ready"]
# busybox wget есть в образе; loopback пространства шлюза
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:19090/-/ready"]
interval: 10s
timeout: 3s
retries: 5
@@ -1025,8 +1178,13 @@ services:
read_only: true
bind:
create_host_path: false
networks:
- telemetry
# с change telemetry-backends-tls — в сетевом пространстве шлюза
# loki-gateway (порты Loki — только loopback), секретов и файлов PKI нет
network_mode: service:loki-gateway
depends_on:
loki-gateway:
condition: service_healthy
restart: true
deploy:
resources:
limits:
@@ -1052,8 +1210,13 @@ services:
read_only: true
bind:
create_host_path: false
networks:
- telemetry
# с change telemetry-backends-tls — в сетевом пространстве шлюза
# tempo-gateway (порты Tempo — только loopback), секретов и файлов PKI нет
network_mode: service:tempo-gateway
depends_on:
tempo-gateway:
condition: service_healthy
restart: true
deploy:
resources:
limits:
@@ -1088,8 +1251,26 @@ services:
GF_PLUGINS_PUBLIC_KEY_RETRIEVAL_DISABLED: "true"
GF_PLUGINS_DISABLE_PLUGINS: cloudwatch,elasticsearch,grafana-postgresql-datasource,grafana-pyroscope-datasource,influxdb,jaeger,mssql,mysql,opentsdb,stackdriver,zipkin,grafana-azure-monitor-datasource,graphite,grafana-testdata-datasource
GOMEMLIMIT: 300MiB
# с change telemetry-backends-tls (design, решение 9) — только HTTPS:
# сертификат grafana (SAN grafana, localhost; CA стенда), TLS ≥ 1.2, как
# у ingress (клиенты — браузер оператора и драйвер на хосте). Запрос
# HTTP без TLS — 400 сервера Go без данных Grafana
GF_SERVER_PROTOCOL: https
GF_SERVER_CERT_FILE: /run/secrets/grafana.crt
GF_SERVER_CERT_KEY: /run/secrets/grafana.key
GF_SERVER_MIN_TLS_VERSION: TLS1.2
GF_SERVER_DOMAIN: localhost
ports:
- "127.0.0.1:${GRAFANA_OUT_PORT:-3000}:3000"
# свои файлы PKI: CA стенда (проверка шлюзов хранилищ), пара grafana
# (интерфейс), пара grafana-client (источники по mTLS; пути — $__file{} в
# datasources.yaml)
secrets:
- ca.crt
- grafana.crt
- grafana.key
- grafana-client.crt
- grafana-client.key
tmpfs:
- /var/lib/grafana
volumes:
@@ -1114,7 +1295,9 @@ services:
networks:
- telemetry
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:3000/api/health"]
# curl образа с CA стенда и именем localhost на loopback контейнера:
# проверка цепочки и имени (busybox wget CA не задать)
test: ["CMD", "curl", "-fsS", "-o", "/dev/null", "--cacert", "/run/secrets/ca.crt", "--resolve", "localhost:3000:127.0.0.1", "https://localhost:3000/api/health"]
interval: 10s
timeout: 3s
retries: 5
@@ -1188,6 +1371,32 @@ secrets:
file: ${PKI_STAND_DIR:-./.pki/stand}/api-client.crt
api-client.key:
file: ${PKI_STAND_DIR:-./.pki/stand}/api-client.key
# change telemetry-backends-tls (design, решения 5, 11): пары loki, tempo,
# prometheus — только шлюзу своего хранилища; otel-collector-client —
# Collector, prometheus-client — Prometheus, grafana и grafana-client —
# Grafana. У Loki и Tempo файлов PKI нет
loki.pem:
file: ${PKI_STAND_DIR:-./.pki/stand}/loki.pem
tempo.pem:
file: ${PKI_STAND_DIR:-./.pki/stand}/tempo.pem
prometheus.pem:
file: ${PKI_STAND_DIR:-./.pki/stand}/prometheus.pem
grafana.crt:
file: ${PKI_STAND_DIR:-./.pki/stand}/grafana.crt
grafana.key:
file: ${PKI_STAND_DIR:-./.pki/stand}/grafana.key
otel-collector-client.crt:
file: ${PKI_STAND_DIR:-./.pki/stand}/otel-collector-client.crt
otel-collector-client.key:
file: ${PKI_STAND_DIR:-./.pki/stand}/otel-collector-client.key
prometheus-client.crt:
file: ${PKI_STAND_DIR:-./.pki/stand}/prometheus-client.crt
prometheus-client.key:
file: ${PKI_STAND_DIR:-./.pki/stand}/prometheus-client.key
grafana-client.crt:
file: ${PKI_STAND_DIR:-./.pki/stand}/grafana-client.crt
grafana-client.key:
file: ${PKI_STAND_DIR:-./.pki/stand}/grafana-client.key
volumes:
postgres_data: