Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 1 | {{/* |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 2 | # Copyright © 2020 Bell Canada, Samsung Electronics |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 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 | |
| 19 | {{- define "common.certInitializer._aafConfigVolumeName" -}} |
| 20 | {{ include "common.fullname" . }}-aaf-config |
| 21 | {{- end -}} |
| 22 | |
| 23 | {{- define "common.certInitializer._aafAddConfigVolumeName" -}} |
| 24 | {{ print "aaf-add-config" }} |
| 25 | {{- end -}} |
| 26 | |
| 27 | {{/* |
| 28 | common templates to enable cert initialization for applictaions |
| 29 | |
| 30 | In deployments/jobs/stateful include: |
| 31 | initContainers: |
| 32 | {{ include "common.certInitializer.initContainer" . | nindent XX }} |
| 33 | |
| 34 | containers: |
| 35 | volumeMounts: |
| 36 | {{- include "common.certInitializer.volumeMount" . | nindent XX }} |
| 37 | volumes: |
| 38 | {{- include "common.certInitializer.volume" . | nindent XX}} |
| 39 | */}} |
| 40 | {{- define "common.certInitializer._initContainer" -}} |
| 41 | {{- $dot := default . .dot -}} |
| 42 | {{- $initRoot := default $dot.Values.certInitializer .initRoot -}} |
| 43 | {{- $initName := default "certInitializer" -}} |
Sylvain Desbureaux | 41cf72f | 2020-05-15 17:25:52 +0200 | [diff] [blame] | 44 | {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }} |
Krzysztof Opasiak | e9754a0 | 2020-07-16 21:06:39 +0200 | [diff] [blame] | 45 | {{ include "common.readinessCheck.waitFor" $subchartDot }} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 46 | - name: {{ include "common.name" $dot }}-aaf-config |
Sylvain Desbureaux | 145140b | 2020-11-19 16:48:39 +0100 | [diff] [blame] | 47 | image: {{ include "repositoryGenerator.repository" $subchartDot }}/{{ $subchartDot.Values.global.aafAgentImage }} |
Krzysztof Opasiak | 3e5fa9a | 2020-05-19 00:44:12 +0200 | [diff] [blame] | 48 | imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 49 | volumeMounts: |
| 50 | - mountPath: {{ $initRoot.mountPath }} |
| 51 | name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }} |
Krzysztof Opasiak | 95a5f84 | 2020-05-06 23:27:18 +0200 | [diff] [blame] | 52 | - mountPath: /opt/app/aaf_config/cert/truststoreONAPall.jks.b64 |
| 53 | name: aaf-agent-certs |
| 54 | subPath: truststoreONAPall.jks.b64 |
| 55 | - mountPath: /opt/app/aaf_config/cert/truststoreONAP.p12.b64 |
| 56 | name: aaf-agent-certs |
| 57 | subPath: truststoreONAP.p12.b64 |
Sylvain Desbureaux | b834159 | 2021-02-23 15:54:00 +0100 | [diff] [blame] | 58 | - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }} |
| 59 | mountPath: /opt/app/aaf_config/bin/retrieval_check.sh |
| 60 | subPath: retrieval_check.sh |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 61 | {{- if $initRoot.aaf_add_config }} |
| 62 | - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }} |
| 63 | mountPath: /opt/app/aaf_config/bin/aaf-add-config.sh |
| 64 | subPath: aaf-add-config.sh |
| 65 | {{- end }} |
| 66 | command: |
| 67 | - sh |
| 68 | - -c |
| 69 | - | |
| 70 | #!/usr/bin/env bash |
| 71 | /opt/app/aaf_config/bin/agent.sh |
Sylvain Desbureaux | b834159 | 2021-02-23 15:54:00 +0100 | [diff] [blame] | 72 | source /opt/app/aaf_config/bin/retrieval_check.sh |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 73 | {{- if $initRoot.aaf_add_config }} |
| 74 | /opt/app/aaf_config/bin/aaf-add-config.sh |
| 75 | {{- end }} |
| 76 | env: |
| 77 | - name: APP_FQI |
| 78 | value: "{{ $initRoot.fqi }}" |
| 79 | - name: aaf_locate_url |
| 80 | value: "https://aaf-locate.{{ $dot.Release.Namespace}}:8095" |
| 81 | - name: aaf_locator_container |
| 82 | value: "oom" |
| 83 | - name: aaf_locator_container_ns |
| 84 | value: "{{ $dot.Release.Namespace }}" |
| 85 | - name: aaf_locator_fqdn |
| 86 | value: "{{ $initRoot.fqdn }}" |
| 87 | - name: aaf_locator_app_ns |
| 88 | value: "{{ $initRoot.app_ns }}" |
| 89 | - name: DEPLOY_FQI |
| 90 | {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "login") | indent 6 }} |
| 91 | - name: DEPLOY_PASSWORD |
| 92 | {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "deployer-creds" "key" "password") | indent 6 }} |
| 93 | #Note: want to put this on Nodes, eventually |
| 94 | - name: cadi_longitude |
| 95 | value: "{{ default "52.3" $initRoot.cadi_longitude }}" |
| 96 | - name: cadi_latitude |
| 97 | value: "{{ default "13.2" $initRoot.cadi_latitude }}" |
| 98 | #Hello specific. Clients don't don't need this, unless Registering with AAF Locator |
| 99 | - name: aaf_locator_public_fqdn |
| 100 | value: "{{ $initRoot.public_fqdn | default "" }}" |
| 101 | {{- end -}} |
| 102 | |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 103 | {{/* |
| 104 | This init container will import custom .pem certificates to truststoreONAPall.jks |
| 105 | Custom certificates must be placed in common/certInitializer/resources directory. |
| 106 | |
| 107 | The feature is enabled by setting Values.global.importCustomCertsEnabled = true |
| 108 | It can be used independently of aafEnabled, however it requires the same includes |
| 109 | as describe above for _initContainer. |
| 110 | |
| 111 | When AAF is enabled the truststoreONAPAll.jks (which contains AAF CA) will be used |
| 112 | to import custom certificates, otherwise the default java keystore will be used. |
| 113 | |
| 114 | The updated truststore file will be placed in /updatedTruststore and can be mounted per component |
| 115 | to a specific path by defining Values.certInitializer.truststoreMountpath (see _trustStoreVolumeMount) |
| 116 | The truststore file will be available to mount even if no custom certificates were imported. |
| 117 | */}} |
| 118 | {{- define "common.certInitializer._initImportCustomCertsContainer" -}} |
| 119 | {{- $dot := default . .dot -}} |
| 120 | {{- $initRoot := default $dot.Values.certInitializer .initRoot -}} |
| 121 | {{- $subchartDot := fromJson (include "common.subChartDot" (dict "dot" $dot "initRoot" $initRoot)) }} |
| 122 | - name: {{ include "common.name" $dot }}-import-custom-certs |
Sylvain Desbureaux | 145140b | 2020-11-19 16:48:39 +0100 | [diff] [blame] | 123 | image: {{ include "repositoryGenerator.image.jre" $subchartDot }} |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 124 | imagePullPolicy: {{ $subchartDot.Values.global.pullPolicy | default $subchartDot.Values.pullPolicy }} |
| 125 | securityContext: |
| 126 | runAsUser: 0 |
| 127 | command: |
Sylvain Desbureaux | 3638967 | 2021-01-19 14:51:24 +0100 | [diff] [blame] | 128 | - /bin/sh |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 129 | - -c |
| 130 | - /root/import-custom-certs.sh |
| 131 | env: |
| 132 | - name: AAF_ENABLED |
| 133 | value: "{{ $subchartDot.Values.global.aafEnabled }}" |
| 134 | - name: TRUSTSTORE_OUTPUT_FILENAME |
| 135 | value: "{{ $initRoot.truststoreOutputFileName }}" |
| 136 | - name: TRUSTSTORE_PASSWORD |
| 137 | {{- include "common.secret.envFromSecretFast" (dict "global" $subchartDot "uid" "truststore-creds" "key" "password") | indent 6 }} |
| 138 | volumeMounts: |
| 139 | - mountPath: /certs |
| 140 | name: aaf-agent-certs |
| 141 | - mountPath: /root/import-custom-certs.sh |
| 142 | name: aaf-agent-certs |
| 143 | subPath: import-custom-certs.sh |
| 144 | - mountPath: /updatedTruststore |
| 145 | name: updated-truststore |
| 146 | {{- end -}} |
| 147 | |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 148 | {{- define "common.certInitializer._volumeMount" -}} |
| 149 | {{- $dot := default . .dot -}} |
| 150 | {{- $initRoot := default $dot.Values.certInitializer .initRoot -}} |
krishnaa96 | edf6f37 | 2020-09-09 09:30:58 +0530 | [diff] [blame] | 151 | - mountPath: {{ $initRoot.appMountPath }} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 152 | name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }} |
| 153 | {{- end -}} |
| 154 | |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 155 | {{/* |
| 156 | This is used together with _initImportCustomCertsContainer |
| 157 | It mounts the updated truststore (with imported custom certificates) to the |
| 158 | truststoreMountpath defined in the values file for the component. |
| 159 | */}} |
| 160 | {{- define "common.certInitializer._trustStoreVolumeMount" -}} |
| 161 | {{- $dot := default . .dot -}} |
| 162 | {{- $initRoot := default $dot.Values.certInitializer .initRoot -}} |
| 163 | {{- if gt (len $initRoot.truststoreMountpath) 0 }} |
| 164 | - mountPath: {{ $initRoot.truststoreMountpath }}/{{ $initRoot.truststoreOutputFileName }} |
| 165 | name: updated-truststore |
| 166 | subPath: {{ $initRoot.truststoreOutputFileName }} |
| 167 | {{- end -}} |
| 168 | {{- end -}} |
| 169 | |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 170 | {{- define "common.certInitializer._volumes" -}} |
| 171 | {{- $dot := default . .dot -}} |
| 172 | {{- $initRoot := default $dot.Values.certInitializer .initRoot -}} |
Krzysztof Opasiak | 3e5fa9a | 2020-05-19 00:44:12 +0200 | [diff] [blame] | 173 | {{- $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))) }} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 174 | - name: {{ include "common.certInitializer._aafConfigVolumeName" $dot }} |
| 175 | emptyDir: |
| 176 | medium: Memory |
Krzysztof Opasiak | 95a5f84 | 2020-05-06 23:27:18 +0200 | [diff] [blame] | 177 | - name: aaf-agent-certs |
| 178 | configMap: |
Krzysztof Opasiak | 75f1875 | 2020-09-09 20:32:56 +0200 | [diff] [blame] | 179 | name: {{ tpl $subchartDot.Values.certsCMName $subchartDot }} |
Krzysztof Opasiak | 95a5f84 | 2020-05-06 23:27:18 +0200 | [diff] [blame] | 180 | defaultMode: 0700 |
Krzysztof Opasiak | 108483c | 2020-05-14 01:44:30 +0200 | [diff] [blame] | 181 | - name: {{ include "common.certInitializer._aafAddConfigVolumeName" $dot }} |
| 182 | configMap: |
| 183 | name: {{ include "common.fullname" $subchartDot }}-add-config |
| 184 | defaultMode: 0700 |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 185 | {{- if $dot.Values.global.importCustomCertsEnabled }} |
| 186 | - name: updated-truststore |
| 187 | emptyDir: {} |
| 188 | {{- end -}} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 189 | {{- end -}} |
| 190 | |
| 191 | {{- define "common.certInitializer.initContainer" -}} |
| 192 | {{- $dot := default . .dot -}} |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 193 | {{- if $dot.Values.global.importCustomCertsEnabled }} |
| 194 | {{ include "common.certInitializer._initImportCustomCertsContainer" . }} |
| 195 | {{- end -}} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 196 | {{- if $dot.Values.global.aafEnabled }} |
| 197 | {{ include "common.certInitializer._initContainer" . }} |
| 198 | {{- end -}} |
| 199 | {{- end -}} |
| 200 | |
| 201 | {{- define "common.certInitializer.volumeMount" -}} |
| 202 | {{- $dot := default . .dot -}} |
| 203 | {{- if $dot.Values.global.aafEnabled }} |
| 204 | {{- include "common.certInitializer._volumeMount" . }} |
| 205 | {{- end -}} |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 206 | {{- if $dot.Values.global.importCustomCertsEnabled }} |
| 207 | {{- include "common.certInitializer._trustStoreVolumeMount" . }} |
| 208 | {{- end -}} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 209 | {{- end -}} |
| 210 | |
| 211 | {{- define "common.certInitializer.volumes" -}} |
| 212 | {{- $dot := default . .dot -}} |
Jozsef Csongvai | 9d4d5af | 2020-07-13 11:10:25 -0400 | [diff] [blame] | 213 | {{- if or ($dot.Values.global.aafEnabled ) ($dot.Values.global.importCustomCertsEnabled) }} |
Krzysztof Opasiak | 020cdb9 | 2020-05-01 01:46:37 +0200 | [diff] [blame] | 214 | {{- include "common.certInitializer._volumes" . }} |
| 215 | {{- end -}} |
| 216 | {{- end -}} |