api: a per-client rate limit on the HTTP API, with trusted proxies for X-Forwarded-For
600 /api/ requests a minute per client address (--requests-per-minute), 429 with Retry-After; static UI files and the node's own machine are exempt. The real client behind a reverse proxy is read from X-Forwarded-For only when the connection comes from a --trusted-proxy, taking the last entry that is not itself a trusted proxy. k8s: TRUSTED_PROXY in config.env (the private ranges) is passed as --trusted-proxy. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
@@ -22,3 +22,12 @@ REGION=
|
||||
# The default of the binary is 24; it is written here so it is visible, and so
|
||||
# a later change of the network's value is one edit in one place.
|
||||
DIFFICULTY=24
|
||||
|
||||
# The reverse proxies in front of the web UI and API (your ingress controller),
|
||||
# comma separated addresses or networks. Only a connection from one of them may
|
||||
# say who the real client is (X-Forwarded-For); the node then limits requests
|
||||
# per real client (600 a minute) instead of counting the whole site as one
|
||||
# client. These are the private ranges, which covers the pod networks of k3s
|
||||
# (10.42.0.0/16), most CNIs and a Traefik on the same cluster. Empty: every
|
||||
# visitor shares one allowance, which throttles the site as a whole.
|
||||
TRUSTED_PROXY=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
|
||||
|
||||
@@ -61,6 +61,11 @@ spec:
|
||||
for r in ${REGION}; do set -- "$@" --region "$r"; done
|
||||
unset IFS; set +f
|
||||
fi
|
||||
if [ -n "${TRUSTED_PROXY}" ]; then
|
||||
set -f; IFS=,
|
||||
for p in ${TRUSTED_PROXY}; do set -- "$@" --trusted-proxy "$p"; done
|
||||
unset IFS; set +f
|
||||
fi
|
||||
exec allmende run "$@"
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
|
||||
Reference in New Issue
Block a user