fix(platform): reject out-of-range serviceCIDR

The clusterDNS derivation accepted any one-to-three-digit octet and any
two-digit prefix, so 10.96.256.0/24 carried into the previous octet and
derived 10.97.0.10. Bound each octet to 0-255 and the prefix to 0-32.

Assisted-by: LLM
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
This commit is contained in:
Timofei Larkin committed 2026-11-20 00:32:01 +01:00
1 parent d5957159d2
commit 0913b8d046
2 files changed
+27 -1

No files matched your search

@@ -94,7 +94,7 @@
{{- end -}}
{{- $clusterDNS := dig "clusterDNS" "" $net -}}
{{- if not $clusterDNS -}}
{{- if not (regexMatch "^([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$" $net.serviceCIDR) -}}
{{- if not (regexMatch "^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])/(3[0-2]|[12]?[0-9])$" $net.serviceCIDR) -}}
{{- fail (printf "cannot derive networking.clusterDNS from serviceCIDR %q (not an IPv4 CIDR); set networking.clusterDNS explicitly" $net.serviceCIDR) -}}
{{- end -}}
{{- $parts := splitList "/" $net.serviceCIDR -}}
@@ -370,6 +370,32 @@ tests:
- failedTemplate:
errorPattern: 'has no address 10 to derive networking.clusterDNS'
- it: refuses to derive clusterDNS from an out-of-range octet
set:
bundles:
system:
enabled: true
variant: isp-full
networkingVariant: cozyplane
networking:
serviceCIDR: "10.96.256.0/24"
asserts:
- failedTemplate:
errorPattern: 'cannot derive networking.clusterDNS from serviceCIDR "10.96.256.0/24"'
- it: refuses to derive clusterDNS from an out-of-range prefix
set:
bundles:
system:
enabled: true
variant: isp-full
networkingVariant: cozyplane
networking:
serviceCIDR: "10.96.0.0/33"
asserts:
- failedTemplate:
errorPattern: 'cannot derive networking.clusterDNS from serviceCIDR "10.96.0.0/33"'
# Disabling cozystack.networking is the documented way to keep a hand-set
# live variant: the guard must not run for a Package that is not rendered.
- it: renders with cozystack.networking disabled despite a different live variant