Skip to content

Commit cd54650

Browse files
authored
Merge pull request Azure#10113 from wdehrich/support-esp-ah-protocols
Support AH and ESP Protocols in NSG Rules
2 parents 3108ad8 + 1ebd5b7 commit cd54650

File tree

4 files changed

+428
-321
lines changed

4 files changed

+428
-321
lines changed

src/Network/Network.Test/ScenarioTests/NetworkSecurityGroupTests.ps1

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,33 +263,37 @@ function Test-NetworkSecurityGroup-MultiValuedRules
263263
$securityRule1Name = Get-ResourceName
264264
$securityRule2Name = Get-ResourceName
265265
$securityRule3Name = Get-ResourceName
266+
$securityRule4Name = Get-ResourceName
267+
$securityRule5Name = Get-ResourceName
266268
$domainNameLabel = Get-ResourceName
267269
$rglocation = Get-ProviderLocation ResourceManagement
268270
$resourceTypeParent = "Microsoft.Network/NetworkSecurityGroups"
269271
$location = Get-ProviderLocation $resourceTypeParent
270-
272+
271273
try
272274
{
273275
# Create the resource group
274276
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
275-
277+
276278
# Create SecurityRule
277279
$securityRule1 = New-AzNetworkSecurityRuleConfig -Name $securityRule1Name -Description "desciption" -Protocol Tcp -SourcePortRange 23-45,80-90 -DestinationPortRange 46-56,70-80 -SourceAddressPrefix 10.10.20.0/24,192.168.0.0/24 -DestinationAddressPrefix 10.10.30.0/24,192.168.2.0/24 -Access Allow -Priority 123 -Direction Inbound
278280
$securityRule2 = New-AzNetworkSecurityRuleConfig -Name $securityRule2Name -Description "desciption" -Protocol Tcp -SourcePortRange 10-20,30-40 -DestinationPortRange 10-20,30-40 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 120 -Direction Inbound
279281
$securityRule3 = New-AzNetworkSecurityRuleConfig -Name $securityRule3Name -Description "desciption" -Protocol Icmp -SourcePortRange 50-60,100-110 -DestinationPortRange 120-130,131-140 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 125 -Direction Inbound
282+
$securityRule4 = New-AzNetworkSecurityRuleConfig -Name $securityRule4Name -Description "desciption" -Protocol Esp -SourcePortRange 150-160,170-180 -DestinationPortRange 190-200,210-220 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 127 -Direction Inbound
283+
$securityRule5 = New-AzNetworkSecurityRuleConfig -Name $securityRule5Name -Description "desciption" -Protocol Ah -SourcePortRange 230-240,250-260 -DestinationPortRange 270-280,290-300 -SourceAddressPrefix Storage -DestinationAddressPrefix Storage -Access Allow -Priority 129 -Direction Inbound
280284

281285
# Create NetworkSecurityGroup
282-
$nsg = New-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgname -Location $location -SecurityRules $securityRule1,$securityRule2,$securityRule3
286+
$nsg = New-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgname -Location $location -SecurityRules $securityRule1,$securityRule2,$securityRule3,$securityRule4,$securityRule5
283287

284288
# Get NetworkSecurityGroup
285289
$getNsg = Get-AzNetworkSecurityGroup -name $nsgName -ResourceGroupName $rgName
286-
290+
287291
#verification
288292
Assert-AreEqual $rgName $getNsg.ResourceGroupName
289293
Assert-AreEqual $nsgName $getNsg.Name
290294
Assert-NotNull $getNsg.Location
291295
Assert-NotNull $getNsg.Etag
292-
Assert-AreEqual 3 @($getNsg.SecurityRules).Count
296+
Assert-AreEqual 5 @($getNsg.SecurityRules).Count
293297
Assert-AreEqual 6 @($getNsg.DefaultSecurityRules).Count
294298
Assert-AreEqual "AllowVnetInBound" $getNsg.DefaultSecurityRules[0].Name
295299
Assert-AreEqual "AllowAzureLoadBalancerInBound" $getNsg.DefaultSecurityRules[1].Name
@@ -298,7 +302,7 @@ function Test-NetworkSecurityGroup-MultiValuedRules
298302
Assert-AreEqual "AllowInternetOutBound" $getNsg.DefaultSecurityRules[4].Name
299303
Assert-AreEqual "DenyAllOutBound" $getNsg.DefaultSecurityRules[5].Name
300304

301-
# verify rule 1.
305+
# verify rule 1.
302306
Assert-AreEqual $securityRule1Name $getNsg.SecurityRules[0].Name
303307
Assert-NotNull $getNsg.SecurityRules[0].Etag
304308
Assert-AreEqual "desciption" $getNsg.SecurityRules[0].Description
@@ -319,8 +323,8 @@ function Test-NetworkSecurityGroup-MultiValuedRules
319323
Assert-AreEqual "123" $getNsg.SecurityRules[0].Priority
320324
Assert-AreEqual "Inbound" $getNsg.SecurityRules[0].Direction
321325

322-
# verify rule 2
323-
Assert-AreEqual "desciption" $getNsg.SecurityRules[1].Description
326+
# verify rule 2
327+
Assert-AreEqual "desciption" $getNsg.SecurityRules[1].Description
324328
Assert-AreEqual "Tcp" $getNsg.SecurityRules[1].Protocol
325329
Assert-AreEqual 2 @($getNsg.SecurityRules[1].SourcePortRange).Count
326330
Assert-AreEqual "10-20" $getNsg.SecurityRules[1].SourcePortRange[0]
@@ -353,6 +357,40 @@ function Test-NetworkSecurityGroup-MultiValuedRules
353357
Assert-AreEqual "125" $getNsg.SecurityRules[2].Priority
354358
Assert-AreEqual "Inbound" $getNsg.SecurityRules[2].Direction
355359

360+
# verify rule 4
361+
Assert-AreEqual "desciption" $getNsg.SecurityRules[3].Description
362+
Assert-AreEqual "Esp" $getNsg.SecurityRules[3].Protocol
363+
Assert-AreEqual 2 @($getNsg.SecurityRules[3].SourcePortRange).Count
364+
Assert-AreEqual "150-160" $getNsg.SecurityRules[3].SourcePortRange[0]
365+
Assert-AreEqual "170-180" $getNsg.SecurityRules[3].SourcePortRange[1]
366+
Assert-AreEqual 2 @($getNsg.SecurityRules[3].DestinationPortRange).Count
367+
Assert-AreEqual "190-200" $getNsg.SecurityRules[3].DestinationPortRange[0]
368+
Assert-AreEqual "210-220" $getNsg.SecurityRules[3].DestinationPortRange[1]
369+
Assert-AreEqual 1 @($getNsg.SecurityRules[3].SourceAddressPrefix).Count
370+
Assert-AreEqual "Storage" $getNsg.SecurityRules[3].SourceAddressPrefix[0]
371+
Assert-AreEqual 1 @($getNsg.SecurityRules[3].DestinationAddressPrefix).Count
372+
Assert-AreEqual "Storage" $getNsg.SecurityRules[3].DestinationAddressPrefix[0]
373+
Assert-AreEqual "Allow" $getNsg.SecurityRules[3].Access
374+
Assert-AreEqual "127" $getNsg.SecurityRules[3].Priority
375+
Assert-AreEqual "Inbound" $getNsg.SecurityRules[3].Direction
376+
377+
# verify rule 5
378+
Assert-AreEqual "desciption" $getNsg.SecurityRules[4].Description
379+
Assert-AreEqual "Ah" $getNsg.SecurityRules[4].Protocol
380+
Assert-AreEqual 2 @($getNsg.SecurityRules[4].SourcePortRange).Count
381+
Assert-AreEqual "230-240" $getNsg.SecurityRules[4].SourcePortRange[0]
382+
Assert-AreEqual "250-260" $getNsg.SecurityRules[4].SourcePortRange[1]
383+
Assert-AreEqual 2 @($getNsg.SecurityRules[4].DestinationPortRange).Count
384+
Assert-AreEqual "270-280" $getNsg.SecurityRules[4].DestinationPortRange[0]
385+
Assert-AreEqual "290-300" $getNsg.SecurityRules[4].DestinationPortRange[1]
386+
Assert-AreEqual 1 @($getNsg.SecurityRules[4].SourceAddressPrefix).Count
387+
Assert-AreEqual "Storage" $getNsg.SecurityRules[4].SourceAddressPrefix[0]
388+
Assert-AreEqual 1 @($getNsg.SecurityRules[4].DestinationAddressPrefix).Count
389+
Assert-AreEqual "Storage" $getNsg.SecurityRules[4].DestinationAddressPrefix[0]
390+
Assert-AreEqual "Allow" $getNsg.SecurityRules[4].Access
391+
Assert-AreEqual "129" $getNsg.SecurityRules[4].Priority
392+
Assert-AreEqual "Inbound" $getNsg.SecurityRules[4].Direction
393+
356394
# list
357395
$list = Get-AzNetworkSecurityGroup -ResourceGroupName $rgname
358396
Assert-AreEqual 1 @($list).Count
@@ -374,7 +412,7 @@ function Test-NetworkSecurityGroup-MultiValuedRules
374412
# Delete NetworkSecurityGroup
375413
$delete = Remove-AzNetworkSecurityGroup -ResourceGroupName $rgname -name $nsgName -PassThru -Force
376414
Assert-AreEqual true $delete
377-
415+
378416
$list = Get-AzNetworkSecurityGroup -ResourceGroupName $rgname
379417
Assert-AreEqual 0 @($list).Count
380418
}

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.NetworkSecurityGroupTests/TestNetworkSecurityGroupMultiValuedRules.json

Lines changed: 374 additions & 312 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Add support for ESP and AH protocols in network security rule configurations
23+
- Updated cmdlets:
24+
- Add-AzNetworkSecurityRuleConfig
25+
- New-AzNetworkSecurityRuleConfig
26+
- Set-AzNetworkSecurityRuleConfig
2227
* Improve handling of exceptions in Cortex cmdlets
2328
* Fix incorrect example in `New-AzApplicationGateway` reference documentation
2429
* Add note in `Get-AzNetworkWatcherPacketCapture` reference documentation about retrieving all properties for a packet capture

src/Network/Network/NetworkSecurityGroup/NetworkSecurityRule/AzureNetworkSecurityRuleConfigBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class AzureNetworkSecurityRuleConfigBase : NetworkBaseCmdlet
4040
MNM.SecurityRuleProtocol.Tcp,
4141
MNM.SecurityRuleProtocol.Udp,
4242
MNM.SecurityRuleProtocol.Icmp,
43+
MNM.SecurityRuleProtocol.Esp,
44+
MNM.SecurityRuleProtocol.Ah,
4345
MNM.SecurityRuleProtocol.Asterisk,
4446
IgnoreCase = true)]
4547
[ValidateNotNullOrEmpty]

0 commit comments

Comments
 (0)