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 port protocol case strictly #9919

Merged
merged 1 commit into from Jun 19, 2015

Conversation

liggitt
Copy link
Member

@liggitt liggitt commented Jun 17, 2015

This tightens validation on port protocol allowed values.

Currently, port protocol validation allows case-insensitive matching of "tcp" or "udp". However, other parts of the system rely on exact matches to the API constants:

pkg/api/validation/validation.go:
 1085   if service.Spec.Type == api.ServiceTypeLoadBalancer {
 1086       for i := range service.Spec.Ports {
 1087:          if service.Spec.Ports[i].Protocol != api.ProtocolTCP {
 1088               allErrs = append(allErrs, errs.NewFieldInvalid(fmt.Sprintf("spec.ports[%d].protocol", i), service.Spec.Ports[i].Protocol, "cannot create an external load balancer with non-TCP ports"))
 1089           }

pkg/cloudprovider/servicecontroller/servicecontroller.go:
  461       // it's supported.
  462       sp := &service.Spec.Ports[i]
  463:      if sp.Protocol != api.ProtocolTCP {
  464           return nil, fmt.Errorf("external load balancers for non TCP services are not currently supported.")
  465       }

pkg/master/controller.go:
  241   }
  242   p := &sub.Ports[0]
  243:  if p.Port != port || p.Protocol != api.ProtocolTCP {
  244       return false, false
  245   }

Other places where exact comparisons are expected between objects:

contrib/mesos/pkg/service/endpoints_controller.go:
400:                if port.Name == name && port.Protocol == svcPort.Protocol {
401:                    return findMappedPortName(pod, port.Protocol, name)

contrib/mesos/pkg/service/endpoints_controller.go:
414:                if port.ContainerPort == p && port.Protocol == svcPort.Protocol {
415:                    return findMappedPort(pod, port.Protocol, p)

pkg/service/endpoints_controller.go:
406:                if port.Name == name && port.Protocol == svcPort.Protocol {

Allowing a service or endpoint to be created with loose protocol validation, only to fail other parts of the system with strict checking isn't good.

@k8s-bot
Copy link

k8s-bot commented Jun 17, 2015

GCE e2e build/test passed for commit ee4cd97.

@saad-ali
Copy link
Member

Assigning @bgrant0607
v1.0 triage needed

@thockin
Copy link
Member

thockin commented Jun 17, 2015

We don't allow caseless compare anywhere else. If we wanted to allow it (I don't think we do) we should normalize case during defaulting, and that just sounds tedious and error prone.

@bgrant0607
Copy link
Member

No, we shouldn't normalize case during defaulting. That would violate one of my API rules, which is that we don't munge field values provided by the user.

I agree this is an annoying quirk, but I don't know that we can fix it at this late stage.

@liggitt
Copy link
Member Author

liggitt commented Jun 19, 2015

+1 on not mutating. Is it even possible for lowercase values to work? From what I saw, they would fail equality checks and not actually drive behavior

@thockin
Copy link
Member

thockin commented Jun 19, 2015

Yeah, we should just do it strictly.

@thockin thockin added this to the v1.0-candidate milestone Jun 19, 2015
@thockin thockin added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 19, 2015
@thockin
Copy link
Member

thockin commented Jun 19, 2015

LGTM
I think we should take this.

satnam6502 added a commit that referenced this pull request Jun 19, 2015
@satnam6502 satnam6502 merged commit 3591a54 into kubernetes:master Jun 19, 2015
@liggitt liggitt deleted the port_protocol_validation branch June 26, 2015 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants