From a6be560ce470d602b5c78e572dd134ea6ca28795 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Wed, 4 Sep 2024 15:10:29 +0200 Subject: [PATCH] Add passwords generation to ClickHouse Signed-off-by: Andrei Kvapil --- packages/apps/clickhouse/Chart.yaml | 2 +- .../apps/clickhouse/templates/clickhouse.yaml | 33 +++++++++++++++++-- .../templates/dashboard-resourcemap.yaml | 19 +++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 packages/apps/clickhouse/templates/dashboard-resourcemap.yaml diff --git a/packages/apps/clickhouse/Chart.yaml b/packages/apps/clickhouse/Chart.yaml index 466917714..5dbf8e093 100644 --- a/packages/apps/clickhouse/Chart.yaml +++ b/packages/apps/clickhouse/Chart.yaml @@ -16,7 +16,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.3.0 +version: 0.4.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/packages/apps/clickhouse/templates/clickhouse.yaml b/packages/apps/clickhouse/templates/clickhouse.yaml index c2b0a5b28..11a057ca8 100644 --- a/packages/apps/clickhouse/templates/clickhouse.yaml +++ b/packages/apps/clickhouse/templates/clickhouse.yaml @@ -1,3 +1,32 @@ +{{- $existingSecret := lookup "v1" "Secret" .Release.Namespace (printf "%s-credentials" .Release.Name) }} +{{- $passwords := dict }} + +{{- with (index $existingSecret "data") }} + {{- range $k, $v := . }} + {{- $_ := set $passwords $k (b64dec $v) }} + {{- end }} +{{- end }} + +{{- range $user, $u := .Values.users }} + {{- if $u.password }} + {{- $_ := set $passwords $user $u.password }} + {{- else if not (index $passwords $user) }} + {{- $_ := set $passwords $user (randAlphaNum 16) }} + {{- end }} +{{- end }} + +{{- if .Values.users }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-credentials +stringData: + {{- range $user, $u := .Values.users }} + {{ quote $user }}: {{ quote (index $passwords $user) }} + {{- end }} +{{- end }} + +--- apiVersion: "clickhouse.altinity.com/v1" kind: "ClickHouseInstallation" metadata: @@ -12,7 +41,7 @@ spec: {{- with .Values.users }} users: {{- range $name, $u := . }} - {{ $name }}/password_sha256_hex: {{ sha256sum $u.password }} + {{ $name }}/password_sha256_hex: {{ sha256sum (index $passwords $name) }} {{ $name }}/profile: {{ ternary "readonly" "default" (index $u "readonly" | default false) }} {{ $name }}/networks/ip: ["::/0"] {{- end }} @@ -31,7 +60,7 @@ spec: spec: accessModes: - ReadWriteOnce - {{- with .Values.storageClass }} + {{- with $.Values.storageClass }} storageClassName: {{ . }} {{- end }} resources: diff --git a/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml b/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml new file mode 100644 index 000000000..f60409434 --- /dev/null +++ b/packages/apps/clickhouse/templates/dashboard-resourcemap.yaml @@ -0,0 +1,19 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ .Release.Name }}-dashboard-resources +rules: +- apiGroups: + - "" + resources: + - services + resourceNames: + - chi-clickhouse-test-clickhouse-0-0 + verbs: ["get", "list", "watch"] +- apiGroups: + - "" + resources: + - secrets + resourceNames: + - {{ .Release.Name }}-credentials + verbs: ["get", "list", "watch"]