Ingresses: switch to Traefik (lan-only middleware; tv: GeoIP + rate limit middlewares)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-02 12:16:10 +01:00
co-authored by Claude Opus 5.5
parent c4bd8ebd12
commit bd6467d054
3 changed files with 64 additions and 37 deletions
+49 -16
View File
@@ -1,8 +1,7 @@
{{- /*
Optional public ingress per app (apps.<name>.publicIngress.host). Unlike the regular
ingress it has NO LAN whitelist; protection instead:
- GeoIP: ingress-nginx answers the host only for clients from DE (map $geo_restricted_host
in the ingress-nginx values in apps-in-apps - the host has to be listed there too!)
ingress it has NO LAN whitelist; protection instead (Traefik middlewares):
- GeoIP: only clients from DE (Middleware traefik/geoblock-de, apps-in-apps)
- rate limits per client IP, and a much stricter one for the login endpoints
The DNS record must point at the public IP (DNS-only, NOT proxied through Cloudflare:
video over Cloudflare's free CDN violates their terms).
@@ -11,26 +10,48 @@ video over Cloudflare's free CDN violates their terms).
{{- range $name, $app := .Values.apps }}
{{- if and $app.enabled $app.publicIngress }}
{{- $host := required (printf "apps.%s.publicIngress.host is required" $name) $app.publicIngress.host }}
{{- $common := dict "nginx.ingress.kubernetes.io/proxy-body-size" "100m" }}
{{- $ns := $root.Values.namespace }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ $name }}-public-ratelimit
namespace: {{ $ns }}
labels:
{{- include "media.labels" $root | nindent 4 }}
spec:
# Per client IP (TCP peer); excess requests get 429.
rateLimit:
average: {{ $app.publicIngress.limitRps | default 30 }}
burst: {{ mul ($app.publicIngress.limitRps | default 30) 5 }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ $name }}-public-inflight
namespace: {{ $ns }}
labels:
{{- include "media.labels" $root | nindent 4 }}
spec:
# Concurrent requests per client IP (every HTTP/2 stream counts).
inFlightReq:
amount: {{ $app.publicIngress.limitConnections | default 30 }}
sourceCriterion:
ipStrategy:
depth: 0
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $name }}-public
namespace: {{ $root.Values.namespace }}
namespace: {{ $ns }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
annotations:
# Only this ingress requests the certificate; -public-login reuses the secret.
cert-manager.io/cluster-issuer: {{ $root.Values.ingress.clusterIssuer }}
{{- toYaml $common | nindent 4 }}
nginx.ingress.kubernetes.io/limit-rps: {{ $app.publicIngress.limitRps | default "30" | quote }}
nginx.ingress.kubernetes.io/limit-burst-multiplier: "5"
nginx.ingress.kubernetes.io/limit-connections: {{ $app.publicIngress.limitConnections | default "30" | quote }}
{{- with $app.ingressAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
traefik.ingress.kubernetes.io/router.middlewares: traefik-geoblock-de@kubernetescrd,{{ $ns }}-{{ $name }}-public-ratelimit@kubernetescrd,{{ $ns }}-{{ $name }}-public-inflight@kubernetescrd
spec:
ingressClassName: {{ $root.Values.ingress.className }}
tls:
@@ -50,19 +71,31 @@ spec:
name: http
{{- with $app.publicIngress.loginPaths }}
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: {{ $name }}-public-login-ratelimit
namespace: {{ $ns }}
labels:
{{- include "media.labels" $root | nindent 4 }}
spec:
rateLimit:
average: 10
period: 1m
burst: 10
---
# Same host, login/password-reset endpoints only: at most 10 attempts per minute per IP.
# Longer path rule -> higher router priority than {{ $name }}-public.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $name }}-public-login
namespace: {{ $root.Values.namespace }}
namespace: {{ $ns }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
annotations:
{{- toYaml $common | nindent 4 }}
nginx.ingress.kubernetes.io/limit-rpm: "10"
nginx.ingress.kubernetes.io/limit-burst-multiplier: "1"
traefik.ingress.kubernetes.io/router.middlewares: traefik-geoblock-de@kubernetescrd,{{ $ns }}-{{ $name }}-public-login-ratelimit@kubernetescrd
spec:
ingressClassName: {{ $root.Values.ingress.className }}
tls: