blob: 30d173c2d8fa1a7e750f641632c5cfe677101858 [file] [log] [blame]
AndrewLambbd6ff6b2023-05-04 15:56:49 +01001{{/*
2# Copyright © 2023 Nordix Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15*/}}
16
17{{ include "common.authorizationPolicy" . }}
18---
19{{- $dot := default . .dot -}}
20{{- $trustedDomain := default "cluster.local" $dot.Values.serviceMesh.authorizationPolicy.trustedDomain -}}
21{{- $authorizedPrincipalsPostgres := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipalsPostgres -}}
22{{- $defaultOperationPorts := list "5432" -}}
23{{- $relName := include "common.release" . -}}
24{{- $postgresName := $dot.Values.postgres.service.name -}}
25{{- if (include "common.useAuthorizationPolicies" .) }}
26apiVersion: security.istio.io/v1beta1
27kind: AuthorizationPolicy
28metadata:
29 name: {{ $relName }}-{{ $postgresName }}-authz
30 namespace: {{ include "common.namespace" . }}
31spec:
32 selector:
33 matchLabels:
34 app: {{ $postgresName }}
35 action: ALLOW
36 rules:
37{{- if $authorizedPrincipalsPostgres }}
38{{- range $principal := $authorizedPrincipalsPostgres }}
39 - from:
40 - source:
41 principals:
42{{- $namespace := default "onap" $principal.namespace -}}
43{{- if eq "onap" $namespace }}
44 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $relName }}-{{ $principal.serviceAccount }}"
45{{- else }}
46 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $principal.serviceAccount }}"
47{{- end }}
48 to:
49 - operation:
50 ports:
51{{- range $port := $defaultOperationPorts }}
52 - "{{ $port }}"
53{{- end }}
54{{- end }}
55{{- end }}
56{{- end }}
57---
58{{- $dot := default . .dot -}}
59{{- $trustedDomain := default "cluster.local" $dot.Values.serviceMesh.authorizationPolicy.trustedDomain -}}
60{{- $authorizedPrincipalsPostgres := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipalsPostgres -}}
61{{- $defaultOperationPorts := list "5432" -}}
62{{- $relName := include "common.release" . -}}
63{{- $postgresName := $dot.Values.postgres.service.name -}}
64{{- $pgHost := "primary" -}}
65{{- if (include "common.useAuthorizationPolicies" .) }}
66apiVersion: security.istio.io/v1beta1
67kind: AuthorizationPolicy
68metadata:
69 name: {{ $relName }}-{{ $postgresName }}-{{ $pgHost }}-authz
70 namespace: {{ include "common.namespace" . }}
71spec:
72 selector:
73 matchLabels:
74 app: {{ $postgresName }}-{{ $pgHost }}
75 action: ALLOW
76 rules:
77{{- if $authorizedPrincipalsPostgres }}
78{{- range $principal := $authorizedPrincipalsPostgres }}
79 - from:
80 - source:
81 principals:
82{{- $namespace := default "onap" $principal.namespace -}}
83{{- if eq "onap" $namespace }}
84 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $relName }}-{{ $principal.serviceAccount }}"
85{{- else }}
86 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $principal.serviceAccount }}"
87{{- end }}
88 to:
89 - operation:
90 ports:
91{{- range $port := $defaultOperationPorts }}
92 - "{{ $port }}"
93{{- end }}
94{{- end }}
95{{- end }}
96{{- end }}
97---
98{{- $dot := default . .dot -}}
99{{- $trustedDomain := default "cluster.local" $dot.Values.serviceMesh.authorizationPolicy.trustedDomain -}}
100{{- $authorizedPrincipalsPostgres := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipalsPostgres -}}
101{{- $defaultOperationPorts := list "5432" -}}
102{{- $relName := include "common.release" . -}}
103{{- $postgresName := $dot.Values.postgres.service.name -}}
104{{- $pgHost := "replica" -}}
105{{- if (include "common.useAuthorizationPolicies" .) }}
106apiVersion: security.istio.io/v1beta1
107kind: AuthorizationPolicy
108metadata:
109 name: {{ $relName }}-{{ $postgresName }}-{{ $pgHost }}-authz
110 namespace: {{ include "common.namespace" . }}
111spec:
112 selector:
113 matchLabels:
114 app: {{ $postgresName }}-{{ $pgHost }}
115 action: ALLOW
116 rules:
117{{- if $authorizedPrincipalsPostgres }}
118{{- range $principal := $authorizedPrincipalsPostgres }}
119 - from:
120 - source:
121 principals:
122{{- $namespace := default "onap" $principal.namespace -}}
123{{- if eq "onap" $namespace }}
124 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $relName }}-{{ $principal.serviceAccount }}"
125{{- else }}
126 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $principal.serviceAccount }}"
127{{- end }}
128 to:
129 - operation:
130 ports:
131{{- range $port := $defaultOperationPorts }}
132 - "{{ $port }}"
133{{- end }}
134{{- end }}
135{{- end }}
136{{- end }}