homek8s/apps/base/sirius-growth/configmap-portal-gate.yaml

69 lines
2.7 KiB
YAML
Raw Normal View History

apiVersion: v1
kind: ConfigMap
metadata:
name: sirius-growth-portal-gate
namespace: sirius-growth
data:
default.conf: |
# Sirius Growth portal login gate. One job: cap credential attempts per client
# IP before they reach the API. The HTTPRoute sends only /api/portal/login* here
# (login, plus a trailing-slash variant); everything else goes straight to the
# portal service, so this pod can never break uploads, downloads or the admin API.
# The TCP peer is always cluster ingress, so $remote_addr is meaningless until
# the forwarded chain is resolved: Envoy (hostNetwork, siriussec) appends the
# caller to X-Forwarded-For. Trusting the pod / service / node ranges makes
# $remote_addr the real client. A caller cannot spoof it by sending its own
# X-Forwarded-For, because Envoy appends the true address to the right of
# whatever the client supplied and nginx walks the chain from the right.
set_real_ip_from 10.244.0.0/16;
set_real_ip_from 10.96.0.0/12;
set_real_ip_from 10.10.0.0/24;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# 12 attempts/min per IP with 6 in hand: a fat-fingered operator gets several
# tries, a password guesser gets nowhere. Tune the two numbers here only.
limit_req_zone $binary_remote_addr zone=portal_login:10m rate=12r/m;
limit_req_status 429;
limit_req_log_level warn;
server {
listen 8080;
server_name _;
default_type application/json;
client_max_body_size 8k;
client_body_timeout 10s;
location ^~ /api/portal/login {
limit_req zone=portal_login burst=6 nodelay;
# JSON, not nginx's HTML error page: portal.js shows the body's `error`
# string on the sign-in page instead of "Portal API is not reachable".
error_page 429 @login_limited;
proxy_pass http://sirius-growth-portal:8091;
proxy_http_version 1.1;
proxy_set_header Host $host;
# Pass the chain through verbatim; uvicorn reads the leftmost entry.
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 5s;
proxy_read_timeout 15s;
proxy_send_timeout 15s;
proxy_buffering off;
}
location @login_limited {
internal;
default_type application/json;
add_header Cache-Control "no-store" always;
return 429 '{"error":"too many sign-in attempts - wait a minute and try again"}';
}
# Nothing else is routed to this pod. An honest 404 beats a proxied surprise.
location / {
return 404;
}
}