Skip to content

Commit bfe6e48

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 94c7fb2 commit bfe6e48

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

hosting/k8s/helm/templates/_helpers.tpl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,31 +422,37 @@ ClickHouse hostname
422422
{{/*
423423
ClickHouse URL for application (with secure parameter)
424424
425-
Note on the external+existingSecret branch: the password is expanded via
426-
Kubernetes' `$(VAR)` syntax, not shell `${VAR}`. Kubelet substitutes
427-
`$(CLICKHOUSE_PASSWORD)` at container-creation time from the
425+
Note on the deploy and external+existingSecret branches: the password is
426+
expanded via Kubernetes' `$(VAR)` syntax, not shell `${VAR}`. Kubelet
427+
substitutes `$(CLICKHOUSE_PASSWORD)` at container-creation time from the
428428
CLICKHOUSE_PASSWORD env var declared just before CLICKHOUSE_URL in
429429
webapp.yaml. Shell-style `${...}` does not work here because
430430
`docker/scripts/entrypoint.sh` assigns CLICKHOUSE_URL to GOOSE_DBSTRING
431431
with a single-pass expansion (`export GOOSE_DBSTRING="$CLICKHOUSE_URL"`),
432432
so any inner `${...}` reaches goose verbatim and fails URL parsing.
433433
434434
CLICKHOUSE_PASSWORD must contain only URL-userinfo-safe characters — the
435-
value is substituted verbatim, so `@ : / ? # [ ] %` break the URL. Use a
436-
hex-encoded password or percent-encode before storing in the Secret.
435+
value is substituted verbatim, so `@ : / ? # [ ] %` break the URL. The
436+
chart-generated datastore password is hex, which is safe; a pinned
437+
auth.password or external Secret value must be URL-safe too.
438+
439+
Inline credentials (usernames and the external plain password) are
440+
percent-encoded via urlquery, so special characters are safe there —
441+
except spaces, which urlquery encodes as `+` and userinfo decoding keeps
442+
literal.
437443
*/}}
438444
{{- define "trigger-v4.clickhouse.url" -}}
439445
{{- if .Values.clickhouse.deploy -}}
440446
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
441447
{{- $secure := ternary "true" "false" .Values.clickhouse.secure -}}
442-
{{ $protocol }}://{{ .Values.clickhouse.auth.username }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
448+
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
443449
{{- else if .Values.clickhouse.external.host -}}
444450
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
445451
{{- $secure := ternary "true" "false" .Values.clickhouse.external.secure -}}
446452
{{- 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 }}
453+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
448454
{{- else -}}
449-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
455+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
450456
{{- end -}}
451457
{{- end -}}
452458
{{- end }}
@@ -460,13 +466,13 @@ applies to the replication URL.
460466
{{- define "trigger-v4.clickhouse.replication.url" -}}
461467
{{- if .Values.clickhouse.deploy -}}
462468
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
463-
{{ $protocol }}://{{ .Values.clickhouse.auth.username }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
469+
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
464470
{{- else if .Values.clickhouse.external.host -}}
465471
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
466472
{{- if .Values.clickhouse.external.existingSecret -}}
467-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
473+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
468474
{{- else -}}
469-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
475+
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
470476
{{- end -}}
471477
{{- end -}}
472478
{{- end }}

hosting/k8s/helm/templates/clickhouse.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
metadata:
6464
annotations:
6565
checksum/config: {{ .Values.clickhouse.configdFiles | toYaml | sha256sum }}
66+
checksum/secret: {{ .Values.clickhouse.auth.password | sha256sum }}
6667
{{- with .Values.clickhouse.podAnnotations }}
6768
{{- toYaml . | nindent 8 }}
6869
{{- end }}

0 commit comments

Comments
 (0)