Skip to content

Commit d1f4748

Browse files
committed
fix(helm): expand CLICKHOUSE_PASSWORD in webapp CLICKHOUSE_URL via kubelet
When clickhouse.external.existingSecret is set, the chart rendered the CLICKHOUSE_URL env var with a literal shell-style ${CLICKHOUSE_PASSWORD} placeholder, expecting bash to expand it at container start. But docker/scripts/entrypoint.sh hands the value straight to goose with a single-pass sh expansion (export GOOSE_DBSTRING="$CLICKHOUSE_URL"), so the inner ${...} reaches goose as literal text and breaks the ClickHouse migration: goose run: parse "http://default:${CLICKHOUSE_PASSWORD}@host:8123?secure=false": net/url: invalid userinfo Switch to Kubernetes' $(VAR) syntax in both clickhouse URL helpers. Kubelet substitutes $(CLICKHOUSE_PASSWORD) at container-creation time from the CLICKHOUSE_PASSWORD env var the chart already sets just before CLICKHOUSE_URL, so the URL arrives at the entrypoint with the real password already inlined — no entrypoint change needed, works for any container image / shell. The plain-password branch (no existingSecret) is unchanged. Operator caveat: CLICKHOUSE_PASSWORD must be URL-userinfo-safe because kubelet substitutes verbatim without percent-encoding. Hex-encoded passwords (e.g. openssl rand -hex 32) are safe by construction.
1 parent 41434b5 commit d1f4748

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

hosting/k8s/helm/templates/_helpers.tpl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@ ClickHouse hostname
400400

401401
{{/*
402402
ClickHouse URL for application (with secure parameter)
403+
404+
Note on the external+existingSecret branch: the password is expanded via
405+
Kubernetes' `$(VAR)` syntax, not shell `${VAR}`. Kubelet substitutes
406+
`$(CLICKHOUSE_PASSWORD)` at container-creation time from the
407+
CLICKHOUSE_PASSWORD env var declared just before CLICKHOUSE_URL in
408+
webapp.yaml. Shell-style `${...}` does not work here because
409+
`docker/scripts/entrypoint.sh` assigns CLICKHOUSE_URL to GOOSE_DBSTRING
410+
with a single-pass expansion (`export GOOSE_DBSTRING="$CLICKHOUSE_URL"`),
411+
so any inner `${...}` reaches goose verbatim and fails URL parsing.
412+
413+
CLICKHOUSE_PASSWORD must contain only URL-userinfo-safe characters — the
414+
value is substituted verbatim, so `@ : / ? # [ ] %` break the URL. Use a
415+
hex-encoded password or percent-encode before storing in the Secret.
403416
*/}}
404417
{{- define "trigger-v4.clickhouse.url" -}}
405418
{{- if .Values.clickhouse.deploy -}}
@@ -410,7 +423,7 @@ ClickHouse URL for application (with secure parameter)
410423
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
411424
{{- $secure := ternary "true" "false" .Values.clickhouse.external.secure -}}
412425
{{- if .Values.clickhouse.external.existingSecret -}}
413-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:${CLICKHOUSE_PASSWORD}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
426+
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
414427
{{- else -}}
415428
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
416429
{{- end -}}
@@ -419,6 +432,9 @@ ClickHouse URL for application (with secure parameter)
419432

420433
{{/*
421434
ClickHouse URL for replication (without secure parameter)
435+
436+
See the note on clickhouse.url above — same `$(VAR)` vs `${VAR}` rationale
437+
applies to the replication URL.
422438
*/}}
423439
{{- define "trigger-v4.clickhouse.replication.url" -}}
424440
{{- if .Values.clickhouse.deploy -}}
@@ -427,7 +443,7 @@ ClickHouse URL for replication (without secure parameter)
427443
{{- else if .Values.clickhouse.external.host -}}
428444
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
429445
{{- if .Values.clickhouse.external.existingSecret -}}
430-
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:${CLICKHOUSE_PASSWORD}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
446+
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
431447
{{- else -}}
432448
{{ $protocol }}://{{ .Values.clickhouse.external.username }}:{{ .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
433449
{{- end -}}

0 commit comments

Comments
 (0)