Skip to content
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

Validate Service.Spec.publicIPs to be a valid IP that is not a localhost #5508

Merged
merged 1 commit into from
Mar 25, 2015

Conversation

fgrzadkowski
Copy link
Contributor

This fixes #5319

for _, ip := range service.Spec.PublicIPs {
if !util.IsValidIP(ip) || ip == "0.0.0.0" {
allErrs = append(allErrs, errs.NewFieldInvalid("spec.publicIPs", ip, "is not an IP address"))
} else if ip == "127.0.0.1" {
Copy link
Member

Choose a reason for hiding this comment

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

How about

if net.ParseIP(ip).IsLoopback() 

Being loopback is more than just 127.0.0.1.

In fact, http://golang.org/pkg/net/#ParseIP has a bunch of conditions that are probably worth checking. Maybe

if !net.ParseIP(ip).IsGlobalUnicast() {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That simplifies logic a lot! Thanks!

Regarding IsGlobalUnicast() - isn't it only for IPv6 which we don't support anyway? IsValidIP returns true only for IPv4 addresses.

@fgrzadkowski fgrzadkowski force-pushed the validate_ips branch 2 times, most recently from ca03867 to 385a22b Compare March 17, 2015 16:36
@fgrzadkowski
Copy link
Contributor Author

New version pushed and synced to HEAD.

@gust1n
Copy link
Contributor

gust1n commented Mar 17, 2015

Isn't publicIPs supposed to be string to support AWS load balancer (ELB) which is a hostname and not an actual IP?
#5228 @justinsb

@fgrzadkowski
Copy link
Contributor Author

@gust1n @justinsb Thanks for linking PR. I haven't noticed it. In that case I'll just check if it's not 0.0.0.0 or a loopback.

@fgrzadkowski
Copy link
Contributor Author

Ping.

@ghost
Copy link

ghost commented Mar 23, 2015

LGTM - but needs a rebase before merge please.

@fgrzadkowski
Copy link
Contributor Author

Rebased.

@@ -94,3 +95,8 @@ func IsCIdentifier(value string) bool {
func IsValidPortNum(port int) bool {
return 0 < port && port < 65536
}

// IsValidIP tests that the argument is a valid IPv4 address.
func IsValidIP(value string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you rename it to IsValidIPv4, to make it more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest I'd prefer to keep the name as is, because from k8s perspective this verifies whether it's a valid IP (because k8s works only for v4).

fgrzadkowski added a commit that referenced this pull request Mar 25, 2015
Validate Service.Spec.publicIPs to be a valid IP that is not a localhost
@fgrzadkowski fgrzadkowski merged commit 7085a0c into kubernetes:master Mar 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.0.0.0 and 127.0.0.1 should be rejected as a publicIP fields for kube services.
5 participants