access-engine/charts/flex-auth/templates/networkpolicy.yaml

68 lines
2.5 KiB
YAML
Raw Normal View History

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "flex-auth.name" . }}
labels:
{{- include "flex-auth.labels" . | nindent 4 }}
spec:
podSelector:
matchLabels:
{{- include "flex-auth.selectorLabels" . | nindent 6 }}
policyTypes:
- Ingress
- Egress
{{- if or .Values.auditDelivery.enabled (eq (include "flex-auth.callerAuth.enabled" .) "true") }}
egress:
{{- if eq (include "flex-auth.callerAuth.enabled" .) "true" }}
- ports:
- port: 443
protocol: TCP
- port: 6443
protocol: TCP
{{- end }}
{{- if .Values.auditDelivery.enabled }}
{{- if or (not (regexMatch "^[1-9][0-9]*$" (toString .Values.auditDelivery.receiverPort))) (lt (int .Values.auditDelivery.receiverPort) 1) (gt (int .Values.auditDelivery.receiverPort) 65535) }}
{{- fail "auditDelivery.receiverPort must be explicitly set to a valid receiver port" }}
{{- end }}
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ required "auditDelivery.receiverNamespace is required" .Values.auditDelivery.receiverNamespace | quote }}
podSelector:
matchLabels:
app.kubernetes.io/name: {{ required "auditDelivery.receiverPodName is required" .Values.auditDelivery.receiverPodName | quote }}
ports:
- port: {{ .Values.auditDelivery.receiverPort }}
protocol: TCP
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ required "auditDelivery.dnsNamespace is required" .Values.auditDelivery.dnsNamespace | quote }}
podSelector:
matchLabels:
k8s-app: {{ required "auditDelivery.dnsPodLabel is required" .Values.auditDelivery.dnsPodLabel | quote }}
ports:
- port: 53
protocol: UDP
- port: 53
protocol: TCP
{{- end }}
{{- else }}
egress: []
{{- end }}
{{- if .Values.consumer.isolated }}
ingress: []
{{- else }}
ingress:
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: {{ required "consumer.namespace is required when not isolated" .Values.consumer.namespace }}
podSelector:
matchLabels:
app.kubernetes.io/name: {{ required "consumer.podName is required when not isolated" .Values.consumer.podName }}
ports:
- port: {{ .Values.service.port }}
protocol: TCP
{{- end }}