Skip to content

Commit 88f7be2

Browse files
authored
Azure Networking: Updated saDataSizeKilobytes validation for vpn gateway connection (#14897)
* Updated saDataSizeKilobytes validation
1 parent 8dd90e9 commit 88f7be2

File tree

6 files changed

+14860
-1
lines changed

6 files changed

+14860
-1
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayConnectionTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ public void TestVirtualNetworkGatewayConnectionWithActiveAcitveGateway()
7373
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionWithActiveActiveGateway");
7474
}
7575

76+
[Fact]
77+
[Trait(Category.AcceptanceType, Category.CheckIn)]
78+
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset4)]
79+
public void TestVirtualNetworkGatewayConnectionWithZeroSaData()
80+
{
81+
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionWithZeroSaData");
82+
}
83+
84+
7685
[Fact]
7786
[Trait(Category.AcceptanceType, Category.CheckIn)]
7887
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset4)]

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayConnectionTests.ps1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,97 @@ function Test-VirtualNetworkGatewayConnectionWithActiveActiveGateway
389389
}
390390
}
391391

392+
<#
393+
.SYNOPSIS
394+
Virtual network gateway connection test with Active-Active feature enabled virtual network gateway
395+
#>
396+
function Test-VirtualNetworkGatewayConnectionWithZeroSaData
397+
{
398+
# Setup
399+
$rgname = Get-ResourceName
400+
$rname1 = Get-ResourceName
401+
$rname2 = Get-ResourceName
402+
$domainNameLabel11 = Get-ResourceName
403+
$domainNameLabel12 = Get-ResourceName
404+
$domainNameLabel2 = Get-ResourceName
405+
$vnetName1 = Get-ResourceName
406+
$vnetName2 = Get-ResourceName
407+
$vnetConnectionName1 = Get-ResourceName
408+
$vnetConnectionName2 = Get-ResourceName
409+
$publicIpName11 = Get-ResourceName
410+
$publicIpName12 = Get-ResourceName
411+
$publicIpName2 = Get-ResourceName
412+
$vnetGatewayConfigName11 = Get-ResourceName
413+
$vnetGatewayConfigName12 = Get-ResourceName
414+
$vnetGatewayConfigName2 = Get-ResourceName
415+
$rglocation = Get-ProviderLocation ResourceManagement
416+
$resourceTypeParent = "Microsoft.Network/connections"
417+
$location = Get-ProviderLocation $resourceTypeParent
418+
419+
try
420+
{
421+
# Create the resource group
422+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
423+
424+
# Create the Virtual Network1
425+
$subnet1 = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
426+
$vnet1 = New-AzVirtualNetwork -Name $vnetName1 -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet1
427+
$vnet1 = Get-AzVirtualNetwork -Name $vnetName1 -ResourceGroupName $rgname
428+
$subnet1 = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet1
429+
430+
# Create Active-Active feature enabled virtualnetworkgateway1 & Get virtualnetworkgateway1
431+
$publicip11 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName11 -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel11
432+
$vnetIpConfig11 = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName11 -PublicIpAddress $publicip11 -Subnet $subnet1
433+
434+
$publicip12 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName12 -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel12
435+
$vnetIpConfig12 = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName12 -PublicIpAddress $publicip12 -Subnet $subnet1
436+
437+
$vnetGateway1 = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname1 -Location $location -IpConfigurations $vnetIpConfig11,$vnetIpConfig12 -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku HighPerformance -EnableActiveActiveFeature
438+
$vnetGateway1 = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname1
439+
440+
# Create IpsecPolicy and test SADataSizeKilobytes when passed 0
441+
$ipsecPolicy = New-AzIpsecPolicy -SALifeTimeSeconds 3000 -SADataSizeKilobytes 0 -IpsecEncryption "GCMAES256" -IpsecIntegrity "GCMAES256" -IkeEncryption "AES256" -IkeIntegrity "SHA256" -DhGroup "DHGroup14" -PfsGroup "PFS2048"
442+
Assert-AreEqual $ipsecPolicy.SADataSizeKilobytes 0
443+
444+
# Create the Virtual Network2
445+
$subnet2 = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 192.168.200.0/26
446+
$vnet2 = New-AzVirtualNetwork -Name $vnetName2 -ResourceGroupName $rgname -Location $location -AddressPrefix 192.168.0.0/16 -Subnet $subnet2
447+
$vnet2 = Get-AzVirtualNetwork -Name $vnetName2 -ResourceGroupName $rgname
448+
$subnet2 = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet2
449+
450+
# Create the publicip2
451+
$publicip2 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName2 -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel2
452+
453+
# Create VirtualNetworkGateway2
454+
$vnetIpConfig2 = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName2 -PublicIpAddress $publicip2 -Subnet $subnet2
455+
456+
$vnetGateway2 = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname2 -location $location -IpConfigurations $vnetIpConfig2 -GatewayType Vpn -VpnType RouteBased -GatewaySku Standard
457+
$vnetGateway2 = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname2
458+
459+
# Create & Get VirtualNetworkGatewayConnection1, VirtualNetworkGatewayConnection2
460+
$connection1 = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName1 -location $location -VirtualNetworkGateway1 $vnetGateway1 -VirtualNetworkGateway2 $vnetGateway2 -ConnectionType Vnet2Vnet -RoutingWeight 3 -SharedKey abc -IpsecPolicies $ipsecPolicy
461+
$connection2 = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName2 -location $location -VirtualNetworkGateway1 $vnetGateway2 -VirtualNetworkGateway2 $vnetGateway1 -ConnectionType Vnet2Vnet -RoutingWeight 3 -SharedKey abc -IpsecPolicies $ipsecPolicy
462+
463+
$connection1 = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName1
464+
$connection2 = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName2
465+
466+
Assert-AreEqual $connection1.IpsecPolicies[0].SADataSizeKilobytes $connection2.IpsecPolicies[0].SADataSizeKilobytes
467+
Assert-AreEqual $connection1.IpsecPolicies[0].SADataSizeKilobytes 0
468+
Assert-AreEqual $connection2.IpsecPolicies[0].SADataSizeKilobytes 0
469+
470+
# Delete VirtualNetworkGatewayConnections
471+
$delete = Remove-AzVirtualNetworkGatewayConnection -ResourceGroupName $connection1.ResourceGroupName -name $vnetConnectionName1 -PassThru -Force
472+
Assert-AreEqual true $delete
473+
$delete = Remove-AzVirtualNetworkGatewayConnection -ResourceGroupName $connection2.ResourceGroupName -name $vnetConnectionName2 -PassThru -Force
474+
Assert-AreEqual true $delete
475+
}
476+
finally
477+
{
478+
# Cleanup
479+
Clean-ResourceGroup $rgname
480+
}
481+
}
482+
392483
function Test-VirtualNetworkGatewayConnectionCRUD
393484
{
394485
# Setup

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayConnectionTests/TestVirtualNetworkGatewayConnectionWithZeroSaData.json

Lines changed: 9802 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.VirtualNetworkGatewayTests/VirtualNetworkGatewayVpnCustomIpsecPolicySetWithZeroSADataSizeTest.json

Lines changed: 4949 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

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

2121
## Upcoming Release
22+
* Updated validation to allow passing zero value for saDataSizeKilobytes parameter
23+
- `New-AzureRmIpsecPolicy`
2224

2325
## Version 4.7.0
2426
* Added new cmdlets to replace old product name `virtual router` with new name `route server` in the future.

src/Network/Network/VirtualNetworkGatewayConnection/NewAzureRmIpsecPolicyCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class NewAzureRmIpsecPolicyCommand : NetworkBaseCmdlet
3131
[Parameter(
3232
Mandatory = false,
3333
HelpMessage = "The IPSec Security Association (also called Quick Mode or Phase 2 SA) payload size in KB")]
34-
[ValidateRange(1024, int.MaxValue)]
34+
[ValidateRange(0, int.MaxValue)]
3535
public int SADataSizeKilobytes { get; set; }
3636

3737
[Parameter(
@@ -136,6 +136,12 @@ public override void Execute()
136136
throw new ArgumentException("IpsecEncryption and IpsecIntegrity must use matching GCM algorithms");
137137
}
138138

139+
// SADataSizeKilobytes either 0 or between 1024 and 2147483647
140+
if (ipsecPolicy.SADataSizeKilobytes != 0 && (ipsecPolicy.SADataSizeKilobytes < 1024 || ipsecPolicy.SADataSizeKilobytes > int.MaxValue))
141+
{
142+
throw new ArgumentException("SA life time in kilobytes must be 0 or between 1024 and 2147483647 included.");
143+
}
144+
139145
ipsecPolicy.IpsecEncryption = this.IpsecEncryption;
140146
ipsecPolicy.IpsecIntegrity = this.IpsecIntegrity;
141147
ipsecPolicy.IkeEncryption = this.IkeEncryption;

0 commit comments

Comments
 (0)