-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Require canonicalization of NetworkDeviceData IPs #129219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require canonicalization of NetworkDeviceData IPs #129219
Conversation
| allErrs = append(allErrs, field.TooLong(fldPath.Child("hardwareAddress"), "" /* unused */, hardwareAddressMaxLength)) | ||
| } | ||
|
|
||
| allErrs = append(allErrs, validateSet(networkDeviceData.IPs, maxIPs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note , but I find this helpers very difficult to reason about
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I got it now, the first function validats, the second function checsk for dupes
| if err != nil { | ||
| return "", "" // will fail at IsValidCIDR | ||
| // must fail | ||
| return validation.IsValidCIDR(fldPath, address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self, this just do the same , parse the cidr, but throws the expected Errorlist
kubernetes/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go
Lines 402 to 409 in 21525f3
| func IsValidCIDR(fldPath *field.Path, value string) field.ErrorList { | |
| var allErrors field.ErrorList | |
| _, _, err := netutils.ParseCIDRSloppy(value) | |
| if err != nil { | |
| allErrors = append(allErrors, field.Invalid(fldPath, value, "must be a valid CIDR value, (e.g. 10.9.8.0/24 or 2001:db8::/64)")) | |
| } | |
| return allErrors | |
| } |
|
/lgtm good catch /assign @thockin |
|
LGTM label has been added. Git tree hash: b27063b6d83674146d8c27ad57c5d1f47937e1e6
|
|
/approve can I? |
|
/label api-review This blocks promotion to beta in 1.33. |
thockin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yongruilin @aaron-prindle another one :)
There's no reason to allow non-standard or non-canonical IP values in new APIs.
9315731 to
2636aa3
Compare
/lgtm |
|
LGTM label has been added. Git tree hash: 032dd381c867f92ac4b0f3712c0b0e0ee9ea5e14
|
|
/test pull-kubernetes-e2e-gce failed test is unrelated |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aojea, danwinship, LionelJouin, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What this PR does / why we need it:
Validates NetworkDeviceData more strictly. There's no reason to allow non-standard or non-canonical IP values in new APIs.
Which issue(s) this PR fixes:
None, but related to KEP-4858 (kubernetes/enhancements#4899) and #128786
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
/kind bug
/sig network
/cc @aojea
/assign @LionelJouin