78 lines
2.2 KiB
YAML
78 lines
2.2 KiB
YAML
{{- /*
|
|
Network isolation for internet-facing apps (apps.<name>.networkPolicy). Jellyfin is reachable
|
|
from the internet (tv.smokyzone.de); if it were ever compromised it must not be able to reach
|
|
the rest of the cluster (Home Assistant, OpenBao, Gitea, the *arr APIs, ...) or the LAN.
|
|
|
|
Ingress: only the ingress controller, the listed in-namespace apps (e.g. Seerr) and the node
|
|
itself (kubelet probes, hostNetwork pods).
|
|
Egress: DNS + public internet only (metadata, artwork, plugins); all private ranges are denied,
|
|
which includes every cluster Service IP (10.152.183.0/24) and pod IP (10.1.0.0/16).
|
|
*/ -}}
|
|
{{- $root := . }}
|
|
{{- range $name, $app := .Values.apps }}
|
|
{{- if and $app.enabled $app.networkPolicy }}
|
|
---
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: NetworkPolicy
|
|
metadata:
|
|
name: {{ $name }}-isolation
|
|
namespace: {{ $root.Values.namespace }}
|
|
labels:
|
|
app.kubernetes.io/name: {{ $name }}
|
|
{{- include "media.labels" $root | nindent 4 }}
|
|
spec:
|
|
podSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/name: {{ $name }}
|
|
policyTypes:
|
|
- Ingress
|
|
- Egress
|
|
ingress:
|
|
- from:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: ingress-nginx
|
|
{{- range $app.networkPolicy.allowFrom }}
|
|
- podSelector:
|
|
matchLabels:
|
|
app.kubernetes.io/name: {{ . }}
|
|
{{- end }}
|
|
{{- range $root.Values.networkPolicy.nodeIPs }}
|
|
- ipBlock:
|
|
cidr: {{ . }}/32
|
|
{{- end }}
|
|
ports:
|
|
- protocol: TCP
|
|
port: {{ $app.port }}
|
|
egress:
|
|
- to:
|
|
- namespaceSelector:
|
|
matchLabels:
|
|
kubernetes.io/metadata.name: kube-system
|
|
podSelector:
|
|
matchLabels:
|
|
k8s-app: kube-dns
|
|
ports:
|
|
- protocol: UDP
|
|
port: 53
|
|
- protocol: TCP
|
|
port: 53
|
|
- to:
|
|
- ipBlock:
|
|
cidr: 0.0.0.0/0
|
|
except:
|
|
- 10.0.0.0/8
|
|
- 172.16.0.0/12
|
|
- 192.168.0.0/16
|
|
- 100.64.0.0/10
|
|
- 169.254.0.0/16
|
|
- 127.0.0.0/8
|
|
- ipBlock:
|
|
cidr: ::/0
|
|
except:
|
|
- fc00::/7
|
|
- fe80::/10
|
|
- ::1/128
|
|
{{- end }}
|
|
{{- end }}
|