Перенесён минимум lab6 (API без изменений), добавлена защита на границах доверия: - внешний HTTPS; обязательный mTLS LB -> API с allowlist identity и отзывом по serial; - TLS на всех связях: PostgreSQL verify-full, MinIO HTTPS, RabbitMQ AMQPS mTLS (EXTERNAL), Valkey TLS + ACL, Collector и хранилища телеметрии через mTLS с отдельными CA; - OpenBao в server mode: cert auth, токены 15 мин, политики только на свой путь; - роли БД, S3-политики и права брокера по принципу минимальных прав; - Argon2id с замером, rehash, общий лимит входа, бюджет защиты от login DoS; - hardening всех контейнеров, scan образов с разбором, модель угроз, матрица доверия; - отрицательные тесты: TLS-аудит (135 проверок), ACL, ротации, sealed OpenBao.
96 lines
3.3 KiB
Nginx Configuration File
96 lines
3.3 KiB
Nginx Configuration File
# nginx 1.27 (lab7): the only business ingress. Client -> nginx: TLS (server cert SAN localhost/nginx).
|
|
# nginx -> every API replica: mTLS. nginx presents lb-client (identity lb.client.messenger) and verifies the replica
|
|
# certificate against the lab root CA with the shared SAN api.internal. The API itself checks the LB identity.
|
|
worker_processes 2;
|
|
pid /var/run/nginx.pid;
|
|
|
|
events {
|
|
worker_connections 256;
|
|
}
|
|
|
|
http {
|
|
resolver 127.0.0.11 valid=5s ipv6=off;
|
|
|
|
upstream api {
|
|
zone api 64k;
|
|
include /etc/nginx/upstream/servers.conf;
|
|
keepalive 32;
|
|
keepalive_timeout 4s;
|
|
}
|
|
|
|
log_format main '$remote_addr - $upstream_addr [$time_local] '
|
|
'"$request" $status $body_bytes_sent '
|
|
'"$upstream_response_time" "$request_time"';
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
server {
|
|
listen 8443 ssl;
|
|
ssl_certificate /run/secrets/server.crt;
|
|
ssl_certificate_key /run/secrets/server.key;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_session_cache shared:tls:5m;
|
|
add_header Strict-Transport-Security "max-age=31536000" always;
|
|
server_tokens off;
|
|
client_max_body_size 64k;
|
|
error_page 413 @payload_too_large;
|
|
|
|
# Upstream mTLS (no fallback to plaintext, verification always on).
|
|
proxy_ssl_certificate /run/secrets/client.crt;
|
|
proxy_ssl_certificate_key /run/secrets/client.key;
|
|
proxy_ssl_trusted_certificate /run/secrets/ca.crt;
|
|
proxy_ssl_verify on;
|
|
proxy_ssl_verify_depth 2;
|
|
proxy_ssl_name api.internal;
|
|
proxy_ssl_server_name on;
|
|
proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
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_connect_timeout 1s;
|
|
proxy_read_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_next_upstream_timeout 5s;
|
|
|
|
location ~ ^/api/v1/chats/[^/]+/messages$ {
|
|
proxy_pass https://api;
|
|
proxy_next_upstream error timeout http_502 http_503 non_idempotent;
|
|
}
|
|
|
|
location ~ ^/api/v1/chats/[^/]+/attachments$ {
|
|
client_max_body_size 10m;
|
|
proxy_request_buffering off;
|
|
proxy_pass https://api;
|
|
proxy_next_upstream off;
|
|
}
|
|
|
|
location @payload_too_large {
|
|
default_type application/json;
|
|
add_header X-Request-Id $request_id always;
|
|
add_header X-Instance-Id lb always;
|
|
add_header Connection close always;
|
|
return 413 '{"error":{"code":"payload_too_large","message":"Тело запроса слишком большое","request_id":"$request_id"}}';
|
|
}
|
|
|
|
location /health/ {
|
|
proxy_pass https://api;
|
|
proxy_next_upstream error timeout;
|
|
}
|
|
|
|
location ~ ^/api/v1/attachments/ {
|
|
proxy_max_temp_file_size 0;
|
|
proxy_pass https://api;
|
|
proxy_next_upstream error timeout;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass https://api;
|
|
proxy_next_upstream error timeout http_502 http_503;
|
|
}
|
|
}
|
|
}
|