Skip to content

Commit 5c83029

Browse files
authored
Merge pull request #566 from jabbera/fix-nsg-issues
Fix nsg creation issues
2 parents 46e6e30 + 78ff1d0 commit 5c83029

1 file changed

Lines changed: 10 additions & 49 deletions

File tree

samples/manage/azure-sql-db-managed-instance/prepare-subnet/prepareSubnet.ps1

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -182,39 +182,11 @@ function DefineSecurityRules{
182182
$securityRules = New-Object "$NScollections.List``1[$NSnetworkModels.PSSecurityRule]"
183183
#begin NSG inbound rules
184184
$rule = New-AzureRmNetworkSecurityRuleConfig `
185-
-Name prepare-allow-management-inbound-9000 `
186-
-Description "Allow inbound TCP traffic on port 9000" `
185+
-Name prepare-allow-management-inbound `
186+
-Description "Allow inbound TCP traffic on ports 9000,9003,1438,1440,1452" `
187187
-Direction Inbound -Priority 110 -Access Allow -Protocol Tcp `
188188
-SourceAddressPrefix * -DestinationAddressPrefix * `
189-
-SourcePortRange * -DestinationPortRange 9000
190-
$securityRules.Add($rule)
191-
$rule = New-AzureRmNetworkSecurityRuleConfig `
192-
-Name prepare-allow-management-inbound-9003 `
193-
-Description "Allow inbound TCP traffic on port 9003" `
194-
-Direction Inbound -Priority 120 -Access Allow -Protocol Tcp `
195-
-SourceAddressPrefix * -DestinationAddressPrefix * `
196-
-SourcePortRange * -DestinationPortRange 9003
197-
$securityRules.Add($rule)
198-
$rule = New-AzureRmNetworkSecurityRuleConfig `
199-
-Name prepare-allow-management-inbound-1438 `
200-
-Description "Allow inbound TCP traffic on port 1438" `
201-
-Direction Inbound -Priority 130 -Access Allow -Protocol Tcp `
202-
-SourceAddressPrefix * -DestinationAddressPrefix * `
203-
-SourcePortRange * -DestinationPortRange 1438
204-
$securityRules.Add($rule)
205-
$rule = New-AzureRmNetworkSecurityRuleConfig `
206-
-Name prepare-allow-management-inbound-1440 `
207-
-Description "Allow inbound TCP traffic on port 1440" `
208-
-Direction Inbound -Priority 140 -Access Allow -Protocol Tcp `
209-
-SourceAddressPrefix * -DestinationAddressPrefix * `
210-
-SourcePortRange * -DestinationPortRange 1440
211-
$securityRules.Add($rule)
212-
$rule = New-AzureRmNetworkSecurityRuleConfig `
213-
-Name prepare-allow-management-inbound-1452 `
214-
-Description "Allow inbound TCP traffic on port 1452" `
215-
-Direction Inbound -Priority 150 -Access Allow -Protocol Tcp `
216-
-SourceAddressPrefix * -DestinationAddressPrefix * `
217-
-SourcePortRange * -DestinationPortRange 1452
189+
-SourcePortRange * -DestinationPortRange @(9000, 9003, 1438, 1440, 1452)
218190
$securityRules.Add($rule)
219191
$rule = New-AzureRmNetworkSecurityRuleConfig `
220192
-Name prepare-allow-mi_subnet-inbound `
@@ -225,33 +197,19 @@ function DefineSecurityRules{
225197
$securityRules.Add($rule)
226198
$rule = New-AzureRmNetworkSecurityRuleConfig `
227199
-Name prepare-allow-health_probe-inbound `
228-
-Description "Allow healt probe inbound" `
200+
-Description "Allow health probe inbound" `
229201
-Direction Inbound -Priority 170 -Access Allow -Protocol * `
230202
-SourceAddressPrefix AzureLoadBalancer -DestinationAddressPrefix * `
231203
-SourcePortRange * -DestinationPortRange *
232204
$securityRules.Add($rule)
233205
#end NSG inbound rules
234206
#begin NSG outbound rules
235207
$rule = New-AzureRmNetworkSecurityRuleConfig `
236-
-Name prepare-allow-management-outbound-80 `
237-
-Description "Allow outbound TCP traffic on port 80" `
208+
-Name prepare-allow-management-outbound `
209+
-Description "Allow outbound TCP traffic on port 80,443,12000" `
238210
-Direction Outbound -Priority 110 -Access Allow -Protocol Tcp `
239211
-SourceAddressPrefix * -DestinationAddressPrefix * `
240-
-SourcePortRange * -DestinationPortRange 80
241-
$securityRules.Add($rule)
242-
$rule = New-AzureRmNetworkSecurityRuleConfig `
243-
-Name prepare-allow-management-outbound-443 `
244-
-Description "Allow outbound TCP traffic on port 443" `
245-
-Direction Outbound -Priority 120 -Access Allow -Protocol Tcp `
246-
-SourceAddressPrefix * -DestinationAddressPrefix * `
247-
-SourcePortRange * -DestinationPortRange 443
248-
$securityRules.Add($rule)
249-
$rule = New-AzureRmNetworkSecurityRuleConfig `
250-
-Name prepare-allow-management-outbound-12000 `
251-
-Description "Allow outbound TCP traffic on port 12000" `
252-
-Direction Outbound -Priority 130 -Access Allow -Protocol Tcp `
253-
-SourceAddressPrefix * -DestinationAddressPrefix * `
254-
-SourcePortRange * -DestinationPortRange 12000
212+
-SourcePortRange * -DestinationPortRange @(80, 443, 12000)
255213
$securityRules.Add($rule)
256214
$rule = New-AzureRmNetworkSecurityRuleConfig `
257215
-Name prepare-allow-mi_subnet-outbound `
@@ -502,6 +460,9 @@ function VerifyNSG {
502460
}
503461
$result['success'] = $result['failedSecurityRules'].Count -eq 0
504462
}
463+
Else {
464+
$result['failedSecurityRules'] = DefineSecurityRules
465+
}
505466
If($true -eq $result['success'])
506467
{
507468
Write-Host "Passed Validation - Network security group." -ForegroundColor Green

0 commit comments

Comments
 (0)