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

Firewall Sync: Allow entire nodeport range #122

Merged
merged 2 commits into from
Feb 3, 2018

Conversation

nicksardo
Copy link
Contributor

@nicksardo nicksardo commented Feb 2, 2018

Changes

  • Firewall rule whitelists entire nodeport range instead of pin-holding nodeports used by ingresses. This is not a concern because the source IP ranges are only used by Google for health checkers and proxies.
  • Nodeport range is definable via flag.
  • Begin enforcing target tags are up-to-date. They were previously only updated at firewall change.
  • Use the gce.LoadBalancerSourceRanges() static func for specifying the GCE source ranges. This is definable via flag.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 2, 2018
@nicksardo nicksardo changed the title Sync entire nodeport range Firewall Sync: Allow entire nodeport range Feb 2, 2018
@@ -131,7 +131,7 @@ func (c *ClusterManager) Checkpoint(lbs []*loadbalancers.L7RuntimeInfo, nodeName
return igs, err
}

if err := c.firewallPool.Sync(firewallPorts, nodeNames); err != nil {
if err := c.firewallPool.Sync(nodeNames); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep the existing behavior but as optional if the range is not set?

Copy link
Member

Choose a reason for hiding this comment

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

Actually on second thought, let's remove the old code -- it's a lot more complex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, we'll need to pass in the list of ports used for NEG and merge them with the node port range.

for _, aAllow := range allowListA {
matchSet.Insert(firewallAllowedToString(aAllow))
}

Copy link
Member

Choose a reason for hiding this comment

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

why not use sets for both and call the set Equal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops


func firewallAllowedToString(allowed *compute.FirewallAllowed) string {
sort.Sort(sort.StringSlice(allowed.Ports))
return strings.ToUpper(allowed.IPProtocol) + strings.Join(allowed.Ports, ",")
Copy link
Member

Choose a reason for hiding this comment

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

add a colon in the middle so if someone logs the result it looks ok to a human
return strings.ToUpper(allowed.IPProtocol) + ":" + strings.Join(allowed.Ports, ",")

@@ -226,6 +227,6 @@ func NewClusterManager(

// L7 pool creates targetHTTPProxy, ForwardingRules, UrlMaps, StaticIPs.
cluster.l7Pool = loadbalancers.NewLoadBalancerPool(cloud, defaultBackendPool, defaultBackendNodePort, cluster.ClusterNamer)
cluster.firewallPool = firewalls.NewFirewallPool(cloud, cluster.ClusterNamer)
cluster.firewallPool = firewalls.NewFirewallPool(cloud, cluster.ClusterNamer, gce.LoadBalancerSrcRanges(), nodePortRanges)
Copy link
Member

Choose a reason for hiding this comment

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

let's just access these as a global -- it is more like a constant than a parameter.

func copyFirewall(f *compute.Firewall) *compute.Firewall {
enc, err := f.MarshalJSON()
if err != nil {
panic(fmt.Sprintf("Failed to encode to json: %v", err))
Copy link
Member

Choose a reason for hiding this comment

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

return error instead of panic.

@@ -190,3 +160,35 @@ type FirewallSyncError struct {
func (f *FirewallSyncError) Error() string {
return f.Message
}

func firewallsEqual(expected *compute.Firewall, existing *compute.Firewall) bool {
Copy link
Member

Choose a reason for hiding this comment

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

can just call this equal (firewalls.equal)

return true
}

func firewallAllowedToString(allowed []*compute.FirewallAllowed) []string {
Copy link
Member

Choose a reason for hiding this comment

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

same, firewall prefix is not needed

@@ -92,11 +103,41 @@ the pod secrets for creating a Kubernetes client.`)
`Print the version of the controller and exit`)
flag.StringVar(&F.IngressClass, "ingress-class", "",
`If set, overrides what ingress classes are managed by the controller.`)
flag.Var(&F.NodePortRanges, "node-port-ranges", `Node port/port-ranges whitelisted for the
L7 load balancing`)
Copy link
Member

Choose a reason for hiding this comment

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

might want to document the with an example

ff.fw[f.Name] = f
cf, err := copyFirewall(f)
if err != nil {
return fmt.Errorf("Failed to copy firewall: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

why not propagate err directly?

ff.fw[f.Name] = f
cf, err := copyFirewall(f)
if err != nil {
return fmt.Errorf("Failed to copy firewall: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

same here

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 3, 2018
@nicksardo
Copy link
Contributor Author

I believe we have three options to handle NEG endpoints.

  1. Pass a separate set of ports to the firewall syncer and merge with the nodeport ranges. (Implemented in second commit)
  2. Don't bother whitelisting individual ports. The L7 firewall rule opens up all TCP connections from the GCE src ranges.
  3. NEG use a separate instantiation of the firewall pool and creates a separate firewall rule.

@bowei bowei merged commit 0a413cd into kubernetes:master Feb 3, 2018
@nicksardo
Copy link
Contributor Author

I need to update the static-ip E2E test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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