Skip to content

Commit 93018c4

Browse files
authored
Add passwords generation to ClickHouse (#332)
Signed-off-by: Andrei Kvapil <[email protected]> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Updated Clickhouse application to version 0.4.0, indicating new enhancements. - Improved user credential management by dynamically generating passwords or using provided ones, enhancing security. - Introduced a new Kubernetes Role for managing access to services and secrets, ensuring better control over resource interactions. - **Bug Fixes** - Corrected the reference for accessing the storage class value to ensure proper retrieval. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Andrei Kvapil <[email protected]>
1 parent b00621e commit 93018c4

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

‎packages/apps/clickhouse/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

‎packages/apps/clickhouse/templates/clickhouse.yaml‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
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 }}
28+
29+
---
130
apiVersion: "clickhouse.altinity.com/v1"
231
kind: "ClickHouseInstallation"
332
metadata:
@@ -12,7 +41,7 @@ spec:
1241
{{- with .Values.users }}
1342
users:
1443
{{- range $name, $u := . }}
15-
{{ $name }}/password_sha256_hex: {{ sha256sum $u.password }}
44+
{{ $name }}/password_sha256_hex: {{ sha256sum (index $passwords $name) }}
1645
{{ $name }}/profile: {{ ternary "readonly" "default" (index $u "readonly" | default false) }}
1746
{{ $name }}/networks/ip: ["::/0"]
1847
{{- end }}
@@ -31,7 +60,7 @@ spec:
3160
spec:
3261
accessModes:
3362
- ReadWriteOnce
34-
{{- with .Values.storageClass }}
63+
{{- with $.Values.storageClass }}
3564
storageClassName: {{ . }}
3665
{{- end }}
3766
resources:
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+
- chi-clickhouse-test-clickhouse-0-0
12+
verbs: ["get", "list", "watch"]
13+
- apiGroups:
14+
- ""
15+
resources:
16+
- secrets
17+
resourceNames:
18+
- {{ .Release.Name }}-credentials
19+
verbs: ["get", "list", "watch"]

0 commit comments

Comments
 (0)