Skip to content

Commit 291ef21

Browse files
committed
multiple radius initial commit
1 parent 196b9a4 commit 291ef21

File tree

8 files changed

+13368
-8
lines changed

8 files changed

+13368
-8
lines changed

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ public void VirtualNetworkGatewayOpenVPNAADAuthTest()
108108
TestRunner.RunTestScript("Test-VirtualNetworkGatewayOpenVPNAADAuth");
109109
}
110110

111+
[Fact]
112+
[Trait(Category.AcceptanceType, Category.CheckIn)]
113+
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)]
114+
public void VirtualNetworkGatewayRadiusTest()
115+
{
116+
TestRunner.RunTestScript("Test-VirtualNetworkGatewayRadius");
117+
}
118+
111119
[Fact]
112120
[Trait(Category.AcceptanceType, Category.CheckIn)]
113121
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)]

src/Network/Network.Test/ScenarioTests/VirtualNetworkGatewayTests.ps1

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,83 @@ function Test-VirtualNetworkGatewayIkeV2
648648
}
649649
}
650650

651+
<#
652+
.SYNOPSIS
653+
Virtual network gateway P2S radius API test
654+
#>
655+
function Test-VirtualNetworkGatewayRadius
656+
{
657+
# Setup
658+
$rgname = Get-ResourceGroupName
659+
$rname = Get-ResourceName
660+
$domainNameLabel = Get-ResourceName
661+
$vnetName = Get-ResourceName
662+
$publicIpName = Get-ResourceName
663+
$vnetGatewayConfigName = Get-ResourceName
664+
$rglocation = Get-ProviderLocation ResourceManagement
665+
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
666+
$location = Get-ProviderLocation $resourceTypeParent
667+
668+
try
669+
{
670+
# Create the multiple radius servers settings
671+
$radiuspd = ConvertTo-SecureString -String "radiuspd" -AsPlainText -Force
672+
$radiusServer1 = New-AzRadiusServer -RadiusServerAddress 10.1.0.1 -RadiusServerSecret $radiuspd -RadiusServerScore 30
673+
$radiusServer2 = New-AzRadiusServer -RadiusServerAddress 10.1.0.2 -RadiusServerSecret $radiuspd -RadiusServerScore 1
674+
$radiusServer3 = New-AzRadiusServer -RadiusServerAddress 10.1.0.3 -RadiusServerSecret $radiuspd -RadiusServerScore 15
675+
$radiusServers = @( $radiusServer1, $radiusServer2 )
676+
677+
# Create the resource group
678+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }
679+
680+
# Create the Virtual Network
681+
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
682+
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
683+
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
684+
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet
685+
686+
# Create the IP config
687+
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
688+
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
689+
690+
# Create & Get virtualnetworkgateway
691+
New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw1 -VpnClientAddressPool 201.169.0.0/16 -VpnClientProtocol "IkeV2" -RadiusServers $radiusServers
692+
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
693+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers.Count 2
694+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerAddress $radiusServer1.RadiusServerAddress
695+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerSecret $radiusServer1.RadiusServerSecret
696+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerScore $radiusServer1.RadiusServerScore
697+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerAddress $radiusServer2.RadiusServerAddress
698+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerSecret $radiusServer2.RadiusServerSecret
699+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerScore $radiusServer2.RadiusServerScore
700+
701+
# Update gateway radius settings
702+
$radiusServers = @($radiusServer3, $radiusServer1)
703+
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientAddressPool 201.169.0.0/16 -VpnClientProtocol "IkeV2" -RadiusServers $radiusServers
704+
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
705+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers.Count 2
706+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerAddress $radiusServer3.RadiusServerAddress
707+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerSecret $radiusServer3.RadiusServerSecret
708+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerScore $radiusServer3.RadiusServerScore
709+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerAddress $radiusServer1.RadiusServerAddress
710+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerSecret $radiusServer1.RadiusServerSecret
711+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerScore $radiusServer1.RadiusServerScore
712+
713+
# Update gateway to singular radius
714+
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientAddressPool 201.169.0.0/16 -VpnClientProtocol "IkeV2" -RadiusServerAddress 10.1.0.2 -RadiusServerSecret $radiuspd
715+
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
716+
Assert-Null $actual.VpnClientConfiguration.RadiusServers
717+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServerAddress 10.1.0.2
718+
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServerSecret "radiuspd"
719+
}
720+
finally
721+
{
722+
# Cleanup
723+
Clean-ResourceGroup $rgname
724+
}
725+
}
726+
727+
651728
<#
652729
.SYNOPSIS
653730
Virtual network gateway P2S OpenVPN API test

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

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

src/Network/Network/Generated/Models/PSVpnClientConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public partial class PSVpnClientConfiguration
4848
public List<PSVpnClientRootCertificate> VpnClientRootCertificates { get; set; }
4949
public List<PSVpnClientRevokedCertificate> VpnClientRevokedCertificates { get; set; }
5050
public List<PSIpsecPolicy> VpnClientIpsecPolicies { get; set; }
51+
public List<PSRadiusServer> RadiusServers { get; set; }
5152

5253
[JsonIgnore]
5354
public string VpnClientProtocolsText
@@ -78,5 +79,11 @@ public string VpnClientIpsecPoliciesText
7879
{
7980
get { return JsonConvert.SerializeObject(VpnClientIpsecPolicies, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
8081
}
82+
83+
[JsonIgnore]
84+
public string RadiusServersText
85+
{
86+
get { return JsonConvert.SerializeObject(RadiusServers, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
87+
}
8188
}
8289
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
16+
17+
namespace Microsoft.Azure.Commands.Network.Models
18+
{
19+
public class PSRadiusServer
20+
{
21+
/// <summary>
22+
/// Radius server address
23+
/// </summary>
24+
[Ps1Xml(Target = ViewControl.Table)]
25+
public string RadiusServerAddress { get; set; }
26+
27+
/// <summary>
28+
/// Radius server secret
29+
/// </summary>
30+
public string RadiusServerSecret { get; set; }
31+
32+
/// <summary>
33+
/// Radius server score
34+
/// </summary>
35+
[Ps1Xml(Target = ViewControl.Table)]
36+
public int RadiusServerScore { get; set; }
37+
}
38+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Network.Models;
16+
using Microsoft.WindowsAzure.Commands.Common;
17+
using System;
18+
using System.Management.Automation;
19+
using System.Security;
20+
using MNM = Microsoft.Azure.Management.Network.Models;
21+
22+
namespace Microsoft.Azure.Commands.Network
23+
{
24+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RadiusServer"), OutputType(typeof(PSRadiusServer))]
25+
public class NewAzRadiusServerCommand : NetworkBaseCmdlet
26+
{
27+
[Parameter(
28+
Mandatory = true,
29+
ValueFromPipelineByPropertyName = true,
30+
HelpMessage = "External radius server address")]
31+
public string RadiusServerAddress { get; set; }
32+
33+
[Parameter(
34+
Mandatory = true,
35+
ValueFromPipelineByPropertyName = true,
36+
HelpMessage = "External radius server secret")]
37+
public SecureString RadiusServerSecret { get; set; }
38+
39+
[Parameter(
40+
Mandatory = false,
41+
ValueFromPipelineByPropertyName = true,
42+
HelpMessage = "External radius server score")]
43+
public int RadiusServerScore { get; set; }
44+
45+
public override void Execute()
46+
{
47+
base.Execute();
48+
var radiusServer = new PSRadiusServer();
49+
50+
radiusServer.RadiusServerAddress = this.RadiusServerAddress;
51+
radiusServer.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
52+
53+
// default score value
54+
radiusServer.RadiusServerScore = (!this.MyInvocation.BoundParameters.ContainsKey("RadiusServerScore")) ? 30 : this.RadiusServerScore;
55+
56+
WriteObject(radiusServer);
57+
}
58+
}
59+
}

src/Network/Network/VirtualNetworkGateway/NewAzureVirtualNetworkGatewayCommand.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,21 +230,28 @@ public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
230230
public SwitchParameter Force { get; set; }
231231

232232
[Parameter(
233-
Mandatory = true,
233+
Mandatory = false,
234234
ValueFromPipelineByPropertyName = true,
235235
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
236236
HelpMessage = "P2S External Radius server address.")]
237237
[ValidateNotNullOrEmpty]
238238
public string RadiusServerAddress { get; set; }
239239

240240
[Parameter(
241-
Mandatory = true,
241+
Mandatory = false,
242242
ValueFromPipelineByPropertyName = true,
243243
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
244244
HelpMessage = "P2S External Radius server secret.")]
245245
[ValidateNotNullOrEmpty]
246246
public SecureString RadiusServerSecret { get; set; }
247247

248+
[Parameter(
249+
Mandatory = false,
250+
ValueFromPipelineByPropertyName = true,
251+
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
252+
HelpMessage = "P2S multiple external Radius server servers.")]
253+
public PSRadiusServer[] RadiusServers { get; set; }
254+
248255
[Parameter(
249256
Mandatory = true,
250257
ValueFromPipelineByPropertyName = true,
@@ -433,6 +440,11 @@ private PSVirtualNetworkGateway CreateVirtualNetworkGateway()
433440
vnetGateway.VpnClientConfiguration.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
434441
}
435442

443+
if (this.RadiusServers != null && this.RadiusServers.Any())
444+
{
445+
vnetGateway.VpnClientConfiguration.RadiusServers = this.RadiusServers?.ToList();
446+
}
447+
436448
if (this.AadTenantUri != null)
437449
{
438450
if (this.AadIssuerUri == null || this.AadAudienceId == null)

src/Network/Network/VirtualNetworkGateway/UpdateAzureVirtualNetworkGatewayCommand.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,44 @@ public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
139139
public SwitchParameter DisableActiveActiveFeature { get; set; }
140140

141141
[Parameter(
142-
Mandatory = true,
142+
Mandatory = false,
143143
ValueFromPipelineByPropertyName = true,
144144
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
145145
HelpMessage = "P2S External Radius server address.")]
146146
[Parameter(
147-
Mandatory = true,
147+
Mandatory = false,
148148
ValueFromPipelineByPropertyName = true,
149149
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration + VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
150150
HelpMessage = "P2S External Radius server address.")]
151151
[ValidateNotNullOrEmpty]
152152
public string RadiusServerAddress { get; set; }
153153

154154
[Parameter(
155-
Mandatory = true,
155+
Mandatory = false,
156156
ValueFromPipelineByPropertyName = true,
157157
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
158158
HelpMessage = "P2S External Radius server secret.")]
159159
[Parameter(
160-
Mandatory = true,
160+
Mandatory = false,
161161
ValueFromPipelineByPropertyName = true,
162162
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration + VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
163163
HelpMessage = "P2S External Radius server secret.")]
164164
[ValidateNotNullOrEmpty]
165165
public SecureString RadiusServerSecret { get; set; }
166166

167+
[Parameter(
168+
Mandatory = false,
169+
ValueFromPipelineByPropertyName = true,
170+
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration,
171+
HelpMessage = "P2S multiple external Radius servers.")]
172+
[Parameter(
173+
Mandatory = false,
174+
ValueFromPipelineByPropertyName = true,
175+
ParameterSetName = VirtualNetworkGatewayParameterSets.RadiusServerConfiguration + VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
176+
HelpMessage = "P2S multiple external Radius servers.")]
177+
[ValidateNotNullOrEmpty]
178+
public PSRadiusServer[] RadiusServers { get; set; }
179+
167180
[Parameter(
168181
Mandatory = true,
169182
ValueFromPipelineByPropertyName = true,
@@ -265,6 +278,7 @@ public override void Execute()
265278
this.VpnClientRevokedCertificates != null ||
266279
this.RadiusServerAddress != null ||
267280
this.RadiusServerSecret != null ||
281+
this.RadiusServers != null ||
268282
(this.VpnClientIpsecPolicy != null && this.VpnClientIpsecPolicy.Length != 0) ||
269283
this.AadTenantUri != null) &&
270284
this.VirtualNetworkGateway.VpnClientConfiguration == null)
@@ -300,13 +314,19 @@ public override void Execute()
300314

301315
if (ParameterSetName.Contains(VirtualNetworkGatewayParameterSets.RadiusServerConfiguration))
302316
{
303-
if (this.RadiusServerSecret == null || this.RadiusServerAddress == null)
317+
if ((this.RadiusServerSecret == null || this.RadiusServerAddress == null) && (this.RadiusServers == null || !this.RadiusServers.Any()))
304318
{
305319
throw new ArgumentException("Both radius server address and secret must be specified if external radius is being configured");
306320
}
307321

308322
this.VirtualNetworkGateway.VpnClientConfiguration.RadiusServerAddress = this.RadiusServerAddress;
309-
this.VirtualNetworkGateway.VpnClientConfiguration.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
323+
324+
if (this.RadiusServerSecret != null)
325+
{
326+
this.VirtualNetworkGateway.VpnClientConfiguration.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
327+
}
328+
329+
this.VirtualNetworkGateway.VpnClientConfiguration.RadiusServers = this.RadiusServers?.ToList();
310330
}
311331

312332
if (ParameterSetName.Contains(VirtualNetworkGatewayParameterSets.AadAuthenticationConfiguration))

0 commit comments

Comments
 (0)