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: {{ $global.Release.Name }}
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 For internal use only!
81 Generate a secret name based on provided name or UID.
82 If UID is provided then the name is generated by appending this UID right after
83 the chart name. If name is provided, it overrides the name generation algorith
84 and is used right away. Both name and uid strings may contain a template to be
87 The template takes below arguments:
88 - .global: environment (.)
89 - .uid: string that uniquely identifies this secret within a helm chart
90 - .name: string that can be used to override default name generation algorithm
91 and provide a custom name for the secret
93 {{- define "common.secret._genName" -}}
94 {{- $global := .global }}
95 {{- $uid := tpl (default "" .uid) $global }}
96 {{- $name := tpl (default "" .name) $global }}
97 {{- default (printf "%s-%s" (include "common.fullname" $global) $uid) $name }}
101 Get the real secret name by UID or name, based on the configuration provided by user.
102 User may decide to not create a new secret but reuse existing one for this deployment
103 (aka externalSecret). In this case the real name of secret to be used is different
104 than the one declared in secret definition. This easily retrieve current secret real
105 name based on declared name or UID even if it has been overrided by the user using
106 externalSecret option. You should use this template always when you need to reference
107 a secret created using common.secret template by name.
109 The template takes below arguments:
110 - .global: environment (.)
111 - .uid: string that uniquely identifies this secret within a helm chart
112 (can be omitted if name has been provided)
113 - .name: name which was used to declare a secret
114 (can be omitted if uid has been provided)
116 {{- define "common.secret.getSecretName" -}}
117 {{- $global := .global }}
118 {{- $targetName := include "common.secret._genName" (dict "global" $global "uid" .uid "name" .name) }}
119 {{- range $secret := $global.Values.secrets }}
120 {{- $currName := include "common.secret._genName" (dict "global" $global "uid" $secret.uid "name" $secret.name) }}
121 {{- if eq $currName $targetName }}
122 {{- $externalSecret := tpl (default "" $secret.externalSecret) $global }}
123 {{- default $currName $externalSecret }}
129 Convenience template which can be used to easily set the value of environment variable
130 to the value of a key in a secret.
132 It takes care of all name mangling, usage of external secrets etc.
134 The template takes below arguments:
135 - .global: environment (.)
136 - .uid: string that uniquely identifies this secret within a helm chart
137 (can be omitted if name has been provided)
138 - .name: name which was used to declare a secret
139 (can be omitted if uid has been provided)
140 - .key: Key within this secret which value should be assigned to this variable
144 - name: SECRET_PASSWORD
145 {{- include "common.secret.envFromSecret" (dict "global" . "uid" "secret" "key" "password") | indent 8}}
147 {{- define "common.secret.envFromSecret" -}}
151 name: {{ include "common.secret.getSecretName" . }}
156 Define secrets to be used by chart.
157 Every secret has a type which is one of:
159 Generic secret template that allows to input some raw data (from files).
160 File Input can be passed as list of files (filePaths) or as a single string
163 Type of secret which allows you to define a list of key value pairs.
164 The list is assiged to envs value. Every item may define below items:
166 Identifier of this value within secret
168 String that defines a value associated with given key.
169 This can be a simple string or a template.
171 Defines what to do if value is not provided by the user.
172 Available options are:
174 Generate a value by derriving it from master password
178 Type of secret that holds only the password.
179 Only two items can be defined for this type:
181 Equivalent of value field from genericKV
183 The same meaning as for genericKV policy field
185 Type of secret that holds both username and password.
186 Below fields are available:
188 The value for login key.
189 This can be a simple string or a template.
190 Providing a value for login is always required.
192 The value for password key.
193 This can be a simple string or a template.
195 The same meaning as the policy field in genericKV.
196 Only the policy for password can be set.
198 Every secret can be identified using:
200 A string to be appended to the chart fullname to generate a secret name.
202 Overrides default secret name generation and allows to set immutable
203 and globaly unique name
205 To allow sharing a secret between the components and allow to pre-deploy secrets
206 before ONAP deployment it is possible to use already existing secret instead of
207 creating a new one. For this purpose externalSecret field can be used. If value of
208 this field is evaluated to true no new secret is created, only the name of the
209 secret is aliased to the external one.
213 {{ include "common.secret" . }}
218 mysqlExternalSecret: "some-other-secret-name"
222 externalSecret: '{{ tpl .Values.passExternalSecret . }}'
224 login: '{{ .Values.mysqlLogin }}'
225 mysqlPassword: '{{ .Values.mysqlPassword }}'
226 passwordPolicy: generate
228 In the above example new secret is not going to be created.
229 Already existing one (some-other-secret-name) is going to be used.
230 To force creating a new one, just make sure that mysqlExternalSecret
234 {{- define "common.secret" -}}
236 {{- range $secret := .Values.secrets }}
237 {{- $name := include "common.secret._genName" (dict "global" $global "uid" $secret.uid "name" $secret.name) }}
238 {{- $type := default "generic" $secret.type }}
239 {{- $externalSecret := tpl (default "" $secret.externalSecret) $global }}
240 {{- if not $externalSecret }}
242 {{ include "common.secret._header" (dict "global" $global "name" $name) }}
244 {{- if eq $type "generic" }}
246 {{- range $curFilePath := $secret.filePaths }}
247 {{ tpl ($global.Files.Glob $curFilePath).AsSecrets $global | indent 2 }}
249 {{- if $secret.filePath }}
250 {{ tpl ($global.Files.Glob $secret.filePath).AsSecrets $global | indent 2 }}
252 {{- else if eq $type "genericKV" }}
254 {{- if $secret.envs }}
255 {{- range $secretEnv := $secret.envs }}
256 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
257 {{ $secretEnv.name }}: {{ include "common.secret._value" $valueDesc }}
260 {{- else if eq $type "password" }}
261 {{- $secretEnv := (dict "policy" (default "generate" $secret.policy) "name" "password" "value" $secret.password) }}
262 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
264 password: {{ include "common.secret._value" $valueDesc }}
265 {{- else if eq $type "basicAuth" }}
267 {{- $secretEnv := (dict "policy" "required" "name" "login" "value" $secret.login) }}
268 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
269 login: {{ include "common.secret._value" $valueDesc }}
270 {{- $secretEnv := (dict "policy" (default "generate" $secret.passwordPolicy) "name" "password" "value" $secret.password) }}
271 {{- $valueDesc := (dict "global" $global "secretName" $name "secretEnv" $secretEnv) }}
272 password: {{ include "common.secret._value" $valueDesc }}