Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions src/Network/Network.Test/ScenarioTests/Data/VpnGatewayAuthCert.cer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIC/TCCAeWgAwIBAgIQHWaON77uI45Gb0Ei98299TANBgkqhkiG9w0BAQsFADAW
MRQwEgYDVQQDDAtWUE5Sb290Q0EwMTAgFw0yNTEwMDIxNjExNDZaGA8yMjI1MTAw
MjE2MjEzOFowFjEUMBIGA1UEAwwLVlBOUm9vdENBMDEwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQC4eU6WOksIAz1FtfW2LuEsVC0Yiaf7eQtTcFLm8YSC
mwhkOJ1Jj25mNoMxhgPPwq35kELq4roSeizGqIQl4rCYRwyj0RtlM1DjF3QfxMe9
OYLMNiOMf8cIWu17cRuGbiHMJrAdDBSSZ9lTeqd1NZ5XgCmw4evXkoY934IBdtuP
DfqpVy7iqx3aU/sGXvGJER3KDcTD6NRopbW7VyGRCxXbMTt1l+bwWGFNElsgnNxn
B/6Ic1ftKYsCB1XL2/yg9iiewTonH6HQnfg9uc09mwJhyTDFaQ3r6ss+AkexbCqQ
mn7l+mPGwJQoV3BbMJItgsuWD2+h4Mux2mxGILg7LzcVAgMBAAGjRTBDMA4GA1Ud
DwEB/wQEAwICBDASBgNVHRMBAf8ECDAGAQH/AgEEMB0GA1UdDgQWBBSutUa5Oc3X
j50LIdlyfQVWu/n6EDANBgkqhkiG9w0BAQsFAAOCAQEAf7qXfQt32CLuZVWUJ0F3
GibllX5WWdG3zr01X1qZYW0rTVYjPCBl85o9kXJmI377J0q6/7dYMz+bPIZg7KEd
R7ZuOJ6Sxo5LwXzujd5CNZYeCMd7VnUFmQv3lqf3v7El+2Sym8O1hlLeRlVkws7/
xB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/pHiibqszOUqin8sL6t3T32UlvfB3b07LALQ/Q+PTnx1SyFs12
yOPKLPzdYPkrnLQ45MMaTJFdDFeMc/Mk1QeRdqyk65XoFXDj3hqxhZvHZ6H1+OmX
xKscuQdKQlFs4LviI6bQTBuKQFlmAqlLKLVSIHSDJlgFDZIqsfZAYmjkatM24RxN
fV8HWbNVLDiInAgNXj+GL2zg8UUNVEjgh1M2ZqgRZpBqtNhkF+GoUn6bKFIkd/LF
+hgbehKSTWc8OlzmsZZMK1LWGK8ZIsGj2W6QrayyMGzOUy16BHg1fJLUwpibK7tt
Qbc0oFE=
-----END CERTIFICATE-----
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,13 @@ public void TestVirtualNetworkGatewayConnectionGetIkeSa()
{
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionGetIkeSa");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.brooklynft_subset4)]
public void TestVirtualNetworkGatewayConnectionWithCertificateAuth()
{
TestRunner.RunTestScript("Test-VirtualNetworkGatewayConnectionWithCertificateAuth");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -974,3 +974,123 @@ function Test-VirtualNetworkGatewayConnectionGetIkeSa
}
}

function Test-VirtualNetworkGatewayConnectionWithCertificateAuth
{
# Setup
$rgname = Get-ResourceGroupName
$vnetName = Get-ResourceName
$localnetName = Get-ResourceName
$vnetConnectionName = Get-ResourceName
$vnetGatewayName = Get-ResourceName
$publicIpName = Get-ResourceName
$identityName = Get-ResourceName
$vnetGatewayConfigName = Get-ResourceName
$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/connections"
$location = Get-ProviderLocation $resourceTypeParent

try
{

$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation -Tags @{ testtag = "testval" }

# Create managed identity
$identity = New-AzUserAssignedIdentity -ResourceGroupName $rgname -Name $identityName -Location $location

$keyVaultName = "kv" + $rgname.Substring(0, [Math]::Min(15, $rgname.Length))
$keyVault = New-AzKeyVault -ResourceGroupName $rgname -VaultName $keyVaultName -Location $location -EnabledForDeployment -Sku Standard -DisableRbacAuthorization

# 2. Grant managed identity access to Key Vault certificates
Set-AzKeyVaultAccessPolicy -VaultName $keyVaultName -ObjectId $identity.PrincipalId -PermissionsToCertificates get,list -PermissionsToSecrets get,list

$currentUser = (Get-AzContext).Account.Id
Set-AzKeyVaultAccessPolicy -VaultName $keyVaultName -UserPrincipalName $currentUser -PermissionsToCertificates get,list,create,delete,import

# 3. Import certificate
$certFilePath = "./ScenarioTests/Data/VpnGatewayoutboundcert.pfx"
$certPassword = ConvertTo-SecureString -String "12345" -Force -AsPlainText
Import-AzKeyVaultCertificate -VaultName $keyVaultName -Name "vpn-gateway-cert" `
-FilePath $certFilePath -Password $certPassword

# 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

$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -DomainNameLabel $publicIpName

# Create VirtualNetworkGateway with managed identity
$vnetIpConfig = New-AzVirtualNetworkGatewayIpConfig -Name $vnetGatewayConfigName -PublicIpAddress $publicip -Subnet $subnet
$actual = New-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $vnetGatewayName -location $location -IpConfigurations $vnetIpConfig -GatewayType Vpn -VpnType RouteBased -EnableBgp $false -GatewaySku VpnGw1 -UserAssignedIdentityId $identity.Id
$vnetGateway = Get-AzVirtualNetworkGateway -ResourceGroupName $rgname -name $vnetGatewayName

Assert-AreEqual "Succeeded" $vnetGateway.ProvisioningState
Assert-NotNull $vnetGateway.Identity

# Create LocalNetworkGateway
$localGateway = New-AzLocalNetworkGateway -ResourceGroupName $rgname -name $localnetName -location $location -AddressPrefix 192.168.0.0/16 -GatewayIpAddress 192.168.4.5

$cert = Get-AzKeyVaultCertificate -VaultName $keyVaultName -Name "vpn-gateway-cert"
$outboundCertUrl = $cert.Id
$certData = Get-AzKeyVaultCertificate -VaultName $keyVaultName -Name "vpn-gateway-cert"
$certBytes = [System.Convert]::ToBase64String($certData.Certificate.RawData)
$subjectName = $certData.Certificate.Subject

$inboundCert1Path = "./ScenarioTests/Data/VpnGatewayInboundCert.cer"
$inboundCert2Path = "./ScenarioTests/Data/VpnGatewayAuthCert.cer"
$inboundCert1Data = Get-Content -Path $inboundCert1Path -Raw
$inboundCert2Data = Get-Content -Path $inboundCert2Path -Raw

# Remove PEM headers if present and get Base64 only
$inboundCert1Base64 = $inboundCert1Data -replace "-----BEGIN CERTIFICATE-----", "" -replace "-----END CERTIFICATE-----", ""
$inboundCert2Base64 = $inboundCert2Data -replace "-----BEGIN CERTIFICATE-----", "" -replace "-----END CERTIFICATE-----", ""
$certChain = @($inboundCert1Base64, $inboundCert2Base64)

$certAuth = New-AzVirtualNetworkGatewayCertificateAuthentication `
-OutboundAuthCertificate $outboundCertUrl `
-InboundAuthCertificateSubjectName $subjectName `
-InboundAuthCertificateChain $certChain

# Verify certificate authentication object properties
Assert-AreEqual $outboundCertUrl $certAuth.OutboundAuthCertificate
Assert-AreEqual $subjectName $certAuth.InboundAuthCertificateSubjectName
Assert-AreEqual 2 $certAuth.InboundAuthCertificateChain.Count
Assert-NotNull $certAuth.InboundAuthCertificateChain[0]
Assert-NotNull $certAuth.InboundAuthCertificateChain[1]

# Create VirtualNetworkGatewayConnection with Certificate Authentication
$actual = New-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName -location $location -VirtualNetworkGateway1 $vnetGateway -LocalNetworkGateway2 $localGateway -ConnectionType IPsec -RoutingWeight 3 -AuthenticationType "Certificate" -CertificateAuthentication $certAuth

# Verify connection was created successfully
$connection = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual $connection.ResourceGroupName $actual.ResourceGroupName
Assert-AreEqual $connection.Name $actual.Name
Assert-AreEqual "Certificate" $connection.AuthenticationType
Assert-NotNull $connection.CertificateAuthentication
Assert-AreEqual $outboundCertUrl $connection.CertificateAuthentication.OutboundAuthCertificate
Assert-AreEqual $subjectName $connection.CertificateAuthentication.InboundAuthCertificateSubjectName
Assert-AreEqual 2 $connection.CertificateAuthentication.InboundAuthCertificateChain.Count

# Update with new certificate (just use same cert for test purposes)
$newCertAuth = New-AzVirtualNetworkGatewayCertificateAuthentication -OutboundAuthCertificate $outboundCertUrl -InboundAuthCertificateSubjectName $subjectName -InboundAuthCertificateChain $certChain

$updatedConnection = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $connection -AuthenticationType "Certificate" -CertificateAuthentication $newCertAuth -Force

# Verify update
$verifyConnection = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -name $vnetConnectionName
Assert-AreEqual "Certificate" $verifyConnection.AuthenticationType
Assert-AreEqual $outboundCertUrl $verifyConnection.CertificateAuthentication.OutboundAuthCertificate
Assert-AreEqual $subjectName $verifyConnection.CertificateAuthentication.InboundAuthCertificateSubjectName

# List connections and verify
$list = Get-AzVirtualNetworkGatewayConnection -ResourceGroupName $rgname -Name "*"
Assert-True { $list.Count -ge 1 }

}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'New-AzVirtualHubRoute', 'New-AzVirtualHubRouteTable',
'New-AzVirtualHubVnetConnection', 'New-AzVirtualNetwork',
'New-AzVirtualNetworkGateway',
'New-AzVirtualNetworkGatewayCertificateAuthentication',
'New-AzVirtualNetworkGatewayConnection',
'New-AzVirtualNetworkGatewayIpConfig',
'New-AzVirtualNetworkGatewayMigrationParameter',
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
--->

## Upcoming Release
* Added certificate-based authentication support for VPN Gateway connections
- New cmdlet `New-AzVirtualNetworkGatewayCertificateAuthentication` to create certificate authentication configuration
- Added `-AuthenticationType` and `-CertificateAuthentication` parameters to `New-AzVirtualNetworkGatewayConnection` and `Set-AzVirtualNetworkGatewayConnection`
- Added `-UserAssignedIdentityId` parameter to `Set-AzVirtualNetworkGateway` for managed identity configuration

## Version 7.21.0
- Added deprecation warning for cmdlet `Invoke-AzFirewallPacketCapture`
Expand Down
32 changes: 32 additions & 0 deletions src/Network/Network/Models/PSCertificateAuthentication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ----------------------------------------------------------------------------------
//
// 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.Azure.Management.Network.Models;
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Network.Models
{
public class PSCertificateAuthentication
{
[Ps1Xml(Label = "OutboundAuthCertificate", Target = ViewControl.Table, Position = 0)]
public string OutboundAuthCertificate { get; set; }

[Ps1Xml(Label = "InboundAuthCertificateSubjectName", Target = ViewControl.Table, Position = 1)]
public string InboundAuthCertificateSubjectName { get; set; }

[Ps1Xml(Label = "InboundAuthCertificateChain", Target = ViewControl.Table, Position = 2)]
public List<string> InboundAuthCertificateChain { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Network/Network/Models/PSVirtualNetworkGateway.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class PSVirtualNetworkGateway : PSTopLevelResource
[Ps1Xml(Label = "AutoScaleConfiguration", Target = ViewControl.Table)]
public PSVirtualNetworkGatewayAutoscaleConfiguration AutoScaleConfiguration { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public PSManagedServiceIdentity Identity { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public PSVirtualNetworkGatewayMigrationStatus VirtualNetworkGatewayMigrationStatus { get; set; }

Expand Down Expand Up @@ -150,6 +153,12 @@ public string AutoScaleConfigurationText
get { return JsonConvert.SerializeObject(AutoScaleConfiguration, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

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

[JsonIgnore]
public string VirtualNetworkGatewayMigrationStatusText
{
Expand Down
11 changes: 11 additions & 0 deletions src/Network/Network/Models/PSVirtualNetworkGatewayConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public class PSVirtualNetworkGatewayConnection : PSTopLevelResource

public bool EnablePrivateLinkFastPath { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string AuthenticationType { get; set; }

public PSCertificateAuthentication CertificateAuthentication { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string ConnectionProtocol { get; set; }

Expand Down Expand Up @@ -136,5 +141,11 @@ public string GatewayCustomBgpIpAddressesText
{
get { return GatewayCustomBgpIpAddresses == null ? string.Empty : JsonConvert.SerializeObject(GatewayCustomBgpIpAddresses, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}

[JsonIgnore]
public string CertificateAuthenticationText
{
get { return CertificateAuthentication == null ? string.Empty : JsonConvert.SerializeObject(CertificateAuthentication, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
[Parameter(Mandatory = false, HelpMessage = "Set max scale units for scalable gateways")]
public Int32 MaxScaleUnit { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "ResourceId of the user assigned identity to be assigned to virtual network gateway.")]
[ValidateNotNullOrEmpty]
[Alias("UserAssignedIdentity")]
public string UserAssignedIdentityId { get; set; }

[Parameter(Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The managed identity configuration for the virtual network gateway.")]
public PSManagedServiceIdentity Identity { get; set; }

public override void Execute()
{
base.Execute();
Expand Down Expand Up @@ -648,6 +661,22 @@ private PSVirtualNetworkGateway CreateVirtualNetworkGateway()
vnetGateway.NatRules = this.NatRule?.ToList();
}

if (this.UserAssignedIdentityId != null)
{
vnetGateway.Identity = new PSManagedServiceIdentity
{
Type = MNM.ResourceIdentityType.UserAssigned,
UserAssignedIdentities = new Dictionary<string, PSManagedServiceIdentityUserAssignedIdentitiesValue>
{
{ this.UserAssignedIdentityId, new PSManagedServiceIdentityUserAssignedIdentitiesValue() }
}
};
}
else if (this.Identity != null)
{
vnetGateway.Identity = this.Identity;
}

if (this.AdminState != null)
{
if (!GatewayType.Equals(MNM.VirtualNetworkGatewayType.ExpressRoute.ToString(), StringComparison.InvariantCultureIgnoreCase))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
HelpMessage = "Determines whether this gateway should accept traffic from other Virtual WAN networks.")]
public bool? AllowVirtualWanTraffic { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "ResourceId of the user assigned identity to be assigned to virtual network gateway.")]
[ValidateNotNullOrEmpty]
[Alias("UserAssignedIdentity")]
public string UserAssignedIdentityId { get; set; }

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The managed identity configuration for the virtual network gateway.")]
public PSManagedServiceIdentity Identity { get; set; }

[Parameter(
Mandatory = true,
ParameterSetName = VirtualNetworkGatewayParameterSets.UpdateResourceWithTags,
Expand Down Expand Up @@ -611,6 +625,22 @@ public override void Execute()
this.VirtualNetworkGateway.AllowVirtualWanTraffic = AllowVirtualWanTraffic.Value;
}

if (this.UserAssignedIdentityId != null)
{
this.VirtualNetworkGateway.Identity = new PSManagedServiceIdentity
{
Type = MNM.ResourceIdentityType.UserAssigned,
UserAssignedIdentities = new Dictionary<string, PSManagedServiceIdentityUserAssignedIdentitiesValue>
{
{ this.UserAssignedIdentityId, new PSManagedServiceIdentityUserAssignedIdentitiesValue() }
}
};
}
else if (this.Identity != null)
{
this.VirtualNetworkGateway.Identity = this.Identity;
}

// Map to the sdk object
MNM.VirtualNetworkGateway sdkVirtualNetworkGateway = NetworkResourceManagerProfile.Mapper.Map<MNM.VirtualNetworkGateway>(this.VirtualNetworkGateway);
sdkVirtualNetworkGateway.Tags =
Expand Down
Loading