Skip to content

Commit 3d68ee0

Browse files
committed
fix(hosting): percent-encode spaces correctly in ClickHouse URL credentials
urlquery encodes spaces as plus signs, which URL userinfo decoding keeps literal. A shared urlencode helper rewrites them to %20 (a real plus already encodes as %2B), so passwords containing spaces now work.
1 parent bfe6e48 commit 3d68ee0

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

hosting/k8s/helm/templates/_helpers.tpl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,16 @@ http://{{ include "trigger-v4.fullname" . }}-s2:{{ .Values.s2.service.port }}/v1
408408
{{- end -}}
409409
{{- end }}
410410

411+
{{/*
412+
Percent-encode a string for the userinfo part of a URL. urlquery encodes
413+
spaces as `+` (query semantics), which userinfo decoding keeps literal; a
414+
real `+` becomes `%2B`, so any `+` left in the output is a space and can be
415+
rewritten to `%20`.
416+
*/}}
417+
{{- define "trigger-v4.urlencode" -}}
418+
{{- . | urlquery | replace "+" "%20" -}}
419+
{{- end }}
420+
411421
{{/*
412422
ClickHouse hostname
413423
*/}}
@@ -437,22 +447,20 @@ chart-generated datastore password is hex, which is safe; a pinned
437447
auth.password or external Secret value must be URL-safe too.
438448
439449
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.
450+
percent-encoded, so any special characters are safe there.
443451
*/}}
444452
{{- define "trigger-v4.clickhouse.url" -}}
445453
{{- if .Values.clickhouse.deploy -}}
446454
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
447455
{{- $secure := ternary "true" "false" .Values.clickhouse.secure -}}
448-
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
456+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.auth.username }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}?secure={{ $secure }}
449457
{{- else if .Values.clickhouse.external.host -}}
450458
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
451459
{{- $secure := ternary "true" "false" .Values.clickhouse.external.secure -}}
452460
{{- if .Values.clickhouse.external.existingSecret -}}
453-
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
461+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
454462
{{- else -}}
455-
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
463+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.external.username }}:{{ include "trigger-v4.urlencode" .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}?secure={{ $secure }}
456464
{{- end -}}
457465
{{- end -}}
458466
{{- end }}
@@ -466,13 +474,13 @@ applies to the replication URL.
466474
{{- define "trigger-v4.clickhouse.replication.url" -}}
467475
{{- if .Values.clickhouse.deploy -}}
468476
{{- $protocol := ternary "https" "http" .Values.clickhouse.secure -}}
469-
{{ $protocol }}://{{ .Values.clickhouse.auth.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
477+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.auth.username }}:$(CLICKHOUSE_PASSWORD)@{{ include "trigger-v4.clickhouse.hostname" . }}:{{ .Values.clickhouse.service.ports.http }}
470478
{{- else if .Values.clickhouse.external.host -}}
471479
{{- $protocol := ternary "https" "http" .Values.clickhouse.external.secure -}}
472480
{{- if .Values.clickhouse.external.existingSecret -}}
473-
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
481+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.external.username }}:$(CLICKHOUSE_PASSWORD)@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
474482
{{- else -}}
475-
{{ $protocol }}://{{ .Values.clickhouse.external.username | urlquery }}:{{ .Values.clickhouse.external.password | urlquery }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
483+
{{ $protocol }}://{{ include "trigger-v4.urlencode" .Values.clickhouse.external.username }}:{{ include "trigger-v4.urlencode" .Values.clickhouse.external.password }}@{{ .Values.clickhouse.external.host }}:{{ .Values.clickhouse.external.httpPort | default 8123 }}
476484
{{- end -}}
477485
{{- end -}}
478486
{{- end }}

0 commit comments

Comments
 (0)