blob: 672ddf0b2f417527eb23835f7d52ea9c4c20f399 [file] [log] [blame]
AndrewLamb7709c172023-05-12 15:37:14 +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{{- $authorizedPrincipalsSdnHosts := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipalsSdnHosts -}}
22{{- $defaultOperationMethods := list "GET" "POST" "PUT" "PATCH" "DELETE" -}}
23{{- $relName := include "common.release" . -}}
24{{- if (include "common.useAuthorizationPolicies" .) }}
25apiVersion: security.istio.io/v1beta1
26kind: AuthorizationPolicy
27metadata:
28 name: sdnhost-{{ include "common.servicename" . }}-authz
29 namespace: {{ include "common.namespace" . }}
30spec:
31 selector:
32 matchLabels:
33 app: sdnhost-{{ include "common.name" . }}
34 action: ALLOW
35 rules:
36{{- if $authorizedPrincipalsSdnHosts }}
37{{- range $principal := $authorizedPrincipalsSdnHosts }}
38 - from:
39 - source:
40 principals:
41{{- $namespace := default "onap" $principal.namespace -}}
42{{- if eq "onap" $namespace }}
43 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $relName }}-{{ $principal.serviceAccount }}"
44{{- else }}
45 - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $principal.serviceAccount }}"
46{{- end }}
47 to:
48 - operation:
49 methods:
50{{- if $principal.allowedOperationMethods }}
51{{- range $method := $principal.allowedOperationMethods }}
52 - {{ $method }}
53{{- end }}
54{{- else }}
55{{- range $method := $defaultOperationMethods }}
56 - {{ $method }}
57{{- end }}
58{{- end }}
59{{- end }}
60{{- end }}
61{{- end }}