Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 1 | {{/*# |
| 2 | # Copyright © 2020-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 | # This is a template for requesting a certificate from the cert-manager (https://cert-manager.io). |
| 18 | # |
| 19 | # To request a certificate following steps are to be done: |
| 20 | # - create an object 'certificates' in the values.yaml |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 21 | # - create a file templates/certificate.yaml and invoke the function "certManagerCertificate.certificate". |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 22 | # |
| 23 | # Here is an example of the certificate request for a component: |
| 24 | # |
| 25 | # Directory structure: |
| 26 | # component |
| 27 | # templates |
| 28 | # certifictes.yaml |
| 29 | # values.yaml |
| 30 | # |
| 31 | # To be added in the file certificates.yamll |
| 32 | # |
| 33 | # To be added in the file values.yaml |
| 34 | # 1. Minimal version (certificates only in PEM format) |
| 35 | # certificates: |
| 36 | # - commonName: component.onap.org |
| 37 | # |
| 38 | # 2. Extended version (with defined own issuer and additional certificate format): |
| 39 | # certificates: |
| 40 | # - name: onap-component-certificate |
| 41 | # secretName: onap-component-certificate |
| 42 | # commonName: component.onap.org |
| 43 | # dnsNames: |
| 44 | # - component.onap.org |
| 45 | # issuer: |
| 46 | # group: certmanager.onap.org |
| 47 | # kind: CMPv2Issuer |
| 48 | # name: cmpv2-issuer-for-the-component |
| 49 | # keystore: |
| 50 | # outputType: |
| 51 | # - p12 |
| 52 | # - jks |
| 53 | # passwordSecretRef: |
| 54 | # name: secret-name |
| 55 | # key: secret-key |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 56 | # create: true |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 57 | # |
| 58 | # Fields 'name', 'secretName' and 'commonName' are mandatory and required to be defined. |
| 59 | # Other mandatory fields for the certificate definition do not have to be defined directly, |
| 60 | # in that case they will be taken from default values. |
| 61 | # |
| 62 | # Default values are defined in file onap/values.yaml (see-> global.certificate.default) |
| 63 | # and can be overriden during onap installation process. |
| 64 | # |
| 65 | */}} |
| 66 | |
| 67 | {{- define "certManagerCertificate.certificate" -}} |
| 68 | {{- $dot := default . .dot -}} |
| 69 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 70 | |
| 71 | {{- $certificates := $dot.Values.certificates -}} |
| 72 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global }} |
| 73 | |
| 74 | {{ range $i, $certificate := $certificates }} |
| 75 | {{/*# General certifiacate attributes #*/}} |
| 76 | {{- $name := include "common.fullname" $dot -}} |
| 77 | {{- $certName := default (printf "%s-cert-%d" $name $i) $certificate.name -}} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 78 | {{- $secretName := default (printf "%s-secret-%d" $name $i) (tpl (default "" $certificate.secretName) $ ) -}} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 79 | {{- $commonName := (required "'commonName' for Certificate is required." $certificate.commonName) -}} |
| 80 | {{- $renewBefore := default $subchartGlobal.certificate.default.renewBefore $certificate.renewBefore -}} |
| 81 | {{- $duration := default $subchartGlobal.certificate.default.duration $certificate.duration -}} |
| 82 | {{- $namespace := $dot.Release.Namespace -}} |
| 83 | {{/*# SAN's #*/}} |
| 84 | {{- $dnsNames := $certificate.dnsNames -}} |
| 85 | {{- $ipAddresses := $certificate.ipAddresses -}} |
| 86 | {{- $uris := $certificate.uris -}} |
| 87 | {{- $emailAddresses := $certificate.emailAddresses -}} |
| 88 | {{/*# Subject #*/}} |
| 89 | {{- $subject := $subchartGlobal.certificate.default.subject -}} |
| 90 | {{- if $certificate.subject -}} |
| 91 | {{- $subject = $certificate.subject -}} |
| 92 | {{- end -}} |
| 93 | {{/*# Issuer #*/}} |
| 94 | {{- $issuer := $subchartGlobal.certificate.default.issuer -}} |
| 95 | {{- if $certificate.issuer -}} |
| 96 | {{- $issuer = $certificate.issuer -}} |
| 97 | {{- end -}} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 98 | {{/*# Secret #*/}} |
| 99 | {{ if $certificate.keystore -}} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 100 | {{- $passwordSecretRef := $certificate.keystore.passwordSecretRef -}} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 101 | {{- $password := include "common.createPassword" (dict "dot" $dot "uid" $certName) | quote -}} |
| 102 | {{- if $passwordSecretRef.create }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 103 | apiVersion: v1 |
| 104 | kind: Secret |
| 105 | metadata: |
| 106 | name: {{ $passwordSecretRef.name }} |
| 107 | namespace: {{ $namespace }} |
| 108 | type: Opaque |
| 109 | stringData: |
| 110 | {{ $passwordSecretRef.key }}: {{ $password }} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 111 | {{- end }} |
| 112 | {{ end -}} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 113 | --- |
| 114 | apiVersion: cert-manager.io/v1 |
| 115 | kind: Certificate |
| 116 | metadata: |
| 117 | name: {{ $certName }} |
| 118 | namespace: {{ $namespace }} |
| 119 | spec: |
| 120 | secretName: {{ $secretName }} |
| 121 | commonName: {{ $commonName }} |
| 122 | renewBefore: {{ $renewBefore }} |
| 123 | {{- if $duration }} |
| 124 | duration: {{ $duration }} |
| 125 | {{- end }} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 126 | {{- if $certificate.isCA }} |
| 127 | isCA: {{ $certificate.isCA }} |
| 128 | {{- end }} |
| 129 | {{- if $certificate.usages }} |
| 130 | usages: |
| 131 | {{- range $usage := $certificate.usages }} |
| 132 | - {{ $usage }} |
| 133 | {{- end }} |
| 134 | {{- end }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 135 | subject: |
| 136 | organizations: |
| 137 | - {{ $subject.organization }} |
| 138 | countries: |
| 139 | - {{ $subject.country }} |
| 140 | localities: |
| 141 | - {{ $subject.locality }} |
| 142 | provinces: |
| 143 | - {{ $subject.province }} |
| 144 | organizationalUnits: |
| 145 | - {{ $subject.organizationalUnit }} |
| 146 | {{- if $dnsNames }} |
| 147 | dnsNames: |
| 148 | {{- range $dnsName := $dnsNames }} |
| 149 | - {{ $dnsName }} |
| 150 | {{- end }} |
| 151 | {{- end }} |
| 152 | {{- if $ipAddresses }} |
| 153 | ipAddresses: |
| 154 | {{- range $ipAddress := $ipAddresses }} |
| 155 | - {{ $ipAddress }} |
| 156 | {{- end }} |
| 157 | {{- end }} |
| 158 | {{- if $uris }} |
| 159 | uris: |
| 160 | {{- range $uri := $uris }} |
| 161 | - {{ $uri }} |
| 162 | {{- end }} |
| 163 | {{- end }} |
| 164 | {{- if $emailAddresses }} |
| 165 | emailAddresses: |
| 166 | {{- range $emailAddress := $emailAddresses }} |
| 167 | - {{ $emailAddress }} |
| 168 | {{- end }} |
| 169 | {{- end }} |
| 170 | issuerRef: |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 171 | {{- if not (eq $issuer.kind "Issuer" ) }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 172 | group: {{ $issuer.group }} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 173 | {{- end }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 174 | kind: {{ $issuer.kind }} |
| 175 | name: {{ $issuer.name }} |
| 176 | {{- if $certificate.keystore }} |
| 177 | keystores: |
| 178 | {{- range $outputType := $certificate.keystore.outputType }} |
| 179 | {{- if eq $outputType "p12" }} |
| 180 | {{- $outputType = "pkcs12" }} |
| 181 | {{- end }} |
| 182 | {{ $outputType }}: |
| 183 | create: true |
| 184 | passwordSecretRef: |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 185 | name: {{ tpl (default "" $certificate.keystore.passwordSecretRef.name) $ }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 186 | key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 187 | {{- end }} |
| 188 | {{- end }} |
| 189 | {{ end }} |
| 190 | {{- end -}} |
| 191 | |
Remigiusz Janeczek | 9b00b56 | 2021-04-26 14:37:57 +0200 | [diff] [blame] | 192 | {{/*Using templates below allows read and write access to volume mounted at $mountPath*/}} |
| 193 | |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 194 | {{- define "common.certManager.volumeMounts" -}} |
| 195 | {{- $dot := default . .dot -}} |
| 196 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 197 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 198 | {{- range $i, $certificate := $dot.Values.certificates -}} |
| 199 | {{- $mountPath := $certificate.mountPath -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 200 | - mountPath: {{ (printf "%s/secret-%d" $mountPath $i) }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 201 | name: certmanager-certs-volume-{{ $i }} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 202 | - mountPath: {{ $mountPath }} |
| 203 | name: certmanager-certs-volume-{{ $i }}-dir |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 204 | {{- end -}} |
| 205 | {{- end -}} |
| 206 | |
| 207 | {{- define "common.certManager.volumes" -}} |
| 208 | {{- $dot := default . .dot -}} |
| 209 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 210 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 211 | {{- $certificates := $dot.Values.certificates -}} |
| 212 | {{- range $i, $certificate := $certificates -}} |
| 213 | {{- $name := include "common.fullname" $dot -}} |
| 214 | {{- $certificatesSecretName := default (printf "%s-secret-%d" $name $i) $certificate.secretName -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 215 | - name: certmanager-certs-volume-{{ $i }}-dir |
| 216 | emptyDir: {} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 217 | - name: certmanager-certs-volume-{{ $i }} |
| 218 | projected: |
| 219 | sources: |
| 220 | - secret: |
| 221 | name: {{ $certificatesSecretName }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 222 | items: |
Piotr Marcinkiewicz | 7062518 | 2021-04-29 17:02:37 +0200 | [diff] [blame^] | 223 | - key: tls.key |
| 224 | path: key.pem |
| 225 | - key: tls.crt |
| 226 | path: cert.pem |
| 227 | - key: ca.crt |
| 228 | path: cacert.pem |
| 229 | {{- if $certificate.keystore }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 230 | {{- range $outputType := $certificate.keystore.outputType }} |
| 231 | - key: keystore.{{ $outputType }} |
| 232 | path: keystore.{{ $outputType }} |
| 233 | - key: truststore.{{ $outputType }} |
| 234 | path: truststore.{{ $outputType }} |
| 235 | {{- end }} |
| 236 | - secret: |
| 237 | name: {{ $certificate.keystore.passwordSecretRef.name }} |
| 238 | items: |
| 239 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 240 | path: keystore.pass |
| 241 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 242 | path: truststore.pass |
| 243 | {{- end }} |
| 244 | {{- end -}} |
| 245 | {{- end -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 246 | |
| 247 | {{- define "common.certManager.linkVolumeMounts" -}} |
| 248 | {{- $dot := default . .dot -}} |
| 249 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 250 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 251 | {{- $certificates := $dot.Values.certificates -}} |
| 252 | {{- $certsLinkCommand := "" -}} |
| 253 | {{- range $i, $certificate := $certificates -}} |
| 254 | {{- $destnationPath := (required "'mountPath' for Certificate is required." $certificate.mountPath) -}} |
| 255 | {{- $sourcePath := (printf "%s/secret-%d/*" $destnationPath $i) -}} |
| 256 | {{- $certsLinkCommand = (printf "ln -s %s %s; %s" $sourcePath $destnationPath $certsLinkCommand) -}} |
| 257 | {{- end -}} |
| 258 | {{ $certsLinkCommand }} |
Remigiusz Janeczek | 9b00b56 | 2021-04-26 14:37:57 +0200 | [diff] [blame] | 259 | {{- end -}} |
| 260 | |
| 261 | {{/*Using templates below allows only read access to volume mounted at $mountPath*/}} |
| 262 | |
| 263 | {{- define "common.certManager.volumeMountsReadOnly" -}} |
| 264 | {{- $dot := default . .dot -}} |
| 265 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 266 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 267 | {{- range $i, $certificate := $dot.Values.certificates -}} |
| 268 | {{- $mountPath := $certificate.mountPath -}} |
| 269 | - mountPath: {{ $mountPath }} |
| 270 | name: certmanager-certs-volume-{{ $i }} |
| 271 | {{- end -}} |
| 272 | {{- end -}} |
| 273 | |
| 274 | {{- define "common.certManager.volumesReadOnly" -}} |
| 275 | {{- $dot := default . .dot -}} |
| 276 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 277 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 278 | {{- $certificates := $dot.Values.certificates -}} |
| 279 | {{- range $i, $certificate := $certificates -}} |
| 280 | {{- $name := include "common.fullname" $dot -}} |
| 281 | {{- $certificatesSecretName := default (printf "%s-secret-%d" $name $i) $certificate.secretName -}} |
| 282 | - name: certmanager-certs-volume-{{ $i }} |
| 283 | projected: |
| 284 | sources: |
| 285 | - secret: |
| 286 | name: {{ $certificatesSecretName }} |
Remigiusz Janeczek | 9b00b56 | 2021-04-26 14:37:57 +0200 | [diff] [blame] | 287 | items: |
Piotr Marcinkiewicz | 7062518 | 2021-04-29 17:02:37 +0200 | [diff] [blame^] | 288 | - key: tls.key |
| 289 | path: key.pem |
| 290 | - key: tls.crt |
| 291 | path: cert.pem |
| 292 | - key: ca.crt |
| 293 | path: cacert.pem |
| 294 | {{- if $certificate.keystore }} |
Remigiusz Janeczek | 9b00b56 | 2021-04-26 14:37:57 +0200 | [diff] [blame] | 295 | {{- range $outputType := $certificate.keystore.outputType }} |
| 296 | - key: keystore.{{ $outputType }} |
| 297 | path: keystore.{{ $outputType }} |
| 298 | - key: truststore.{{ $outputType }} |
| 299 | path: truststore.{{ $outputType }} |
| 300 | {{- end }} |
| 301 | - secret: |
| 302 | name: {{ $certificate.keystore.passwordSecretRef.name }} |
| 303 | items: |
| 304 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 305 | path: keystore.pass |
| 306 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 307 | path: truststore.pass |
| 308 | {{- end }} |
| 309 | {{- end -}} |
| 310 | {{- end -}} |