Skip to content

Commit 7302aa9

Browse files
committed
fix(hosting): store the ClickHouse password in a Secret and URL-encode inline credentials
The chart-deployed ClickHouse now reads CLICKHOUSE_PASSWORD from a chart-owned Secret instead of a plaintext env value in the pod spec, and the CLICKHOUSE_URL helpers percent-encode inline usernames and passwords so special characters no longer produce an unparseable URL.
1 parent 4608012 commit 7302aa9

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

hosting/k8s/helm/templates/_helpers.tpl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,19 +434,23 @@ so any inner `${...}` reaches goose verbatim and fails URL parsing.
434434
CLICKHOUSE_PASSWORD must contain only URL-userinfo-safe characters — the
435435
value is substituted verbatim, so `@ : / ? # [ ] %` break the URL. Use a
436436
hex-encoded password or percent-encode before storing in the Secret.
437+
438+
Inline credentials (auth.* and external.* values) are percent-encoded via
439+
urlquery, so special characters are safe there — except spaces, which
440+
urlquery encodes as `+` and userinfo decoding keeps literal.
437441
*/}}
438442
{{- define "trigger-v4.clickhouse.url" -}}
439443
{{- if .Values.clickhouse.deploy -}}
440444
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
441445
{{- $secure := ternary "true" "false" .Values.clickhouse.secure -}}
442-
{{ $protocol }}://{{ .Values.clickhouse.auth.username }}:{{ .Values.clickhouse.auth.password }}@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
446+
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:{{ .Values.clickhouse.auth.password | urlquery }}@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
443447
{{- else if .Values.clickhouse.external.host -}}
444448
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
445449
{{- $secure := ternary "true" "false" .Values.clickhouse.external.secure -}}
446450
{{- if .Values.clickhouse.external.existingSecret -}}
447-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
451+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
448452
{{- else -}}
449-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
453+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
450454
{{- end -}}
451455
{{- end -}}
452456
{{- end }}
@@ -460,13 +464,13 @@ applies to the replication URL.
460464
{{- define "trigger-v4.clickhouse.replication.url" -}}
461465
{{- if .Values.clickhouse.deploy -}}
462466
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
463-
{{ $protocol }}://{{ .Values.clickhouse.auth.username }}:{{ .Values.clickhouse.auth.password }}@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
467+
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:{{ .Values.clickhouse.auth.password | urlquery }}@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
464468
{{- else if .Values.clickhouse.external.host -}}
465469
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
466470
{{- if .Values.clickhouse.external.existingSecret -}}
467-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
471+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
468472
{{- else -}}
469-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
473+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
470474
{{- end -}}
471475
{{- end -}}
472476
{{- end }}

hosting/k8s/helm/templates/clickhouse.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ data:
3131
{{- $content | nindent 4 }}
3232
{{- end }}
3333
---
34+
apiVersion: v1
35+
kind: Secret
36+
metadata:
37+
name: {{ include "trigger-v4.fullname" . }}-clickhouse
38+
labels:
39+
{{- $component := "clickhouse" }}
40+
{{- include "trigger-v4.componentLabels" (dict "Chart" .Chart "Release" .Release "Values" .Values "component" $component) | nindent 4 }}
41+
type: Opaque
42+
data:
43+
admin-password: {{ .Values.clickhouse.auth.password | b64enc | quote }}
44+
---
3445
{{- /* Reuse an existing data PVC instead of creating one via
3546
volumeClaimTemplates. Set explicitly through persistence.existingClaim,
3647
or detected automatically: upgrades from chart versions that bundled
@@ -63,6 +74,7 @@ spec:
6374
metadata:
6475
annotations:
6576
checksum/config: {{ .Values.clickhouse.configdFiles | toYaml | sha256sum }}
77+
checksum/secret: {{ .Values.clickhouse.auth.password | sha256sum }}
6678
{{- with .Values.clickhouse.podAnnotations }}
6779
{{- toYaml . | nindent 8 }}
6880
{{- end }}
@@ -89,7 +101,10 @@ spec:
89101
- name: CLICKHOUSE_USER
90102
value: {{ .Values.clickhouse.auth.username | quote }}
91103
- name: CLICKHOUSE_PASSWORD
92-
value: {{ .Values.clickhouse.auth.password | quote }}
104+
valueFrom:
105+
secretKeyRef:
106+
name: {{ include "trigger-v4.fullname" . }}-clickhouse
107+
key: admin-password
93108
- name: CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT
94109
value: "1"
95110
ports:

0 commit comments

Comments
 (0)