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 | |
| 192 | {{- define "common.certManager.volumeMounts" -}} |
| 193 | {{- $dot := default . .dot -}} |
| 194 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 195 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 196 | {{- range $i, $certificate := $dot.Values.certificates -}} |
| 197 | {{- $mountPath := $certificate.mountPath -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 198 | - mountPath: {{ (printf "%s/secret-%d" $mountPath $i) }} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 199 | name: certmanager-certs-volume-{{ $i }} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 200 | - mountPath: {{ $mountPath }} |
| 201 | name: certmanager-certs-volume-{{ $i }}-dir |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 202 | {{- end -}} |
| 203 | {{- end -}} |
| 204 | |
| 205 | {{- define "common.certManager.volumes" -}} |
| 206 | {{- $dot := default . .dot -}} |
| 207 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 208 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 209 | {{- $certificates := $dot.Values.certificates -}} |
| 210 | {{- range $i, $certificate := $certificates -}} |
| 211 | {{- $name := include "common.fullname" $dot -}} |
| 212 | {{- $certificatesSecretName := default (printf "%s-secret-%d" $name $i) $certificate.secretName -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 213 | - name: certmanager-certs-volume-{{ $i }}-dir |
| 214 | emptyDir: {} |
Piotr Marcinkiewicz | 5957101 | 2021-01-12 17:37:08 +0100 | [diff] [blame] | 215 | - name: certmanager-certs-volume-{{ $i }} |
| 216 | projected: |
| 217 | sources: |
| 218 | - secret: |
| 219 | name: {{ $certificatesSecretName }} |
| 220 | {{- if $certificate.keystore }} |
| 221 | items: |
| 222 | {{- range $outputType := $certificate.keystore.outputType }} |
| 223 | - key: keystore.{{ $outputType }} |
| 224 | path: keystore.{{ $outputType }} |
| 225 | - key: truststore.{{ $outputType }} |
| 226 | path: truststore.{{ $outputType }} |
| 227 | {{- end }} |
| 228 | - secret: |
| 229 | name: {{ $certificate.keystore.passwordSecretRef.name }} |
| 230 | items: |
| 231 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 232 | path: keystore.pass |
| 233 | - key: {{ $certificate.keystore.passwordSecretRef.key }} |
| 234 | path: truststore.pass |
| 235 | {{- end }} |
| 236 | {{- end -}} |
| 237 | {{- end -}} |
Piotr Marcinkiewicz | af82e2b | 2021-02-11 11:23:31 +0100 | [diff] [blame] | 238 | |
| 239 | {{- define "common.certManager.linkVolumeMounts" -}} |
| 240 | {{- $dot := default . .dot -}} |
| 241 | {{- $initRoot := default $dot.Values.certManagerCertificate .initRoot -}} |
| 242 | {{- $subchartGlobal := mergeOverwrite (deepCopy $initRoot.global) $dot.Values.global -}} |
| 243 | {{- $certificates := $dot.Values.certificates -}} |
| 244 | {{- $certsLinkCommand := "" -}} |
| 245 | {{- range $i, $certificate := $certificates -}} |
| 246 | {{- $destnationPath := (required "'mountPath' for Certificate is required." $certificate.mountPath) -}} |
| 247 | {{- $sourcePath := (printf "%s/secret-%d/*" $destnationPath $i) -}} |
| 248 | {{- $certsLinkCommand = (printf "ln -s %s %s; %s" $sourcePath $destnationPath $certsLinkCommand) -}} |
| 249 | {{- end -}} |
| 250 | {{ $certsLinkCommand }} |
Piotr Marcinkiewicz | 3267293 | 2021-03-26 13:06:35 +0100 | [diff] [blame] | 251 | {{- end -}} |