Validate Except of IPBlock for NetworkPolicy spec
This patch enhances the validation of Except field that the values will be rejected if they are not strictly within the CIDR range.
This commit is contained in:
@@ -165,8 +165,10 @@ func ValidateIPBlock(ipb *networking.IPBlock, fldPath *field.Path) field.ErrorLi
|
||||
allErrs = append(allErrs, field.Invalid(exceptPath, exceptIP, "not a valid CIDR"))
|
||||
return allErrs
|
||||
}
|
||||
if !cidrIPNet.Contains(exceptCIDR.IP) {
|
||||
allErrs = append(allErrs, field.Invalid(exceptPath, exceptCIDR.IP, "not within CIDR range"))
|
||||
cidrMaskLen, _ := cidrIPNet.Mask.Size()
|
||||
exceptMaskLen, _ := exceptCIDR.Mask.Size()
|
||||
if !cidrIPNet.Contains(exceptCIDR.IP) || cidrMaskLen >= exceptMaskLen {
|
||||
allErrs = append(allErrs, field.Invalid(exceptPath, exceptIP, "must be a strict subset of `cidr`"))
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
|
||||
Reference in New Issue
Block a user