Skip to content

Commit

Permalink
Fix cleaning up stale security rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zarvd authored and k8s-infra-cherrypick-robot committed Apr 15, 2024
1 parent 59df614 commit e260b47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/provider/loadbalancer/securitygroup/securitygroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,11 @@ func (helper *RuleHelper) RemoveDestinationPrefixesFromRules(prefixes []string)
}

for _, rule := range helper.rules {
if rule.DestinationAddressPrefix != nil && index[*rule.DestinationAddressPrefix] {
rule.DestinationAddressPrefix = nil
continue
}
if rule.DestinationAddressPrefixes == nil {
if rule.DestinationAddressPrefix != nil && index[*rule.DestinationAddressPrefix] {
rule.DestinationAddressPrefix = nil
}
continue
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/provider/loadbalancer/securitygroup/securitygroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,20 @@ func TestSecurityGroupHelper_RemoveDstAddressesFromRules(t *testing.T) {
Priority: ptr.To(int32(2000)),
},
},
{
Name: ptr.To("test-rule-4"),
SecurityRulePropertiesFormat: &network.SecurityRulePropertiesFormat{
Protocol: network.SecurityRuleProtocolAsterisk,
Access: network.SecurityRuleAccessAllow,
Direction: network.SecurityRuleDirectionInbound,
SourceAddressPrefix: ptr.To("*"),
SourcePortRange: ptr.To("*"),
DestinationAddressPrefixes: ptr.To([]string{}),
DestinationAddressPrefix: ptr.To("192.168.0.1"),
DestinationPortRanges: ptr.To([]string{"8000"}),
Priority: ptr.To(int32(2000)),
},
},
}

sg = fx.Azure().SecurityGroup().WithRules(rules).Build()
Expand Down

0 comments on commit e260b47

Please sign in to comment.