AndrewLamb | 0e7c7fe | 2023-05-17 14:13:54 +0100 | [diff] [blame] | 1 | {{/* |
| 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 | {{- $dot := default . .dot -}} |
| 18 | {{- $trustedDomain := default "cluster.local" $dot.Values.serviceMesh.authorizationPolicy.trustedDomain -}} |
| 19 | {{- $authorizedPrincipals := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipals -}} |
| 20 | {{- $authorizedPrincipalsMetrics := default list $dot.Values.serviceMesh.authorizationPolicy.authorizedPrincipalsMetrics -}} |
| 21 | {{- $defaultOperationMethods := list "GET" "POST" "PUT" "PATCH" "DELETE" -}} |
| 22 | {{- $relName := include "common.release" . -}} |
| 23 | |
| 24 | {{- if (include "common.useAuthorizationPolicies" .) }} |
| 25 | apiVersion: security.istio.io/v1beta1 |
| 26 | kind: AuthorizationPolicy |
| 27 | metadata: |
| 28 | name: {{ include "common.fullname" (dict "suffix" "authz" "dot" . )}} |
| 29 | namespace: {{ include "common.namespace" . }} |
| 30 | spec: |
| 31 | selector: |
| 32 | matchLabels: |
| 33 | app: {{ include "common.name" . }} |
| 34 | action: ALLOW |
| 35 | rules: |
| 36 | {{- if $authorizedPrincipals }} |
| 37 | {{- range $principal := $authorizedPrincipals }} |
| 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 }} |
| 62 | --- |
| 63 | {{- if (include "common.useAuthorizationPolicies" .) }} |
| 64 | apiVersion: security.istio.io/v1beta1 |
| 65 | kind: AuthorizationPolicy |
| 66 | metadata: |
| 67 | name: {{ include "common.fullname" (dict "suffix" "metrics-authz" "dot" . )}} |
| 68 | namespace: {{ include "common.namespace" . }} |
| 69 | spec: |
| 70 | selector: |
| 71 | matchLabels: |
| 72 | app: {{ include "common.name" . }}-metrics |
| 73 | action: ALLOW |
| 74 | rules: |
| 75 | {{- if $authorizedPrincipalsMetrics }} |
| 76 | {{- range $principal := $authorizedPrincipalsMetrics }} |
| 77 | - from: |
| 78 | - source: |
| 79 | principals: |
| 80 | {{- $namespace := default "onap" $principal.namespace -}} |
| 81 | {{- if eq "onap" $namespace }} |
| 82 | - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $relName }}-{{ $principal.serviceAccount }}" |
| 83 | {{- else }} |
| 84 | - "{{ $trustedDomain }}/ns/{{ $namespace }}/sa/{{ $principal.serviceAccount }}" |
| 85 | {{- end }} |
| 86 | to: |
| 87 | - operation: |
| 88 | methods: |
| 89 | {{- if $principal.allowedOperationMethods }} |
| 90 | {{- range $method := $principal.allowedOperationMethods }} |
| 91 | - {{ $method }} |
| 92 | {{- end }} |
| 93 | {{- else }} |
| 94 | {{- range $method := $defaultOperationMethods }} |
| 95 | - {{ $method }} |
| 96 | {{- end }} |
| 97 | {{- end }} |
| 98 | {{- end }} |
| 99 | {{- end }} |
| 100 | {{- end }} |