SGS portal: nginx login gate — rate-limit /api/portal/login (12r/m, burst 6)
This commit is contained in:
parent
c77b5a6e80
commit
5036d853bf
5 changed files with 146 additions and 0 deletions
69
apps/base/sirius-growth/configmap-portal-gate.yaml
Normal file
69
apps/base/sirius-growth/configmap-portal-gate.yaml
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
53
apps/base/sirius-growth/deployment-portal-gate.yaml
Normal file
53
apps/base/sirius-growth/deployment-portal-gate.yaml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: sirius-growth-portal-gate
|
||||
namespace: sirius-growth
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: sirius-growth-portal-gate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: sirius-growth-portal-gate
|
||||
spec:
|
||||
tolerations:
|
||||
- key: dedicated
|
||||
operator: Exists
|
||||
effect: PreferNoSchedule
|
||||
nodeSelector:
|
||||
kubernetes.io/hostname: siriussec
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.27-alpine
|
||||
imagePullPolicy: IfNotPresent
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
name: http
|
||||
volumeMounts:
|
||||
- name: conf
|
||||
mountPath: /etc/nginx/conf.d/default.conf
|
||||
subPath: default.conf
|
||||
readOnly: true
|
||||
readinessProbe:
|
||||
tcpSocket:
|
||||
port: 8080
|
||||
initialDelaySeconds: 2
|
||||
periodSeconds: 10
|
||||
livenessProbe:
|
||||
tcpSocket:
|
||||
port: 8080
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 20
|
||||
resources:
|
||||
requests:
|
||||
cpu: 10m
|
||||
memory: 16Mi
|
||||
limits:
|
||||
memory: 64Mi
|
||||
volumes:
|
||||
- name: conf
|
||||
configMap:
|
||||
name: sirius-growth-portal-gate
|
||||
|
|
@ -18,6 +18,13 @@ spec:
|
|||
backendRefs:
|
||||
- name: sirius-growth-contact
|
||||
port: 8090
|
||||
- matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /api/portal/login
|
||||
backendRefs:
|
||||
- name: sirius-growth-portal-gate
|
||||
port: 8080
|
||||
- matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ resources:
|
|||
- deployment.yaml
|
||||
- deployment-api.yaml
|
||||
- deployment-portal.yaml
|
||||
- deployment-portal-gate.yaml
|
||||
- configmap-portal-gate.yaml
|
||||
- service.yaml
|
||||
- service-api.yaml
|
||||
- service-portal.yaml
|
||||
- service-portal-gate.yaml
|
||||
- httproute.yaml
|
||||
- cluster.yaml
|
||||
- podmonitor.yaml
|
||||
|
|
|
|||
14
apps/base/sirius-growth/service-portal-gate.yaml
Normal file
14
apps/base/sirius-growth/service-portal-gate.yaml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: sirius-growth-portal-gate
|
||||
namespace: sirius-growth
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: sirius-growth-portal-gate
|
||||
ports:
|
||||
- name: http
|
||||
port: 8080
|
||||
targetPort: 8080
|
||||
protocol: TCP
|
||||
Loading…
Reference in a new issue