Skip to content

Commit 8395a3d

Browse files
committed
Add support to use kubernetes secrets for basicAuthUsers passwords
Signed-off-by: Vasil Vasilev <[email protected]>
1 parent 41d088a commit 8395a3d

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Diff for: deployment/helm/ditto/templates/nginx-auth.yaml

+15-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,21 @@ type: Opaque
2424
stringData:
2525
nginx.htpasswd: |-
2626
{{- if .Values.global.hashedBasicAuthUsers }}
27-
{{ range .Values.global.hashedBasicAuthUsers }}
28-
{{- . | indent 4 }}
29-
{{ end }}
27+
{{ range .Values.global.hashedBasicAuthUsers }}
28+
{{- . | indent 4 }}
29+
{{ end }}
3030
{{- else }}
31-
{{ range $key, $value := .Values.global.basicAuthUsers }}
32-
{{- (htpasswd $value.user $value.password) | indent 4 }}
33-
{{ end }}
34-
{{ end }}
31+
{{ range $key, $value := .Values.global.basicAuthUsers }}
32+
{{- if $value.secretName }}
33+
{{- $secret := lookup "v1" "Secret" $.Release.Namespace $value.secretName }}
34+
{{- if $secret }}
35+
{{- $passwordBase64 := index $secret.data $value.user}}
36+
{{- htpasswd $value.user ($passwordBase64 | b64dec) | indent 4 }}
37+
{{- end }}
38+
{{- else }}
39+
{{- (htpasswd $value.user $value.password) | indent 4 }}
40+
{{- end }}
41+
{{ end }}
42+
{{- end }}
3543
---
3644
{{- end }}

Diff for: deployment/helm/ditto/values.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ global:
6969
# maxAuthSubjectsCount the maximum possible number of authorization subjects in Ditto headers, default: 100
7070
maxAuthSubjectsCount: 100
7171
# basicAuthUsers configures several user/password combinations which the nginx of the Ditto chart will authenticate
72+
# secretName - name of kubernetes secret, containing password for user(s). secret.data must contain ${user}: passwordBase64
73+
# if provided, password from secret will be used. Single kubernetes secret can be used for all users, by adding row for each user.
7274
basicAuthUsers:
7375
# - user: ditto
7476
# password: ditto
77+
# secretName: ditto
7578
# - user: jane
7679
# password: janesPw
80+
# secretName: jane
7781
# hashedBasicAuthUsers configures a list of hashed .htpasswd username/password entries
7882
hashedBasicAuthUsers: []
7983
# jwtOnly controls whether only OpenID-Connect authentication is supported
@@ -172,9 +176,6 @@ global:
172176
podDeletionCostPatching:
173177
# enabled whether the pod-deletion-cost annotation patching should be enabled
174178
enabled: true
175-
# annotations defines k8s annotations to add to corresponding jobs
176-
annotations: {}
177-
178179

179180
## ----------------------------------------------------------------------------
180181
## dbconfig for mongodb connections

0 commit comments

Comments
 (0)