2 # Copyright © 2019 AT&T, Samsung Electronics
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 For internal use only!
20 Generates a secret header with given name and desired labels.
22 The template takes two arguments:
23 - .global: environment (.)
24 - .name: name of the secret
27 {{ include "common.secret._header" (dict "global" . "name" "myFancyName") }}
29 {{- define "common.secret._header" -}}
30 {{- $global := .global }}
36 namespace: {{ include "common.namespace" $global }}
38 app: {{ include "common.name" $global }}
39 chart: {{ $global.Chart.Name }}-{{ $global.Chart.Version | replace "+" "_" }}
40 release: {{ include "common.release" $global }}
41 heritage: {{ $global.Release.Service }}
46 For internal use only!
48 Pick a value based on "user input" and generation policy.
50 The template takes below arguments:
51 - .global: environment (.)
52 - .secretName: name of the secret where the value will be placed
53 - .secretEnv: map of values which configures this secret. This can contain below keys:
54 - value: Value of secret key provided by user (can be a template inside a string)
55 - policy: What to do if value is missing or empty. Possible options are:
56 - generate: Generate a new password deriving it from master password
57 - required: Fail the deployment if value has not been provided
59 - name: Name of the key to which this value should be assigned
61 {{- define "common.secret._value" -}}
62 {{- $global := .global }}
63 {{- $name := .secretName }}
64 {{- $secretEnv := .secretEnv }}
65 {{- $value := tpl $secretEnv.value $global }}
66 {{- $policy := default "generate" $secretEnv.policy }}
70 {{- else if eq $policy "generate" }}
71 {{- include "common.createPassword" (dict "dot" $global "uid" $name) | quote }}
73 {{- fail (printf "Value for %s secret %s key not provided" $name $secretEnv.name) }}
79 Generate a secret name based on provided name or UID.
80 If UID is provided then the name is generated by appending this UID right after
81 the chart name. If name is provided, it overrides the name generation algorith
82 and is used right away. Both name and uid strings may contain a template to be
85 The template takes below arguments:
86 - .global: environment (.)
87 - .uid: string that uniquely identifies this secret within a helm chart
88 - .name: string that can be used to override default name generation algorithm
89 and provide a custom name for the secret
91 {{- define "common.secret.genName" -}}
92 {{- $global := .global }}
93 {{- $uid := tpl (default "" .uid) $global }}
94 {{- $name := tpl (default "" .name) $global }}
95 {{- $fullname := ne (default "" .chartName) "" | ternary (include "common.fullnameExplicit" (dict "dot" $global "chartName" .chartName)) (include "common.fullname" $global) }}
96 {{- default (printf "%s-%s" $fullname $uid) $name }}
100 Get the real secret name by UID or name, based on the configuration provided by user.
101 User may decide to not create a new secret but reuse existing one for this deployment
102 (aka externalSecret). In this case the real name of secret to be used is different
103 than the one declared in secret definition. This easily retrieve current secret real
104 name based on declared name or UID even if it has been overrided by the user using
105 externalSecret option. You should use this template always when you need to reference
106 a secret created using common.secret template by name.
108 The template takes below arguments:
109 - .global: environment (.)
110 - .uid: string that uniquely identifies this secret within a helm chart
111 (can be omitted if name has been provided)
112 - .name: name which was used to declare a secret
113 (can be omitted if uid has been provided)
115 {{- define "common.secret.getSecretName" -}}
116 {{- $global := .global }}
117 {{- $name := tpl (default "" .name) $global }}
118 {{- $uid := tpl (default "" .uid) $global }}
119 {{- $targetName := default (include "common.secret.genName" (dict "global" $global "uid" $uid "name" .name)) $name}}
120 {{- range $secret := $global.Values.secrets }}
121 {{- $givenName := tpl (default "" $secret.name) $global }}
122 {{- $currUID := tpl (default "" $secret.uid) $global }}
123 {{- $currName := default (include "common.secret.genName" (dict "global" $global "uid" $currUID "name" $secret.name)) $givenName }}
124 {{- if or (eq $uid $currUID) (eq $currName $targetName) }}
125 {{- $externalSecret := tpl (default "" $secret.externalSecret) $global }}
126 {{- default $currName $externalSecret }}
132 Convenience template which can be used to easily set the value of environment variable
133 to the value of a key in a secret.
135 It takes care of all name mangling, usage of external secrets etc.
137 The template takes below arguments:
138 - .global: environment (.)
139 - .uid: string that uniquely identifies this secret within a helm chart
140 (can be omitted if name has been provided)
141 - .name: name which was used to declare a secret
142 (can be omitted if uid has been provided)
143 - .key: Key within this secret which value should be assigned to this variable
147 - name: SECRET_PASSWORD
148 {{- include "common.secret.envFromSecret" (dict "global" . "uid" "secret" "key" "password") | indent 8}}
150 {{- define "common.secret.envFromSecret" -}}
154 name: {{ include "common.secret.getSecretName" . }}
159 Define secrets to be used by chart.
160 Every secret has a type which is one of:
162 Generic secret template that allows to input some raw data (from files).
163 File Input can be passed as list of files (filePaths) or as a single string
166 Type of secret which allows you to define a list of key value pairs.
167 The list is assiged to envs value. Every item may define below items:
169 Identifier of this value within secret
171 String that defines a value associated with given key.
172 This can be a simple string or a template.
174 Defines what to do if value is not provided by the user.
175 Available options are:
177 Generate a value by derriving it from master password
181 Type of secret that holds only the password.
182 Only two items can be defined for this type:
184 Equivalent of value field from genericKV
186 The same meaning as for genericKV policy field
188 Type of secret that holds both username and password.
189 Below fields are available:
191 The value for login key.
192 This can be a simple string or a template.
193 Providing a value for login is always required.
195 The value for password key.
196 This can be a simple string or a template.
198 The same meaning as the policy field in genericKV.
199 Only the policy for password can be set.
201 Every secret can be identified using:
203 A string to be appended to the chart fullname to generate a secret name.
205 Overrides default secret name generation and allows to set immutable
206 and globaly unique name
208 To allow sharing a secret between the components and allow to pre-deploy secrets
209 before ONAP deployment it is possible to use already existing secret instead of
210 creating a new one. For this purpose externalSecret field can be used. If value of
211 this field is evaluated to true no new secret is created, only the name of the
212 secret is aliased to the external one.
216 {{ include "common.secret" . }}
221 mysqlExternalSecret: "some-other-secret-name"
225 externalSecret: '{{ tpl .Values.passExternalSecret . }}'
227 login: '{{ .Values.mysqlLogin }}'
228 mysqlPassword: '{{ .Values.mysqlPassword }}'
229 passwordPolicy: generate
231 In the above example new secret is not going to be created.
232 Already existing one (some-other-secret-name) is going to be used.
233 To force creating a new one, just make sure that mysqlExternalSecret
237 {{- define "common.secret" -}}
239 {{- range $secret := .Values.secrets }}
240 {{- $uid := tpl (default "" $secret.uid) $global }}
241 {{- $name := include "common.secret.genName" (dict "global" $global "uid" $uid "name" $secret.name) }}
242 {{- $type := default "generic" $secret.type }}
243 {{- $externalSecret := tpl (default "" $secret.externalSecret) $global }}
244 {{- if not $externalSecret }}
246 {{ include "common.secret._header" (dict "global" $global "name" $name) }}
248 {{- if eq $type "generic" }}
250 {{- range $curFilePath := $secret.filePaths }}
251 {{ tpl ($global.Files.Glob $curFilePath).AsSecrets $global | indent 2 }}
253 {{- if $secret.filePath }}
254 {{ tpl ($global.Files.Glob $secret.filePath).AsSecrets $global | indent 2 }}
256 {{- else if eq $type "genericKV" }}
258 {{- if $secret.envs }}
259 {{- range $secretEnv := $secret.envs }}
260 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
261 {{ $secretEnv.name }}: {{ include "common.secret._value" $valueDesc }}
264 {{- else if eq $type "password" }}
265 {{- $secretEnv := (dict "policy" (default "generate" $secret.policy) "name" "password" "value" $secret.password) }}
266 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
268 password: {{ include "common.secret._value" $valueDesc }}
269 {{- else if eq $type "basicAuth" }}
271 {{- $secretEnv := (dict "policy" "required" "name" "login" "value" $secret.login) }}
272 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
273 login: {{ include "common.secret._value" $valueDesc }}
274 {{- $secretEnv := (dict "policy" (default "generate" $secret.passwordPolicy) "name" "password" "value" $secret.password) }}
275 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
276 password: {{ include "common.secret._value" $valueDesc }}