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:
@@ -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
|
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.
|
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
|
Traefik listens on the node's ports 80/443 (hostPort), so no port is needed. Access is
|
||||||
old NodePort URLs (`:30444`) keep working.
|
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).
|
Certificates come from `letsencrypt-dns-cloudflare` (DNS-01).
|
||||||
|
|
||||||
## Storage layout
|
## Storage layout
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
{{- /*
|
{{- /*
|
||||||
Optional public ingress per app (apps.<name>.publicIngress.host). Unlike the regular
|
Optional public ingress per app (apps.<name>.publicIngress.host). Unlike the regular
|
||||||
ingress it has NO LAN whitelist; protection instead:
|
ingress it has NO LAN whitelist; protection instead (Traefik middlewares):
|
||||||
- GeoIP: ingress-nginx answers the host only for clients from DE (map $geo_restricted_host
|
- GeoIP: only clients from DE (Middleware traefik/geoblock-de, apps-in-apps)
|
||||||
in the ingress-nginx values in apps-in-apps - the host has to be listed there too!)
|
|
||||||
- rate limits per client IP, and a much stricter one for the login endpoints
|
- 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:
|
The DNS record must point at the public IP (DNS-only, NOT proxied through Cloudflare:
|
||||||
video over Cloudflare's free CDN violates their terms).
|
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 }}
|
{{- range $name, $app := .Values.apps }}
|
||||||
{{- if and $app.enabled $app.publicIngress }}
|
{{- if and $app.enabled $app.publicIngress }}
|
||||||
{{- $host := required (printf "apps.%s.publicIngress.host is required" $name) $app.publicIngress.host }}
|
{{- $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
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $name }}-public
|
name: {{ $name }}-public
|
||||||
namespace: {{ $root.Values.namespace }}
|
namespace: {{ $ns }}
|
||||||
labels:
|
labels:
|
||||||
app.kubernetes.io/name: {{ $name }}
|
app.kubernetes.io/name: {{ $name }}
|
||||||
{{- include "media.labels" $root | nindent 4 }}
|
{{- include "media.labels" $root | nindent 4 }}
|
||||||
annotations:
|
annotations:
|
||||||
# Only this ingress requests the certificate; -public-login reuses the secret.
|
# Only this ingress requests the certificate; -public-login reuses the secret.
|
||||||
cert-manager.io/cluster-issuer: {{ $root.Values.ingress.clusterIssuer }}
|
cert-manager.io/cluster-issuer: {{ $root.Values.ingress.clusterIssuer }}
|
||||||
{{- toYaml $common | nindent 4 }}
|
traefik.ingress.kubernetes.io/router.middlewares: traefik-geoblock-de@kubernetescrd,{{ $ns }}-{{ $name }}-public-ratelimit@kubernetescrd,{{ $ns }}-{{ $name }}-public-inflight@kubernetescrd
|
||||||
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 }}
|
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: {{ $root.Values.ingress.className }}
|
ingressClassName: {{ $root.Values.ingress.className }}
|
||||||
tls:
|
tls:
|
||||||
@@ -50,19 +71,31 @@ spec:
|
|||||||
name: http
|
name: http
|
||||||
{{- with $app.publicIngress.loginPaths }}
|
{{- 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.
|
# 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
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $name }}-public-login
|
name: {{ $name }}-public-login
|
||||||
namespace: {{ $root.Values.namespace }}
|
namespace: {{ $ns }}
|
||||||
labels:
|
labels:
|
||||||
app.kubernetes.io/name: {{ $name }}
|
app.kubernetes.io/name: {{ $name }}
|
||||||
{{- include "media.labels" $root | nindent 4 }}
|
{{- include "media.labels" $root | nindent 4 }}
|
||||||
annotations:
|
annotations:
|
||||||
{{- toYaml $common | nindent 4 }}
|
traefik.ingress.kubernetes.io/router.middlewares: traefik-geoblock-de@kubernetescrd,{{ $ns }}-{{ $name }}-public-login-ratelimit@kubernetescrd
|
||||||
nginx.ingress.kubernetes.io/limit-rpm: "10"
|
|
||||||
nginx.ingress.kubernetes.io/limit-burst-multiplier: "1"
|
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: {{ $root.Values.ingress.className }}
|
ingressClassName: {{ $root.Values.ingress.className }}
|
||||||
tls:
|
tls:
|
||||||
|
|||||||
+12
-19
@@ -40,20 +40,17 @@ media:
|
|||||||
- media/manga
|
- media/manga
|
||||||
|
|
||||||
ingress:
|
ingress:
|
||||||
className: nginx
|
className: traefik
|
||||||
# Each app with `ingress: true` gets <name>.<domain>. The DNS records point at the
|
# Each app with `ingress: true` gets <name>.<domain>. The DNS records point at the
|
||||||
# node's private IP, so the UIs are only reachable from the LAN / via VPN.
|
# node's private IP, so the UIs are only reachable from the LAN / via VPN.
|
||||||
domain: smokyzone.de
|
domain: smokyzone.de
|
||||||
# DNS-01 works for hostnames that only resolve to a private IP.
|
# DNS-01 works for hostnames that only resolve to a private IP.
|
||||||
clusterIssuer: letsencrypt-dns-cloudflare
|
clusterIssuer: letsencrypt-dns-cloudflare
|
||||||
annotations:
|
annotations:
|
||||||
nginx.ingress.kubernetes.io/proxy-body-size: 100m
|
# LAN-only: home network + pods (incl. Tailscale), Middleware traefik/lan-only in apps-in-apps.
|
||||||
# LAN-only: home network + pods (incl. the Tailscale subnet router, 10.1.0.0/16), but
|
# Side effect: LAN access via the NodePort (:30444) is blocked (arrives SNATed as the
|
||||||
# NOT 192.168.2.218 - the router's internet forward (443 -> NodePort 30444, for git)
|
# node's IP) - use the URL without port.
|
||||||
# arrives SNATed as the node's own IP. So internet clients that send this hostname
|
traefik.ingress.kubernetes.io/router.middlewares: traefik-lan-only@kubernetescrd
|
||||||
# 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"
|
|
||||||
|
|
||||||
# StorageClass for the per-app config PVCs, empty = cluster default.
|
# StorageClass for the per-app config PVCs, empty = cluster default.
|
||||||
storageClassName: ""
|
storageClassName: ""
|
||||||
@@ -90,8 +87,8 @@ apps:
|
|||||||
# plugin (apps-in-apps: intel-gpu-plugin), which injects /dev/dri. Not privileged.
|
# plugin (apps-in-apps: intel-gpu-plugin), which injects /dev/dri. Not privileged.
|
||||||
gpu: true
|
gpu: true
|
||||||
# Remote access without VPN (templates/public-ingress.yaml): DE-only via GeoIP in
|
# Remote access without VPN (templates/public-ingress.yaml): DE-only via GeoIP in
|
||||||
# ingress-nginx, rate limited. jellyfin.smokyzone.de stays LAN/Tailscale-only.
|
# Traefik, rate limited. jellyfin.smokyzone.de stays LAN/Tailscale-only.
|
||||||
# templates/networkpolicy.yaml: only ingress-nginx, Seerr and the node may connect;
|
# templates/networkpolicy.yaml: only the ingress controller, Seerr and the node may connect;
|
||||||
# Jellyfin itself may only reach DNS and the public internet.
|
# Jellyfin itself may only reach DNS and the public internet.
|
||||||
networkPolicy:
|
networkPolicy:
|
||||||
allowFrom:
|
allowFrom:
|
||||||
@@ -103,20 +100,16 @@ apps:
|
|||||||
publicIngress:
|
publicIngress:
|
||||||
host: tv.smokyzone.de
|
host: tv.smokyzone.de
|
||||||
# The web UI loads 40+ scripts/images in parallel at startup (plugins: SeerrFin,
|
# The web UI loads 40+ scripts/images in parallel at startup (plugins: SeerrFin,
|
||||||
# Featured, Bonfire ...). With HTTP/2 every stream counts against limit-connections;
|
# Featured, Bonfire ...). Every HTTP/2 stream counts as an in-flight request; 30
|
||||||
# 30 caused 429s for plugin scripts. Login stays limited separately (10/min).
|
# caused 429s for plugin scripts. Login stays limited separately (10/min).
|
||||||
limitRps: "50"
|
limitRps: 50
|
||||||
limitConnections: "100"
|
limitConnections: 100
|
||||||
# Jellyfin's routing is case-insensitive, nginx paths are not -> both spellings.
|
# Jellyfin's routing is case-insensitive, ingress paths are not -> both spellings.
|
||||||
loginPaths:
|
loginPaths:
|
||||||
- /Users/AuthenticateByName
|
- /Users/AuthenticateByName
|
||||||
- /users/authenticatebyname
|
- /users/authenticatebyname
|
||||||
- /Users/ForgotPassword
|
- /Users/ForgotPassword
|
||||||
- /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:
|
env:
|
||||||
- name: JELLYFIN_PublishedServerUrl
|
- name: JELLYFIN_PublishedServerUrl
|
||||||
value: https://jellyfin.smokyzone.de
|
value: https://jellyfin.smokyzone.de
|
||||||
|
|||||||
Reference in New Issue
Block a user