Skip to content

Conversation

thockin
Copy link
Member

@thockin thockin commented Jun 26, 2021

/kind bug

What this PR does / why we need it:

This forks Go's ParseIP() and ParseCIDR() functions and reverts https://go-review.googlesource.com/c/go/+/325829/ , which changed the parsing to error on leading zeros. We don't know if anyone has stored objects with those leading zeros, so this represents an unknown break for us.

Which issue(s) this PR fixes:

xref kubernetes/kubernetes#100895

Release note:

Add k8s.io/utils/net.ParseIP() and k8s.io/utils/net.ParseCIDR() functions.  ALL KUBERNETES CODE should use these instead of the standard equivalents.  They are identical in every way except the parsing of leading zeros.

cc @liggitt

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 26, 2021
@k8s-ci-robot k8s-ci-robot requested review from lavalamp and mcrute June 26, 2021 04:33
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 26, 2021
Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you envision trying to transition API validation to require new objects to pass the stricter stdlib methods over time?

ALL KUBERNETES CODE should use these instead of the standard equivalents. They are identical in every way except the parsing of leading zeros.

That's not going to stick (in this repo or in kubernetes/kubernetes) unless we have some sort of static analysis ensuring that happens. Any ideas for that (starting in this repo would be a good first step).

var parseIPTests = []struct {
in string
out IP
}{
{"127.0.1.2", IPv4(127, 0, 1, 2)},
{"127.0.0.1", IPv4(127, 0, 0, 1)},
{"127.001.002.003", IPv4(127, 1, 2, 3)}, // see https://issue.k8s.io/100895
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one that demonstrates it parses as decimal as well?

{"127.010.020.030", IPv4(127, 10, 20, 30)}, // see https://issue.k8s.io/100895

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. Also will test 007 vs 008 to prove octal's edge

@liggitt
Copy link
Member

liggitt commented Jun 27, 2021

lgtm, just a couple nits/questions and the painful question of how we ensure consistent use

Copy link
Member Author

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New push is up. The issue of a static checker needs to be resolved.

var parseIPTests = []struct {
in string
out IP
}{
{"127.0.1.2", IPv4(127, 0, 1, 2)},
{"127.0.0.1", IPv4(127, 0, 0, 1)},
{"127.001.002.003", IPv4(127, 1, 2, 3)}, // see https://issue.k8s.io/100895
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. Also will test 007 vs 008 to prove octal's edge

@liggitt
Copy link
Member

liggitt commented Jun 29, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 29, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 4a2b36d into kubernetes:master Jun 29, 2021
@liggitt
Copy link
Member

liggitt commented Jun 29, 2021

side-benefit of a different name is that a static checker could be easier to write

this is about as dumb a check as I can imagine but would catch a lot in k/k

egrep -r '\.(ParseIP|ParseCIDR)\(' pkg staging cmd plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants