blob: 81574ce97f122b11e4860b477376ed687a0244c7 [file] [log] [blame]
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +02001{{- /*
Mohammed Naser7d1623e2024-06-17 09:12:39 -04002Copyright Broadcom, Inc. All Rights Reserved.
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +02003SPDX-License-Identifier: APACHE-2.0
4*/}}
5
6{{- if .Values.networkPolicy.enabled }}
7kind: NetworkPolicy
8apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
9metadata:
10 name: {{ template "common.names.fullname" . }}
11 namespace: {{ include "common.names.namespace" . | quote }}
Mohammed Naser65cda132024-05-02 14:34:08 -040012 labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020013 app.kubernetes.io/component: keycloak
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020014 {{- if .Values.commonAnnotations }}
15 annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
16 {{- end }}
17spec:
Mohammed Naser65cda132024-05-02 14:34:08 -040018 {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020019 podSelector:
Mohammed Naser65cda132024-05-02 14:34:08 -040020 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
21 app.kubernetes.io/component: keycloak
22 policyTypes:
23 - Ingress
24 - Egress
25 {{- if .Values.networkPolicy.allowExternalEgress }}
26 egress:
27 - {}
28 {{- else }}
29 egress:
30 - ports:
31 # Allow dns resolution
32 - port: 53
33 protocol: UDP
34 - port: 53
35 protocol: TCP
36 {{- range $port := .Values.networkPolicy.kubeAPIServerPorts }}
37 - port: {{ $port }}
38 {{- end }}
39 # Allow connection to PostgreSQL
40 - ports:
41 - port: {{ include "keycloak.databasePort" . | trimAll "\"" | int }}
42 {{- if .Values.postgresql.enabled }}
43 to:
44 - podSelector:
45 matchLabels:
46 app.kubernetes.io/name: postgresql
47 app.kubernetes.io/instance: {{ .Release.Name }}
48 {{- end }}
49 # Allow connection to other keycloak nodes
50 - ports:
Mohammed Naser7d1623e2024-06-17 09:12:39 -040051 {{- /* Constant in code: https://github.com/keycloak/keycloak/blob/ce8e925c1ad9bf7a3180d1496e181aeea0ab5f8a/operator/src/main/java/org/keycloak/operator/Constants.java#L60 */}}
52 - port: 7800
Mohammed Naser65cda132024-05-02 14:34:08 -040053 - port: {{ .Values.containerPorts.http }}
54 {{- if .Values.tls.enabled }}
55 - port: {{ .Values.containerPorts.https }}
56 {{- end }}
57 to:
58 - podSelector:
59 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
60 app.kubernetes.io/component: keycloak
61 {{- if .Values.networkPolicy.extraEgress }}
62 {{- include "common.tplvalues.render" ( dict "value" .Values.networkPolicy.extraEgress "context" $ ) | nindent 4 }}
63 {{- end }}
64 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020065 ingress:
66 - ports:
Mohammed Naser7d1623e2024-06-17 09:12:39 -040067 {{- /* Constant in code: https://github.com/keycloak/keycloak/blob/ce8e925c1ad9bf7a3180d1496e181aeea0ab5f8a/operator/src/main/java/org/keycloak/operator/Constants.java#L60 */}}
68 - port: 7800
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020069 - port: {{ .Values.containerPorts.http }}
70 {{- if .Values.tls.enabled }}
71 - port: {{ .Values.containerPorts.https }}
72 {{- end }}
73 {{- if not .Values.networkPolicy.allowExternal }}
74 from:
75 - podSelector:
Mohammed Naser65cda132024-05-02 14:34:08 -040076 matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 14 }}
77 - podSelector:
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020078 matchLabels:
79 {{ template "common.names.fullname" . }}-client: "true"
Mohammed Naser65cda132024-05-02 14:34:08 -040080 {{- if .Values.networkPolicy.ingressNSMatchLabels }}
81 - namespaceSelector:
82 matchLabels:
83 {{- range $key, $value := .Values.networkPolicy.ingressNSMatchLabels }}
84 {{ $key | quote }}: {{ $value | quote }}
85 {{- end }}
86 {{- if .Values.networkPolicy.ingressNSPodMatchLabels }}
87 podSelector:
88 matchLabels:
89 {{- range $key, $value := .Values.networkPolicy.ingressNSPodMatchLabels }}
90 {{ $key | quote }}: {{ $value | quote }}
91 {{- end }}
92 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020093 {{- end }}
94 {{- end }}
Mohammed Naser65cda132024-05-02 14:34:08 -040095 {{- $extraIngress := coalesce .Values.networkPolicy.additionalRules .Values.networkPolicy.extraIngress }}
96 {{- if $extraIngress }}
97 {{- include "common.tplvalues.render" ( dict "value" $extraIngress "context" $ ) | nindent 4 }}
98 {{- end }}
Oleksandr Kozachenkob0093492023-09-06 21:43:47 +020099{{- end }}