Skip to content

Commit 193880d

Browse files
committed
Add passwords generation to FerretDB
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 36d8855 commit 193880d

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎packages/apps/ferretdb/Chart.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 0.3.0
19+
version: 0.4.0
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: {{ .Release.Name }}-dashboard-resources
5+
rules:
6+
- apiGroups:
7+
- ""
8+
resources:
9+
- services
10+
resourceNames:
11+
- {{ .Release.Name }}
12+
verbs: ["get", "list", "watch"]
13+
- apiGroups:
14+
- ""
15+
resources:
16+
- secrets
17+
resourceNames:
18+
- {{ .Release.Name }}-credentials
19+
verbs: ["get", "list", "watch"]

‎packages/apps/ferretdb/templates/init-script.yaml‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace (printf "%s-credentials" .Release.Name) }}
2+
{{- $passwords := dict }}
3+
4+
{{- with (index $existingSecret "data") }}
5+
{{- range $k, $v := . }}
6+
{{- $_ := set $passwords $k (b64dec $v) }}
7+
{{- end }}
8+
{{- end }}
9+
10+
{{- range $user, $u := .Values.users }}
11+
{{- if $u.password }}
12+
{{- $_ := set $passwords $user $u.password }}
13+
{{- else if not (index $passwords $user) }}
14+
{{- $_ := set $passwords $user (randAlphaNum 16) }}
15+
{{- end }}
16+
{{- end }}
17+
18+
{{- if .Values.users }}
19+
apiVersion: v1
20+
kind: Secret
21+
metadata:
22+
name: {{ .Release.Name }}-credentials
23+
stringData:
24+
{{- range $user, $u := .Values.users }}
25+
{{ quote $user }}: {{ quote (index $passwords $user) }}
26+
{{- end }}
27+
{{- end }}
128
---
229
apiVersion: v1
330
kind: Secret
@@ -13,7 +40,7 @@ stringData:
1340
{{- range $user, $u := .Values.users }}
1441
SELECT 'CREATE ROLE {{ $user }} LOGIN INHERIT;'
1542
WHERE NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '{{ $user }}')\gexec
16-
ALTER ROLE {{ $user }} WITH PASSWORD '{{ $u.password }}' LOGIN INHERIT {{ ternary "REPLICATION" "NOREPLICATION" (default false $u.replication) }};
43+
ALTER ROLE {{ $user }} WITH PASSWORD '{{ index $passwords $user }}' LOGIN INHERIT {{ ternary "REPLICATION" "NOREPLICATION" (default false $u.replication) }};
1744
COMMENT ON ROLE {{ $user }} IS 'user managed by helm';
1845
{{- end }}
1946
EOT

0 commit comments

Comments
 (0)