lab7: HTTPS+mTLS, OpenBao AppRole, Argon2id, rate limits, hardening

This commit is contained in:
2026-11-19 20:48:27 +03:00
parent 20afc2c790
commit 5e98b1b5af
67 changed files with 3169 additions and 87 deletions
+30
View File
@@ -0,0 +1,30 @@
map $ssl_client_s_dn $lb_identity_ok {
default 0;
"~*CN=lb(,|/|$)" 1;
}
server {
listen 8443 ssl;
server_name api-gateway;
ssl_certificate /pki/gateway.crt;
ssl_certificate_key /pki/gateway.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_client_certificate /pki/ca.crt;
ssl_verify_client on;
ssl_verify_depth 2;
# A trusted CA is not enough: only the LB identity may call the API.
if ($lb_identity_ok = 0) {
return 403;
}
location / {
proxy_pass http://${API_UPSTREAM}:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Client-Identity $ssl_client_s_dn;
proxy_connect_timeout 2s;
proxy_read_timeout 30s;
}
}
+41
View File
@@ -0,0 +1,41 @@
events {}
http {
upstream api_secure {
server api-gw1:8443 max_fails=1 fail_timeout=2s;
server api-gw2:8443 max_fails=1 fail_timeout=2s;
}
server {
listen 8443 ssl;
server_name localhost;
ssl_certificate /pki/server.crt;
ssl_certificate_key /pki/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache shared:SSL:5m;
client_max_body_size 11m;
location / {
proxy_pass https://api_secure;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 3s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
# A stopped replica makes its gateway answer 502; retry the other
# gateway. Message POSTs carry Idempotency-Key, so a retry is safe.
proxy_next_upstream error timeout http_502 http_503 http_504;
proxy_next_upstream_tries 2;
proxy_next_upstream_timeout 3s;
# Mandatory mTLS to every API replica: verify the gateway chain and
# present the LB identity certificate.
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /pki/ca.crt;
proxy_ssl_certificate /pki/lb.crt;
proxy_ssl_certificate_key /pki/lb.key;
proxy_ssl_server_name on;
proxy_ssl_name api-gw1;
}
}
}