[COMMON] Add custom certs into AAF truststore
[oom.git] / kubernetes / common / cmpv2Certificate / templates / _certServiceClient.tpl
1 {{/*
2 # Copyright © 2021 Nokia
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 {{/*
18 In order to use certServiceClient it is needed do define certificates array in target component values.yaml. Each
19 certificate will be requested from separate init container
20
21 Minimum example of array in target component values.yaml:
22 certificates:
23   - mountPath:  /var/custom-certs
24     commonName: common-name
25
26 Full example (other fields are ignored):
27 certificates:
28   - mountPath:  /var/custom-certs
29     caName: RA
30     keystore:
31       outputType:
32         - jks
33     commonName: common-name
34     dnsNames:
35       - dns-name-1
36       - dns-name-2
37     ipAddresses:
38       - 192.168.0.1
39       - 192.168.0.2
40     emailAddresses:
41       - email-1@onap.org
42       - email-2@onap.org
43     uris:
44       - http://uri-1.onap.org
45       - http://uri-2.onap.org
46     subject:
47       organization: Linux-Foundation
48       country: US
49       locality: San Francisco
50       province: California
51       organizationalUnit: ONAP
52
53 There also need to be some includes used in a target component deployment (indent values may need to be adjusted):
54   1. In initContainers section:
55     {{ include "common.certServiceClient.initContainer" . | indent 6 }}
56   2. In volumeMounts section of container using certificates:
57     {{ include "common.certServiceClient.volumeMounts" . | indent 10 }}
58   3. In volumes section:
59     {{ include "common.certServiceClient.volumes" . | indent 8 }}
60
61 */}}
62
63 {{- define "common.certServiceClient.initContainer" -}}
64 {{- $dot := default . .dot -}}
65 {{- $initRoot := default $dot.Values.cmpv2Certificate .initRoot -}}
66 {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}}
67 {{- if and $subchartGlobal.cmpv2Enabled (not $subchartGlobal.CMPv2CertManagerIntegration) -}}
68 {{- range $index, $certificate := $dot.Values.certificates -}}
69 {{/*# General certifiacate attributes  #*/}}
70 {{- $commonName     := (required "'commonName' for Certificate is required." $certificate.commonName) -}}
71 {{/*# SAN's #*/}}
72 {{- $dnsNames       := default (list)    $certificate.dnsNames       -}}
73 {{- $ipAddresses    := default (list)    $certificate.ipAddresses    -}}
74 {{- $uris           := default (list)    $certificate.uris           -}}
75 {{- $emailAddresses := default (list)    $certificate.emailAddresses   -}}
76 {{- $sansList := concat $dnsNames $ipAddresses $uris $emailAddresses   -}}
77 {{- $sans := join "," $sansList }}
78 {{/*# Subject #*/}}
79 {{- $organization   := $subchartGlobal.certificate.default.subject.organization        -}}
80 {{- $country        := $subchartGlobal.certificate.default.subject.country             -}}
81 {{- $locality       := $subchartGlobal.certificate.default.subject.locality            -}}
82 {{- $province       := $subchartGlobal.certificate.default.subject.province            -}}
83 {{- $orgUnit        := $subchartGlobal.certificate.default.subject.organizationalUnit  -}}
84 {{- if $certificate.subject -}}
85 {{- $organization   := $certificate.subject.organization -}}
86 {{- $country        := $certificate.subject.country -}}
87 {{- $locality       := $certificate.subject.locality -}}
88 {{- $province       := $certificate.subject.province -}}
89 {{- $orgUnit        := $certificate.subject.organizationalUnit -}}
90 {{- end -}}
91 {{- $caName := default $subchartGlobal.platform.certServiceClient.envVariables.caName $certificate.caName -}}
92 {{- $outputType := $subchartGlobal.platform.certServiceClient.envVariables.outputType -}}
93 {{- if $certificate.keystore -}}
94 {{- $outputTypeList := (required "'outputType' in 'keystore' section is required." $certificate.keystore.outputType) -}}
95 {{- $outputType = mustFirst ($outputTypeList) | upper -}}
96 {{- end -}}
97 {{- $requestUrl := $subchartGlobal.platform.certServiceClient.envVariables.requestURL -}}
98 {{- $certPath := $subchartGlobal.platform.certServiceClient.envVariables.certPath -}}
99 {{- $requestTimeout := $subchartGlobal.platform.certServiceClient.envVariables.requestTimeout -}}
100 {{- $certificatesSecretMountPath := $subchartGlobal.platform.certServiceClient.secret.mountPath -}}
101 {{- $keystorePath := $subchartGlobal.platform.certServiceClient.envVariables.keystorePath -}}
102 {{- $keystorePassword := $subchartGlobal.platform.certServiceClient.envVariables.keystorePassword -}}
103 {{- $truststorePath := $subchartGlobal.platform.certServiceClient.envVariables.truststorePath -}}
104 {{- $truststorePassword := $subchartGlobal.platform.certServiceClient.envVariables.truststorePassword -}}
105 - name: certs-init-{{ $index }}
106   image: {{ include "repositoryGenerator.image.certserviceclient" $dot }}
107   imagePullPolicy: {{ $dot.Values.global.pullPolicy | default $dot.Values.pullPolicy }}
108   env:
109     - name: REQUEST_URL
110       value: {{ $requestUrl | quote }}
111     - name: REQUEST_TIMEOUT
112       value: {{ $requestTimeout | quote }}
113     - name: OUTPUT_PATH
114       value: {{ $certPath | quote }}
115     - name: OUTPUT_TYPE
116       value: {{ $outputType | quote }}
117     - name: CA_NAME
118       value: {{ $caName | quote }}
119     - name: COMMON_NAME
120       value: {{ $commonName | quote }}
121     - name: SANS
122       value: {{ $sans | quote }}
123     - name: ORGANIZATION
124       value: {{ $organization | quote }}
125     - name: ORGANIZATION_UNIT
126       value: {{ $orgUnit | quote }}
127     - name: LOCATION
128       value: {{ $locality | quote }}
129     - name: STATE
130       value: {{ $province | quote }}
131     - name: COUNTRY
132       value: {{ $country | quote }}
133     - name: KEYSTORE_PATH
134       value: {{ $keystorePath | quote }}
135     - name: KEYSTORE_PASSWORD
136       value: {{ $keystorePassword | quote }}
137     - name: TRUSTSTORE_PATH
138       value: {{ $truststorePath | quote }}
139     - name: TRUSTSTORE_PASSWORD
140       value: {{ $truststorePassword | quote }}
141   terminationMessagePath: /dev/termination-log
142   terminationMessagePolicy: File
143   volumeMounts:
144     - mountPath: {{ $certPath }}
145       name: cmpv2-certs-volume-{{ $index }}
146     - mountPath: {{ $certificatesSecretMountPath }}
147       name: certservice-tls-volume
148 {{- end -}}
149 {{- end -}}
150 {{- end -}}
151
152 {{- define "common.certServiceClient.volumes" -}}
153 {{- $dot := default . .dot -}}
154 {{- $initRoot := default $dot.Values.cmpv2Certificate .initRoot -}}
155 {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}}
156 {{- if and $subchartGlobal.cmpv2Enabled (not $subchartGlobal.CMPv2CertManagerIntegration) -}}
157 {{- $certificatesSecretName := $subchartGlobal.platform.certServiceClient.secret.name -}}
158 - name: certservice-tls-volume
159   secret:
160     secretName: {{ $certificatesSecretName }}
161 {{ range $index, $certificate := $dot.Values.certificates -}}
162 - name: cmpv2-certs-volume-{{ $index }}
163   emptyDir:
164     medium: Memory
165 {{- end -}}
166 {{- end -}}
167 {{- end -}}
168
169 {{- define "common.certServiceClient.volumeMounts" -}}
170 {{- $dot := default . .dot -}}
171 {{- $initRoot := default $dot.Values.cmpv2Certificate .initRoot -}}
172 {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}}
173 {{- if and $subchartGlobal.cmpv2Enabled (not $subchartGlobal.CMPv2CertManagerIntegration) -}}
174 {{- range $index, $certificate := $dot.Values.certificates -}}
175 {{- $mountPath := $certificate.mountPath -}}
176 - mountPath: {{ $mountPath }}
177   name: cmpv2-certs-volume-{{ $index }}
178 {{ end -}}
179 {{- end -}}
180 {{- end -}}