Skip to content

Commit

Permalink
Add support for cloudflare source in loadbalaner firewall rules (#139)
Browse files Browse the repository at this point in the history
* Add support for cloudflare source in loadbalaner firewall rules

* Add firewall rules annotation to TestLoadbalancers_EnsureLoadBalancer unit test

* Fix gofmt issue in loadbalancer_test.go
  • Loading branch information
reubit committed Dec 7, 2022
1 parent c191e26 commit 235119c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions vultr/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ func TestLoadbalancers_EnsureLoadBalancer(t *testing.T) {

svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "lb-name",
Namespace: v1.NamespaceDefault,
UID: "lb-name",
Annotations: nil,
Name: "lb-name",
Namespace: v1.NamespaceDefault,
UID: "lb-name",
Annotations: map[string]string{
annoVultrFirewallRules: "cloudflare,80;10.0.0.0/8,80",
},
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand Down
9 changes: 6 additions & 3 deletions vultr/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,13 @@ func buildFirewallRules(service *v1.Service) ([]govultr.LBFirewallRule, error) {
if len(rules) != 2 { //nolint
return nil, fmt.Errorf("loadbalancer fw rules : %s invalid configuration", rules)
}

source := rules[0]
_, _, err := net.ParseCIDR(source)
if err != nil {
return nil, fmt.Errorf("loadbalancer fw rules : source %s is invalid", source)
if source != "cloudflare" {
_, _, err := net.ParseCIDR(source)
if err != nil {
return nil, fmt.Errorf("loadbalancer fw rules : source %s is invalid", source)
}
}

port, err := strconv.Atoi(rules[1])
Expand Down

0 comments on commit 235119c

Please sign in to comment.