[COMMON][CERTINIT] Generate cert with certInit
[oom.git] / kubernetes / common / certInitializer / templates / _certInitializer.yaml
1 {{/*
2 # Copyright © 2020 Bell Canada, Samsung Electronics
3 # Copyright © 2021 Orange
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 */}}
17
18
19
20 {{- define "common.certInitializer._aafConfigVolumeName" -}}
21   {{ include "common.fullname" . }}-aaf-config
22 {{- end -}}
23
24 {{- define "common.certInitializer._aafAddConfigVolumeName" -}}
25   {{ print "aaf-add-config" }}
26 {{- end -}}
27
28 {{/*
29   common templates to enable cert initialization for applictaions
30
31   In deployments/jobs/stateful include:
32   initContainers:
33     {{ include "common.certInitializer.initContainer" . | nindent XX }}
34
35   containers:
36     volumeMounts:
37       {{- include "common.certInitializer.volumeMount" . | nindent XX }}
38     volumes:
39       {{- include "common.certInitializer.volume" . | nindent XX}}
40 */}}
41 {{- define "common.certInitializer._initContainer" -}}
42 {{-   $dot := default . .dot -}}
43 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
44 {{-   $initName := default "certInitializer" -}}
45 {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
46 {{ include "common.readinessCheck.waitFor" $subchartDot }}
47 - name: {{ include "common.name" $dot }}-aaf-config
48   image: {{ include "repositoryGenerator.repository" $subchartDot }}/{{ $subchartDot.Values.global.aafAgentImage }}
49   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
50   volumeMounts:
51   - mountPath: {{ $initRoot.mountPath }}
52     name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
53   - mountPath: /opt/app/aaf_config/cert/truststoreONAPall.jks.b64
54     name: aaf-agent-certs
55     subPath: truststoreONAPall.jks.b64
56   - mountPath: /opt/app/aaf_config/cert/truststoreONAP.p12.b64
57     name: aaf-agent-certs
58     subPath: truststoreONAP.p12.b64
59   - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
60     mountPath: /opt/app/aaf_config/bin/retrieval_check.sh
61     subPath: retrieval_check.sh
62 {{-     if hasKey $initRoot "ingressTlsSecret" }}
63   - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
64     mountPath: /opt/app/aaf_config/bin/tls_certs_configure.sh
65     subPath: tls_certs_configure.sh
66 {{-     end }}
67 {{-     if $initRoot.aaf_add_config }}
68   - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
69     mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh
70     subPath: aaf-add-config.sh
71 {{-     end }}
72   command:
73     - sh
74     - -c
75     - |
76       /opt/app/aaf_config/bin/agent.sh
77       . /opt/app/aaf_config/bin/retrieval_check.sh
78 {{-     if hasKey $initRoot "ingressTlsSecret" }}
79       /opt/app/aaf_config/bin/tls_certs_configure.sh
80 {{-     end -}}
81 {{-     if $initRoot.aaf_add_config }}
82       /opt/app/aaf_config/bin/aaf-add-config.sh
83 {{-     end }}
84   env:
85     - name: APP_FQI
86       value: "{{ $initRoot.fqi }}"
87     - name: aaf_locate_url
88       value: "https://aaf-locate.{{ $dot.Release.Namespace}}:8095"
89     - name: aaf_locator_container
90       value: "oom"
91     - name: aaf_locator_container_ns
92       value: "{{ $dot.Release.Namespace }}"
93     - name: aaf_locator_fqdn
94       value: "{{ $initRoot.fqdn }}"
95     - name: aaf_locator_app_ns
96       value: "{{ $initRoot.app_ns }}"
97     - name: DEPLOY_FQI
98     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "login") | indent 6 }}
99     - name: DEPLOY_PASSWORD
100     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "password") | indent 6 }}
101   #Note: want to put this on Nodes, eventually
102     - name: cadi_longitude
103       value: "{{ default "52.3" $initRoot.cadi_longitude }}"
104     - name: cadi_latitude
105       value: "{{ default "13.2" $initRoot.cadi_latitude }}"
106   #Hello specific.  Clients don't don't need this, unless Registering with AAF Locator
107     - name: aaf_locator_public_fqdn
108       value: "{{ $initRoot.public_fqdn | default "" }}"
109 {{- end -}}
110
111 {{/*
112   This init container will import custom .pem certificates to truststoreONAPall.jks
113   Custom certificates must be placed in common/certInitializer/resources directory.
114
115   The feature is enabled by setting Values.global.importCustomCertsEnabled = true
116   It can be used independently of aafEnabled, however it requires the same includes
117   as describe above for _initContainer.
118
119   When AAF is enabled the truststoreONAPAll.jks (which contains AAF CA) will be used
120   to import custom certificates, otherwise the default java keystore will be used.
121
122   The updated truststore file will be placed in /updatedTruststore and can be mounted per component
123   to a specific path by defining Values.certInitializer.truststoreMountpath (see _trustStoreVolumeMount)
124   The truststore file will be available to mount even if no custom certificates were imported.
125 */}}
126 {{- define "common.certInitializer._initImportCustomCertsContainer" -}}
127 {{-   $dot := default . .dot -}}
128 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
129 {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }}
130 - name: {{ include "common.name" $dot }}-import-custom-certs
131   image: {{ include "repositoryGenerator.image.jre" $subchartDot }}
132   imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }}
133   securityContext:
134     runAsUser: 0
135   command:
136     - /bin/sh
137     - -c
138     - /root/import-custom-certs.sh
139   env:
140     - name: AAF_ENABLED
141       value: "{{  $subchartDot.Values.global.aafEnabled }}"
142     - name: TRUSTSTORE_OUTPUT_FILENAME
143       value: "{{ $initRoot.truststoreOutputFileName }}"
144     - name: TRUSTSTORE_PASSWORD
145     {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "truststore-creds" "key" "password") | indent 6 }}
146   volumeMounts:
147     - mountPath: /certs
148       name: aaf-agent-certs
149     - mountPath: /root/import-custom-certs.sh
150       name: aaf-agent-certs
151       subPath: import-custom-certs.sh
152     - mountPath: /updatedTruststore
153       name: updated-truststore
154 {{- end -}}
155
156 {{- define "common.certInitializer._volumeMount" -}}
157 {{-   $dot := default . .dot -}}
158 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
159 - mountPath: {{ $initRoot.appMountPath }}
160   name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
161 {{- end -}}
162
163 {{/*
164   This is used together with _initImportCustomCertsContainer
165   It mounts the updated truststore (with imported custom certificates) to the
166   truststoreMountpath defined in the values file for the component.
167 */}}
168 {{- define "common.certInitializer._trustStoreVolumeMount" -}}
169 {{-   $dot := default . .dot -}}
170 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
171 {{- if gt (len $initRoot.truststoreMountpath) 0 }}
172 - mountPath: {{ $initRoot.truststoreMountpath }}/{{ $initRoot.truststoreOutputFileName }}
173   name: updated-truststore
174   subPath: {{ $initRoot.truststoreOutputFileName }}
175 {{- end -}}
176 {{- end -}}
177
178 {{- define "common.certInitializer._volumes" -}}
179 {{-   $dot := default . .dot -}}
180 {{-   $initRoot := default $dot.Values.certInitializer .initRoot -}}
181 {{- $subchartDot := mergeOverwrite (deepCopy (omit $dot "Values")) (dict "Chart" (set (fromJson (toJson $dot.Chart)) "Name" $initRoot.nameOverride) "Values" (mergeOverwrite (deepCopy $initRoot) (dict "global" $dot.Values.global))) }}
182 - name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }}
183   emptyDir:
184     medium: Memory
185 - name: aaf-agent-certs
186   configMap:
187     name: {{ tpl $subchartDot.Values.certsCMName $subchartDot }}
188     defaultMode: 0700
189 - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }}
190   configMap:
191     name: {{ include "common.fullname" $subchartDot }}-add-config
192     defaultMode: 0700
193 {{-     if $dot.Values.global.importCustomCertsEnabled }}
194 - name: updated-truststore
195   emptyDir: {}
196 {{-     end -}}
197 {{- end -}}
198
199 {{- define "common.certInitializer.initContainer" -}}
200 {{-   $dot := default . .dot -}}
201   {{- if $dot.Values.global.importCustomCertsEnabled }}
202     {{ include "common.certInitializer._initImportCustomCertsContainer" . }}
203   {{- end -}}
204   {{- if $dot.Values.global.aafEnabled }}
205     {{ include "common.certInitializer._initContainer" . }}
206   {{- end -}}
207 {{- end -}}
208
209 {{- define "common.certInitializer.volumeMount" -}}
210 {{-   $dot := default . .dot -}}
211   {{- if $dot.Values.global.aafEnabled }}
212     {{- include "common.certInitializer._volumeMount" . }}
213   {{- end -}}
214   {{- if $dot.Values.global.importCustomCertsEnabled }}
215     {{- include "common.certInitializer._trustStoreVolumeMount" . }}
216   {{- end -}}
217 {{- end -}}
218
219 {{- define "common.certInitializer.volumes" -}}
220 {{-   $dot := default . .dot -}}
221   {{- if or ($dot.Values.global.aafEnabled ) ($dot.Values.global.importCustomCertsEnabled) }}
222     {{- include "common.certInitializer._volumes" . }}
223   {{- end -}}
224 {{- end -}}