diff --git a/README.md b/README.md index cab88c4..21e89c8 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,9 @@ via the `apps-in-apps` repo into the namespace `media`. The hostnames resolve to the node's private IP (`192.168.2.218`) via Cloudflare DNS-only records, so the UIs are only reachable from the LAN or through a VPN into the LAN. -ingress-nginx listens on the node's ports 80/443 (hostPort), so no port is needed; the -old NodePort URLs (`:30444`) keep working. +Traefik listens on the node's ports 80/443 (hostPort), so no port is needed. Access is +limited to the LAN by the Middleware `traefik/lan-only` (defined in apps-in-apps); via the +NodePort (`:30444`) requests arrive SNATed as the node's IP and are therefore refused. Certificates come from `letsencrypt-dns-cloudflare` (DNS-01). ## Storage layout diff --git a/templates/public-ingress.yaml b/templates/public-ingress.yaml index 41c6dea..a884ba2 100644 --- a/templates/public-ingress.yaml +++ b/templates/public-ingress.yaml @@ -1,8 +1,7 @@ {{- /* Optional public ingress per app (apps..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: diff --git a/values.yaml b/values.yaml index 14d5fb3..af0e393 100644 --- a/values.yaml +++ b/values.yaml @@ -40,20 +40,17 @@ media: - media/manga ingress: - className: nginx + className: traefik # Each app with `ingress: true` gets .. The DNS records point at the # node's private IP, so the UIs are only reachable from the LAN / via VPN. domain: smokyzone.de # DNS-01 works for hostnames that only resolve to a private IP. clusterIssuer: letsencrypt-dns-cloudflare annotations: - nginx.ingress.kubernetes.io/proxy-body-size: 100m - # LAN-only: home network + pods (incl. the Tailscale subnet router, 10.1.0.0/16), but - # NOT 192.168.2.218 - the router's internet forward (443 -> NodePort 30444, for git) - # arrives SNATed as the node's own IP. So internet clients that send this hostname - # get 403, while LAN clients reach the ingress directly on hostPort 443 with their - # real IP. Side effect: LAN access via :30444 is blocked too (use the URL without port). - nginx.ingress.kubernetes.io/whitelist-source-range: "192.168.2.0/25,192.168.2.128/26,192.168.2.192/28,192.168.2.208/29,192.168.2.216/31,192.168.2.219/32,192.168.2.220/30,192.168.2.224/27,10.1.0.0/16" + # LAN-only: home network + pods (incl. Tailscale), Middleware traefik/lan-only in apps-in-apps. + # Side effect: LAN access via the NodePort (:30444) is blocked (arrives SNATed as the + # node's IP) - use the URL without port. + traefik.ingress.kubernetes.io/router.middlewares: traefik-lan-only@kubernetescrd # StorageClass for the per-app config PVCs, empty = cluster default. storageClassName: "" @@ -90,8 +87,8 @@ apps: # plugin (apps-in-apps: intel-gpu-plugin), which injects /dev/dri. Not privileged. gpu: true # Remote access without VPN (templates/public-ingress.yaml): DE-only via GeoIP in - # ingress-nginx, rate limited. jellyfin.smokyzone.de stays LAN/Tailscale-only. - # templates/networkpolicy.yaml: only ingress-nginx, Seerr and the node may connect; + # Traefik, rate limited. jellyfin.smokyzone.de stays LAN/Tailscale-only. + # templates/networkpolicy.yaml: only the ingress controller, Seerr and the node may connect; # Jellyfin itself may only reach DNS and the public internet. networkPolicy: allowFrom: @@ -103,20 +100,16 @@ apps: publicIngress: host: tv.smokyzone.de # The web UI loads 40+ scripts/images in parallel at startup (plugins: SeerrFin, - # Featured, Bonfire ...). With HTTP/2 every stream counts against limit-connections; - # 30 caused 429s for plugin scripts. Login stays limited separately (10/min). - limitRps: "50" - limitConnections: "100" - # Jellyfin's routing is case-insensitive, nginx paths are not -> both spellings. + # Featured, Bonfire ...). Every HTTP/2 stream counts as an in-flight request; 30 + # caused 429s for plugin scripts. Login stays limited separately (10/min). + limitRps: 50 + limitConnections: 100 + # Jellyfin's routing is case-insensitive, ingress paths are not -> both spellings. loginPaths: - /Users/AuthenticateByName - /users/authenticatebyname - /Users/ForgotPassword - /users/forgotpassword - ingressAnnotations: - nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" - nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" - nginx.ingress.kubernetes.io/proxy-buffering: "off" env: - name: JELLYFIN_PublishedServerUrl value: https://jellyfin.smokyzone.de