Skip to content

Commit 785ec40

Browse files
committed
Fix validation of CIDR fields
isCIDR() accepts both "mask-like" CIDRs and "address-like" CIDRs
1 parent 4d38b37 commit 785ec40

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

apis/v1alpha1/shared_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ type AdminNetworkPolicyIngressPeer struct {
134134
}
135135

136136
// CIDR is an IP address range in CIDR notation (for example, "10.0.0.0/8" or "fd00::/8").
137-
// +kubebuilder:validation:XValidation:rule="isCIDR(self)",message="Invalid CIDR format provided"
137+
// +kubebuilder:validation:XValidation:rule="isCIDR(self) && cidr(self) == cidr(self).masked()",message="Invalid CIDR format provided"
138138
// +kubebuilder:validation:MaxLength=43
139139
type CIDR string

apis/v1alpha2/clusternetworkpolicy_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ type PortRange struct {
465465

466466
// CIDR is an IP address range in CIDR notation
467467
// (for example, "10.0.0.0/8" or "fd00::/8").
468-
// +kubebuilder:validation:XValidation:rule="isCIDR(self)",message="Invalid CIDR format provided"
468+
// +kubebuilder:validation:XValidation:rule="isCIDR(self) && cidr(self) == cidr(self).masked()",message="Invalid CIDR format provided"
469469
// +kubebuilder:validation:MaxLength=43
470470
type CIDR string
471471

config/crd/experimental/policy.networking.k8s.io_clusternetworkpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ spec:
305305
type: string
306306
x-kubernetes-validations:
307307
- message: Invalid CIDR format provided
308-
rule: isCIDR(self)
308+
rule: isCIDR(self) && cidr(self) == cidr(self).masked()
309309
maxItems: 25
310310
minItems: 1
311311
type: array

config/crd/standard/policy.networking.k8s.io_clusternetworkpolicies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ spec:
259259
type: string
260260
x-kubernetes-validations:
261261
- message: Invalid CIDR format provided
262-
rule: isCIDR(self)
262+
rule: isCIDR(self) && cidr(self) == cidr(self).masked()
263263
maxItems: 25
264264
minItems: 1
265265
type: array

0 commit comments

Comments
 (0)