Skip to content
22 changes: 17 additions & 5 deletions charts/lerian-common/templates/_streaming.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,27 @@ global.streaming (all optional except brokers, which gates emission):
via useExistingSecret), so mechanism/username/TLS are validated regardless of the secret
source. When a mechanism is set it must be a supported one, a username is required, and
TLS must be on unless plaintext SASL is explicitly opted into. */ -}}
{{- if $saslMechanism -}}
{{- /* Normalize like lib-streaming does: the mechanism is case-insensitive and
TrimSpace'd, and an all-whitespace value means "no SASL" (disabled). The booleans
follow strconv.ParseBool (case-insensitive true/1/t). Validate on the normalized
values so a valid lowercase/whitespace-padded config is not falsely rejected. */ -}}
{{- $saslMechNorm := upper (trim (toString $saslMechanism)) -}}
{{- if $saslMechNorm -}}
{{- $allowedSasl := list "PLAIN" "SCRAM-SHA-256" "SCRAM-SHA-512" -}}
{{- if not (has $saslMechanism $allowedSasl) -}}
{{- fail (printf "\n[lerian-common] Unsupported STREAMING_SASL_MECHANISM %q — lib-streaming accepts only PLAIN, SCRAM-SHA-256, SCRAM-SHA-512.\n" $saslMechanism) -}}
{{- if not (has $saslMechNorm $allowedSasl) -}}
{{- fail (printf "\n[lerian-common] Unsupported STREAMING_SASL_MECHANISM %q — lib-streaming accepts only PLAIN, SCRAM-SHA-256, SCRAM-SHA-512 (case-insensitive).\n" $saslMechanism) -}}
{{- end -}}
{{- if not $saslUsername -}}
{{- if not (trim (toString $saslUsername)) -}}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
{{- fail (printf "\n[lerian-common] Value required but empty: STREAMING_SASL_USERNAME\n a SASL mechanism (%s) is set, which requires a username (and a password).\n set: configmap.STREAMING_SASL_USERNAME (or global.streaming.saslUsername)\n" $saslMechanism) -}}
{{- end -}}
{{- if not (or (eq (toString $tlsEnabled) "true") (eq (toString $saslAllowPlaintext) "true")) -}}
{{- /* Match strconv.ParseBool EXACTLY (what the runtime's GetenvBoolOrDefault uses): the
true set is 1/t/T/TRUE/true/True with no trimming — anything else (e.g. "TrUe", " true ")
parses as an error and the runtime falls back to false. Using lower()/trim() here would
wrongly accept those and ship a SASL-without-TLS config that crashes at bootstrap. */ -}}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
{{- $parseBoolTrue := list "1" "t" "T" "TRUE" "true" "True" -}}
{{- $tlsOn := has (toString $tlsEnabled) $parseBoolTrue -}}
{{- $plaintextOn := has (toString $saslAllowPlaintext) $parseBoolTrue -}}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
{{- if not (or $tlsOn $plaintextOn) -}}
Comment thread
guimoreirar marked this conversation as resolved.
{{- fail (printf "\n[lerian-common] SASL requires TLS: mechanism %s is set but STREAMING_TLS_ENABLED is not true.\n set: STREAMING_TLS_ENABLED=true (recommended), or opt into plaintext SASL with STREAMING_SASL_ALLOW_PLAINTEXT=true.\n" $saslMechanism) -}}
{{- end -}}
{{- end -}}
Expand Down
Loading