mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(kubernetes): reject invalid UTF-8 sysctl file values
Raw Helm file inputs can carry invalid UTF-8 that Go quoting turns into different Unicode characters. Reject these bytes rather than silently changing the requested worker configuration. Assisted-by: LLM Signed-off-by: Michel Jansen <mjansen@whero.xyz>
This commit is contained in:
1 parent
7d9f913350
commit
9b6128d3ca
2 files changed
+23
No files matched your search
@@ -251,3 +251,19 @@ VALUES
|
||||
done
|
||||
rm -rf "$TMP"
|
||||
}
|
||||
|
||||
@test "sysctl file values reject invalid UTF-8 rather than changing their bytes" {
|
||||
TMP=$(mktemp -d)
|
||||
# --set-file reads raw bytes, unlike the YAML/JSON-facing application API.
|
||||
for bytes in '\377' '\300\257' '\342\202'; do
|
||||
printf '%b' "$bytes" > "$TMP/value"
|
||||
if render_pool "$TMP/r.yaml" --skip-schema-validation --set-file "talos.sysctls.kernel\\.panic=$TMP/value"; then
|
||||
echo "FAIL: accepted invalid UTF-8 sysctl bytes: $bytes"
|
||||
false
|
||||
fi
|
||||
grep -Fq 'must be valid UTF-8' "$TMP/r.yaml.err"
|
||||
done
|
||||
printf '\357\277\275' > "$TMP/value"
|
||||
render_pool "$TMP/r.yaml" --skip-schema-validation --set-file "talos.sysctls.kernel\\.panic=$TMP/value"
|
||||
rm -rf "$TMP"
|
||||
}
|
||||
@@ -51,6 +51,13 @@
|
||||
{{- if not (kindIs "string" $value) }}
|
||||
{{- fail (printf "talos.sysctls[%q] must be a string" $key) }}
|
||||
{{- end }}
|
||||
{{- /* JSON replaces invalid UTF-8 with replacement runes. Comparing the
|
||||
round-trip detects raw --set-file bytes that quote would change into
|
||||
different Unicode characters in the machine config. */}}
|
||||
{{- $roundTrip := dict "value" $value | toJson | fromJson }}
|
||||
{{- if ne $value $roundTrip.value }}
|
||||
{{- fail (printf "talos.sysctls[%q] must be valid UTF-8" $key) }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $kubeletVersion := include "kubernetes.versionMap" $root | trim }}
|
||||
|
||||
Reference in new issue
Block a user