Skip to content

Commit d6611c0

Browse files
committed
Ensure NSG rules cleanup excludes Destination Application Security Groups
1 parent 6c132ae commit d6611c0

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

pkg/provider/loadbalancer/securitygroup/securitygroup.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,12 @@ func (helper *RuleHelper) SecurityGroup() (*network.SecurityGroup, bool, error)
386386
rules = make([]network.SecurityRule, 0, len(helper.rules))
387387
)
388388
for _, r := range helper.rules {
389-
noDstPrefixes := ptr.Deref(r.DestinationAddressPrefix, "") == "" &&
390-
len(ptr.Deref(r.DestinationAddressPrefixes, []string{})) == 0
391-
if noDstPrefixes {
389+
var (
390+
dstAddresses = ListDestinationPrefixes(r)
391+
dstASGs = ptr.Deref(r.DestinationApplicationSecurityGroups, []network.ApplicationSecurityGroup{})
392+
)
393+
394+
if len(dstAddresses) == 0 && len(dstASGs) == 0 {
392395
// Skip the rule without destination prefixes.
393396
continue
394397
}

pkg/provider/loadbalancer/testutil/fixture/azure_securitygroup.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,29 @@ func (f *AzureFixture) NoiseSecurityRules(nRules int) []network.SecurityRule {
6262
fmt.Sprintf("130.0.50.%d", i),
6363
}),
6464
SourcePortRange: ptr.To("*"),
65-
DestinationAddressPrefixes: ptr.To([]string{
66-
fmt.Sprintf("222.111.0.%d", i), // NOTE: keep the source IP / destination IP unique to LB ips.
67-
fmt.Sprintf("200.0.50.%d", i),
68-
}),
6965
DestinationPortRanges: ptr.To([]string{
7066
fmt.Sprintf("4000%d", i),
7167
fmt.Sprintf("5000%d", i),
7268
}),
7369
},
7470
}
71+
72+
switch i % 3 {
73+
case 0:
74+
rule.DestinationAddressPrefixes = ptr.To([]string{
75+
fmt.Sprintf("222.111.0.%d", i),
76+
fmt.Sprintf("200.0.50.%d", i),
77+
})
78+
case 1:
79+
rule.DestinationAddressPrefix = ptr.To(fmt.Sprintf("222.111.0.%d", i))
80+
case 2:
81+
rule.DestinationApplicationSecurityGroups = &[]network.ApplicationSecurityGroup{
82+
{
83+
ID: ptr.To(fmt.Sprintf("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/the-rg/providers/Microsoft.Network/applicationSecurityGroups/the-asg-%d", i)),
84+
},
85+
}
86+
}
87+
7588
rv = append(rv, rule)
7689

7790
initPriority++

0 commit comments

Comments
 (0)