Files

121 lines
3.7 KiB
YAML

{{- /*
Optional public ingress per app (apps.<name>.publicIngress.host). Unlike the regular
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).
*/ -}}
{{- $root := . }}
{{- range $name, $app := .Values.apps }}
{{- if and $app.enabled $app.publicIngress }}
{{- $host := required (printf "apps.%s.publicIngress.host is required" $name) $app.publicIngress.host }}
{{- $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: {{ $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 }}
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:
- hosts:
- {{ $host }}
secretName: {{ $name }}-public-tls
rules:
- host: {{ $host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ $name }}
port:
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: {{ $ns }}
labels:
app.kubernetes.io/name: {{ $name }}
{{- include "media.labels" $root | nindent 4 }}
annotations:
traefik.ingress.kubernetes.io/router.middlewares: traefik-geoblock-de@kubernetescrd,{{ $ns }}-{{ $name }}-public-login-ratelimit@kubernetescrd
spec:
ingressClassName: {{ $root.Values.ingress.className }}
tls:
- hosts:
- {{ $host }}
secretName: {{ $name }}-public-tls
rules:
- host: {{ $host }}
http:
paths:
{{- range . }}
- path: {{ . }}
pathType: Prefix
backend:
service:
name: {{ $name }}
port:
name: http
{{- end }}
{{- end }}
{{- end }}
{{- end }}