# Default-deny ingress for the authentik namespace, with explicit allow rules for the # traffic paths that actually need to reach in: Traefik (kube-system) for the public # auth.axion1337.chat endpoint and ACME HTTP-01 challenges, and MAS (matrix namespace) # for upstream OIDC calls. Egress is intentionally untouched (federation-equivalent # outbound calls like SMTP aren't restricted here). # # authentik-postgresql: the Bitnami postgresql subchart's own generated NetworkPolicy # restricted the port (5432) but not the source - any pod in any namespace could reach # it (issue #37). Disabled via postgresql.primary.networkPolicy.enabled: false in # authentik.yaml and replaced below with a policy scoped to authentik-server/-worker. apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: default-deny-ingress namespace: authentik spec: podSelector: {} policyTypes: - Ingress --- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-ingress-authentik-server namespace: authentik spec: podSelector: matchLabels: app.kubernetes.io/name: authentik app.kubernetes.io/component: server policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system - namespaceSelector: matchLabels: kubernetes.io/metadata.name: matrix ports: # NetworkPolicy matches the pod's actual container port, not the Service's # external port - the authentik-server Service maps 80->9000, 443->9443. - protocol: TCP port: 9000 - protocol: TCP port: 9443 --- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-ingress-authentik-postgresql namespace: authentik spec: podSelector: matchLabels: app.kubernetes.io/name: postgresql app.kubernetes.io/component: primary policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app.kubernetes.io/name: authentik app.kubernetes.io/component: server - podSelector: matchLabels: app.kubernetes.io/name: authentik app.kubernetes.io/component: worker - podSelector: matchLabels: app.kubernetes.io/name: authentik-backup ports: - protocol: TCP port: 5432 --- apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-ingress-acme-solver namespace: authentik spec: podSelector: matchLabels: acme.cert-manager.io/http01-solver: "true" policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system ports: - protocol: TCP port: 8089 --- # Egress: alles bleibt erlaubt AUSSER dem Metadaten-Dienst (management #0088). # # Warum so schmal? Der Lehrbuch-Schnitt (0.0.0.0/0 except RFC1918) haette hier zwei # Dinge zerrissen, beide ueber 10.0.0.3 (CFGMON im privaten Hetzner-Netz): Alloy # schreibt Metriken und Logs dorthin, und der TURN-Rotations-CronJob erreicht Gitea # ueber einen hostAlias auf dieselbe Adresse. Private Netze bleiben deshalb offen. # # 169.254.0.0/16 ist Link-Local; darin liegt bei Hetzner unter 169.254.169.254 der # Metadaten-Dienst, aus jedem Pod unauthentifiziert abfragbar (nachgemessen 2026-08-19: # HTTP 200 mit instance-id, hostname, region, MAC, Netzkonfiguration). userdata und # public-keys waren LEER - es liegen hier also keine Zugangsdaten offen. Der Gewinn ist # entsprechend bescheiden; der Schnitt kostet aber nichts und schliesst die Klasse. # # ACHTUNG beim Erweitern: Sobald eine Egress-Regel fuer einen Pod existiert, gilt fuer # ihn Default-Deny fuer alles NICHT Aufgefuehrte. Die drei Bloecke unten sind daher # Pflicht, nicht Bequemlichkeit - insbesondere DNS: fehlt es, steht alles, und der # Fehler sieht wie ein Anwendungsproblem aus, nicht wie eine Firewall. # # Rollback: diese eine Policy im Namespace loeschen. apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: egress-block-metadata namespace: authentik spec: podSelector: {} policyTypes: - Egress egress: # 1. DNS - zuerst, weil ohne DNS nichts geht. - to: - namespaceSelector: matchLabels: kubernetes.io/metadata.name: kube-system ports: - protocol: UDP port: 53 - protocol: TCP port: 53 # 2. Cluster-intern: Pods und Services (inkl. API-Server 10.43.0.1). - to: - ipBlock: cidr: 10.42.0.0/16 - ipBlock: cidr: 10.43.0.0/16 # 3. Alles uebrige - Foederation, ACME, SMTP, Registries, privates Netz - # ausser Link-Local. - to: - ipBlock: cidr: 0.0.0.0/0 except: - 169.254.0.0/16