Skip to content

Multiple Radius Servers for VPN scenario #11550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
291ef21
multiple radius initial commit
henry416 Apr 10, 2020
3a3b8d5
new cmdlet
henry416 Apr 10, 2020
60a3689
cortex scenario
henry416 Apr 10, 2020
689cc88
updated tests
henry416 Apr 13, 2020
51985c6
rebased and PR comments
henry416 Apr 20, 2020
5ee0e3f
fixed test issue
henry416 Apr 22, 2020
2178f14
reworked parametersets
henry416 Apr 23, 2020
409fb72
revert Set test
henry416 Apr 23, 2020
b66c9c1
supress a junk secret
henry416 Apr 27, 2020
ab7a846
multiple radius initial commit
henry416 Apr 10, 2020
7c571f0
new cmdlet
henry416 Apr 10, 2020
5710d7a
cortex scenario
henry416 Apr 10, 2020
2aa5d9c
updated tests
henry416 Apr 13, 2020
737715e
rebased and PR comments
henry416 Apr 20, 2020
febf6b4
fixed test issue
henry416 Apr 22, 2020
32ed2b8
reworked parametersets
henry416 Apr 23, 2020
5a547f0
revert Set test
henry416 Apr 23, 2020
e9b8578
supress a junk secret
henry416 Apr 27, 2020
117f908
only allow one type of radius to be set
henry416 Apr 28, 2020
41917d7
Merge branch 'radius' of https://github.com/henry416/azure-powershell…
henry416 Apr 28, 2020
aacc438
help files
henry416 Apr 28, 2020
56d1368
filled in MD file
henry416 Apr 29, 2020
e652816
suppress exception
henry416 Apr 29, 2020
e02bf20
Merge remote-tracking branch 'upstream/master' into radius
henry416 Apr 29, 2020
52633f8
suppress other cmdlet signature issue
henry416 Apr 29, 2020
767508a
Merge branch 'master' into radius
henry416 May 1, 2020
4a36dd0
fix
henry416 May 4, 2020
1d49b58
Merge branch 'radius' of https://github.com/henry416/azure-powershell…
henry416 May 4, 2020
1c36974
reset static analysis and fixed new cmdlet for default parameter
henry416 May 5, 2020
0bc94a6
merged signatureissue fix
henry416 May 6, 2020
0fb7c2a
fixed typo
henry416 May 6, 2020
b09407e
removed RemoveAzureSecurityPartnerProviderCommand exception as per PR…
henry416 May 6, 2020
e4311c3
Revert "removed RemoveAzureSecurityPartnerProviderCommand exception a…
henry416 May 6, 2020
2adb21b
Merge remote-tracking branch 'upstream/master' into radius
henry416 May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public void VirtualNetworkGatewayOpenVPNAADAuthTest()
TestRunner.RunTestScript("Test-VirtualNetworkGatewayOpenVPNAADAuth");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)]
public void VirtualNetworkGatewayRadiusTest()
{
TestRunner.RunTestScript("Test-VirtualNetworkGatewayRadius");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset3)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function Test-SetVirtualNetworkGatewayCRUD
$gw1ipconfBgp1 = New-AzIpConfigurationBgpPeeringAddressObject -IpConfigurationId $ipconfigurationId1 -CustomAddress $addresslist1
$gateway = Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gateway -IpConfigurationBgpPeeringAddresses $gw1ipconfBgp1
Assert-AreEqual $ipconfigurationId1 $gateway.BgpSettings.BGPPeeringAddresses[0].IpConfigurationId

# Tags
$gateway = Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gateway -Tag @{ testtagKey="SomeTagKey"; testtagValue="SomeKeyValue" }
Assert-AreEqual 2 $gateway.Tag.Count
Expand Down Expand Up @@ -648,6 +648,80 @@ function Test-VirtualNetworkGatewayIkeV2
}
}

<#
.SYNOPSIS
Virtual network gateway P2S radius API test
#>
function Test-VirtualNetworkGatewayRadius
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$domainNameLabel = Get-ResourceName
$vnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/virtualNetworkGateways"
$location = Get-ProviderLocation $resourceTypeParent

try
{
# Create the multiple radius servers settings
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
$radiuspd = ConvertTo-SecureString -String "radiuspd" -AsPlainText -Force
$radiusServer1 = New-AzRadiusServer -RadiusServerAddress 10.1.0.1 -RadiusServerSecret $radiuspd -RadiusServerScore 30
$radiusServer2 = New-AzRadiusServer -RadiusServerAddress 10.1.0.2 -RadiusServerSecret $radiuspd -RadiusServerScore 1
$radiusServer3 = New-AzRadiusServer -RadiusServerAddress 10.1.0.3 -RadiusServerSecret $radiuspd -RadiusServerScore 15
$radiusServers = @( $radiusServer1, $radiusServer2 )

# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create the Virtual Network
$subnet = New-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -AddressPrefix 10.0.0.0/24
$vnet = New-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet
$vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$subnet = Get-AzVirtualNetworkSubnetConfig -Name "GatewaySubnet" -VirtualNetwork $vnet

# Create the IP config
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet

# Create & Get virtualnetworkgateway
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" -RadiusServerList $radiusServers
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers.Count 2
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerAddress $radiusServer1.RadiusServerAddress
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerScore $radiusServer1.RadiusServerScore
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerAddress $radiusServer2.RadiusServerAddress
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerScore $radiusServer2.RadiusServerScore

# Update gateway to singular radius
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientAddressPool 201.169.0.0/16 -VpnClientProtocol "IkeV2" -RadiusServerAddress 10.1.0.2 -RadiusServerSecret $radiuspd
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-Null $actual.VpnClientConfiguration.RadiusServers
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServerAddress 10.1.0.2

# Update gateway radius settings
$radiusServers = @($radiusServer3, $radiusServer1)
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $actual -VpnClientAddressPool 201.169.0.0/16 -VpnClientProtocol "IkeV2" -RadiusServerList $radiusServers
$actual = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $rname
Assert-Null $actual.VpnClientConfiguration.RadiusServerAddress
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers.Count 2
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerAddress $radiusServer3.RadiusServerAddress
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[0].RadiusServerScore $radiusServer3.RadiusServerScore
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerAddress $radiusServer1.RadiusServerAddress
Assert-AreEqual $actual.VpnClientConfiguration.RadiusServers[1].RadiusServerScore $radiusServer1.RadiusServerScore
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}


<#
.SYNOPSIS
Virtual network gateway P2S OpenVPN API test
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Set-AzPublicIpPrefix', 'Get-AzRouteTable', 'New-AzRouteTable',
'Remove-AzRouteTable', 'Add-AzRouteConfig', 'Get-AzRouteConfig',
'New-AzRouteConfig', 'Remove-AzRouteConfig', 'Set-AzRouteConfig',
'Set-AzRouteTable', 'Set-AzVirtualNetworkGateway',
'Set-AzRouteTable', 'New-AzRadiusServer', 'Set-AzVirtualNetworkGateway',
'Get-AzVirtualNetworkGateway', 'New-AzVirtualNetworkGateway',
'Get-AzVirtualNetworkGatewayVpnclientConnectionHealth',
'Get-AzVpnClientRootCertificate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,23 @@ public class NewAzureRmVpnServerConfigurationCommand : VpnServerConfigurationBas
public string[] VpnClientRevokedCertificateFilesList { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External Radius server address.")]
[ValidateNotNullOrEmpty]
public string RadiusServerAddress { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External Radius server secret.")]
[ValidateNotNullOrEmpty]
public SecureString RadiusServerSecret { get; set; }

[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External multiple radius servers.")]
public PSRadiusServer[] RadiusServerList { get; set; }

[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
Expand Down Expand Up @@ -172,6 +176,7 @@ public override void Execute()
this.VpnClientRevokedCertificateFilesList,
this.RadiusServerAddress,
this.RadiusServerSecret,
this.RadiusServerList,
this.RadiusServerRootCertificateFilesList,
this.RadiusClientRootCertificateFilesList,
this.AadTenant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public class UpdateAzureRmVpnServerConfigurationCommand : VpnServerConfiguration
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationResourceId + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External Radius server address.")]
[ValidateNotNullOrEmpty]
public string RadiusServerAddress { get; set; }

[Parameter(
Expand All @@ -184,9 +183,22 @@ public class UpdateAzureRmVpnServerConfigurationCommand : VpnServerConfiguration
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationResourceId + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External Radius server secret.")]
[ValidateNotNullOrEmpty]
public SecureString RadiusServerSecret { get; set; }

[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External multiple radius servers.")]
[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationObject + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External multiple radius servers.")]
[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationResourceId + CortexParameterSetNames.ByRadiusAuthentication,
HelpMessage = "P2S External multiple radius servers.")]
public PSRadiusServer[] RadiusServerList { get; set; }

[Parameter(
Mandatory = false,
ParameterSetName = CortexParameterSetNames.ByVpnServerConfigurationName + CortexParameterSetNames.ByRadiusAuthentication,
Expand Down Expand Up @@ -364,19 +376,30 @@ public override void Execute()
// VpnAuthenticationType = Radius related validations.
else if (vpnServerConfigurationToUpdate.VpnAuthenticationTypes.Contains(MNM.VpnAuthenticationType.Radius))
{
if (this.RadiusServerAddress != null)
if ((this.RadiusServerList != null && this.RadiusServerList.Count() > 0) && (this.RadiusServerAddress != null || this.RadiusServerSecret != null))
{
vpnServerConfigurationToUpdate.RadiusServerAddress = this.RadiusServerAddress;
throw new ArgumentException("Cannot configure both singular radius server and multiple radius servers at the same time.");
}

if (this.RadiusServerSecret != null)
if (RadiusServerList != null && this.RadiusServerList.Count() > 0)
{
vpnServerConfigurationToUpdate.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
vpnServerConfigurationToUpdate.RadiusServers = this.RadiusServerList.ToList();
vpnServerConfigurationToUpdate.RadiusServerAddress = null;
vpnServerConfigurationToUpdate.RadiusServerSecret = null;
}

if (vpnServerConfigurationToUpdate.RadiusServerAddress == null || vpnServerConfigurationToUpdate.RadiusServerSecret == null)
else
{
throw new ArgumentException("Both radius server address and secret must be specified if VpnAuthenticationType is being configured as Radius.");
if (this.RadiusServerAddress != null)
{
vpnServerConfigurationToUpdate.RadiusServerAddress = this.RadiusServerAddress;
}

if (this.RadiusServerSecret != null)
{
vpnServerConfigurationToUpdate.RadiusServerSecret = SecureStringExtensions.ConvertToString(this.RadiusServerSecret);
}

vpnServerConfigurationToUpdate.RadiusServers = null;
}

// Read the RadiusServerRootCertificates if present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public PSVpnServerConfiguration CreateVpnServerConfigurationObject(
string[] vpnClientRevokedCertificateFilesList,
string radiusServerAddress,
SecureString radiusServerSecret,
PSRadiusServer[] radiusServers,
string[] radiusServerRootCertificateFilesList,
string[] radiusClientRootCertificateFilesList,
string aadTenant,
Expand Down Expand Up @@ -172,13 +173,17 @@ public PSVpnServerConfiguration CreateVpnServerConfigurationObject(
// VpnAuthenticationType = Radius related validations.
else if (vpnAuthenticationType.Contains(MNM.VpnAuthenticationType.Radius))
{
if (radiusServerAddress == null || radiusServerSecret == null)
if (radiusServerAddress != null)
{
throw new ArgumentException("Both radius server address and secret must be specified if VpnAuthenticationType is being configured as Radius.");
vpnServerConfiguration.RadiusServerAddress = radiusServerAddress;
}

vpnServerConfiguration.RadiusServerAddress = radiusServerAddress;
vpnServerConfiguration.RadiusServerSecret = SecureStringExtensions.ConvertToString(radiusServerSecret);
if (radiusServerSecret != null)
{
vpnServerConfiguration.RadiusServerSecret = SecureStringExtensions.ConvertToString(radiusServerSecret);
}

vpnServerConfiguration.RadiusServers = radiusServers?.ToList();

// Read the RadiusServerRootCertificates if present
if (radiusServerRootCertificateFilesList != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public partial class PSVpnClientConfiguration
public List<PSVpnClientRootCertificate> VpnClientRootCertificates { get; set; }
public List<PSVpnClientRevokedCertificate> VpnClientRevokedCertificates { get; set; }
public List<PSIpsecPolicy> VpnClientIpsecPolicies { get; set; }
public List<PSRadiusServer> RadiusServers { get; set; }

[JsonIgnore]
public string VpnClientProtocolsText
Expand Down Expand Up @@ -78,5 +79,11 @@ public string VpnClientIpsecPoliciesText
{
get { return JsonConvert.SerializeObject(VpnClientIpsecPolicies, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string RadiusServersText
{
get { return JsonConvert.SerializeObject(RadiusServers, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}
}
}
8 changes: 8 additions & 0 deletions src/Network/Network/Models/Cortex/PSVpnServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class PSVpnServerConfiguration : PSTopLevelResource

public string RadiusServerSecret { get; set; }

public List<PSRadiusServer> RadiusServers { get; set; }

public PSAadAuthenticationParameters AadAuthenticationParameters { get; set; }

[Ps1Xml(Label = "P2SVpnGateway ids", Target = ViewControl.Table)]
Expand All @@ -61,6 +63,12 @@ public string VpnClientRevokedCertificatesText
get { return JsonConvert.SerializeObject(VpnClientRevokedCertificates, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string RadiusServersText
{
get { return JsonConvert.SerializeObject(RadiusServers, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string RadiusServerRootCertificatesText
{
Expand Down
38 changes: 38 additions & 0 deletions src/Network/Network/Models/PSRadiusServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.Common.Attributes;

namespace Microsoft.Azure.Commands.Network.Models
{
public class PSRadiusServer
{
/// <summary>
/// Radius server address
/// </summary>
[Ps1Xml(Target = ViewControl.Table)]
public string RadiusServerAddress { get; set; }

/// <summary>
/// Radius server secret
/// </summary>
public string RadiusServerSecret { get; set; }

/// <summary>
/// Radius server score
/// </summary>
[Ps1Xml(Target = ViewControl.Table)]
public int RadiusServerScore { get; set; }
}
}
Loading