forked from mtusi2026/mtusi2026lab7
- внутренняя PKI: root -> ca-servers / ca-clients, leaf на каждый сервис; pki/, secrets/, bootstrap/ не коммитятся и не попадают в образ - внешний HTTPS :8443 с проверкой CA и hostname (IP намеренно не в SAN) - обязательный mTLS LB -> каждая API-реплика: relay проверяет цепочку, CN и серийник (identities.json) и scope; uvicorn слушает только loopback - mTLS к RabbitMQ (TLS + EXTERNAL auth, CN -> user, ACL topology) и к OTLP-ingress (nginx: allowlist CN, Collector доступен только из otel) - TLS к PostgreSQL (verify-full), S3, OpenBao, Loki/Tempo, Grafana - OpenBao: file storage + volume, AppRole с secret_id 24h и token 20m, scoped KV-policy; root token/unseal только у оператора - раздельные DB-роли и S3-ключи с prefix-rights; read_only/cap_drop, stateful-исключения задокументированы - rate limit входа в PostgreSQL (общий для реплик), Argon2id + rehash, семафор хеширования; ротация/отзыв leaf и рабочего секрета без пересборки образов Co-Authored-By: O3 Agent Claude <noreply@ozon.ru>
108 lines
3.9 KiB
Nginx Configuration File
108 lines
3.9 KiB
Nginx Configuration File
# LB стенда lab7.
|
|
# 8443 — внешний TLS (клиент → LB) + mTLS (LB → каждая API-реплика).
|
|
# 4318 — OTLP-ingress: mTLS + allowlist identity (api/worker) → Collector по TLS.
|
|
# nginx работает non-root (uid 101), read-only ФС, все временные пути в /tmp.
|
|
worker_processes 1;
|
|
error_log /dev/stderr warn;
|
|
pid /tmp/nginx.pid;
|
|
|
|
events { worker_connections 1024; }
|
|
|
|
http {
|
|
client_body_temp_path /tmp/client_temp;
|
|
proxy_temp_path /tmp/proxy_temp;
|
|
fastcgi_temp_path /tmp/fastcgi_temp;
|
|
uwsgi_temp_path /tmp/uwsgi_temp;
|
|
scgi_temp_path /tmp/scgi_temp;
|
|
access_log /dev/stdout;
|
|
|
|
upstream api_pool {
|
|
server messenger-lab7-api-1:8443 max_fails=1 fail_timeout=5s;
|
|
server messenger-lab7-api-2:8443 max_fails=1 fail_timeout=5s;
|
|
keepalive 16;
|
|
}
|
|
|
|
# Identity для OTLP: разрешены только сервисные сертификаты api/worker.
|
|
# Чужой сертификат, подписанный тем же CA, получит 403.
|
|
map $ssl_client_s_dn $otel_identity_ok {
|
|
default 0;
|
|
"~*CN=messenger-api" 1;
|
|
"~*CN=messenger-worker" 1;
|
|
}
|
|
|
|
server {
|
|
listen 8443 ssl;
|
|
server_name localhost ingress nginx;
|
|
|
|
ssl_certificate /run/secrets/ingress_server_crt;
|
|
ssl_certificate_key /run/secrets/ingress_server_key;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_session_cache shared:SSL:1m;
|
|
ssl_session_tickets off;
|
|
|
|
client_max_body_size 11m;
|
|
|
|
location / {
|
|
proxy_pass https://api_pool;
|
|
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 Connection "";
|
|
|
|
# Обязательный mTLS до реплики: клиентский сертификат CN=lb,
|
|
# проверка цепочки и имени API-сервера.
|
|
proxy_ssl_certificate /run/secrets/ingress_client_crt;
|
|
proxy_ssl_certificate_key /run/secrets/ingress_client_key;
|
|
proxy_ssl_trusted_certificate /run/secrets/ca_servers;
|
|
proxy_ssl_verify on;
|
|
proxy_ssl_verify_depth 2;
|
|
proxy_ssl_name api;
|
|
proxy_ssl_server_name on;
|
|
proxy_ssl_session_reuse off;
|
|
|
|
proxy_next_upstream error timeout;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_connect_timeout 2s;
|
|
proxy_send_timeout 15s;
|
|
proxy_read_timeout 15s;
|
|
proxy_request_buffering on;
|
|
}
|
|
}
|
|
|
|
server {
|
|
listen 4318 ssl;
|
|
server_name ingress nginx;
|
|
|
|
ssl_certificate /run/secrets/ingress_server_crt;
|
|
ssl_certificate_key /run/secrets/ingress_server_key;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
# mTLS для телеметрии: без сертификата/с чужим CA — отказ на handshake,
|
|
# с сертификатом того же CA, но чужой identity — 403 ниже.
|
|
ssl_client_certificate /run/secrets/ca_clients;
|
|
ssl_verify_client on;
|
|
ssl_verify_depth 2;
|
|
|
|
client_max_body_size 64m;
|
|
|
|
location / {
|
|
if ($otel_identity_ok = 0) {
|
|
return 403;
|
|
}
|
|
proxy_pass https://otel-collector:4318;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
|
|
# Collector проверяется по CA (серверный TLS на закрытом сегменте).
|
|
proxy_ssl_trusted_certificate /run/secrets/ca_servers;
|
|
proxy_ssl_verify on;
|
|
proxy_ssl_name otel-collector;
|
|
proxy_ssl_server_name on;
|
|
|
|
proxy_read_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
}
|
|
}
|
|
}
|