Skip to content

Commit 8c39c1b

Browse files
author
Maddie Clayton
authored
Merge pull request #8437 from akshaysngupta/master
Cmdlets for managed service identity on Application Gateway
2 parents 37e25e1 + b550822 commit 8c39c1b

22 files changed

+6619
-1749
lines changed

src/Accounts/Accounts/AzureRmAlias/Mappings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,10 @@
12881288
"New-AzApplicationGatewayFrontendPort": "New-AzureRmApplicationGatewayFrontendPort",
12891289
"Remove-AzApplicationGatewayFrontendPort": "Remove-AzureRmApplicationGatewayFrontendPort",
12901290
"Set-AzApplicationGatewayFrontendPort": "Set-AzureRmApplicationGatewayFrontendPort",
1291+
"Get-AzApplicationGatewayIdentity": "Get-AzureRmApplicationGatewayIdentity",
1292+
"New-AzApplicationGatewayIdentity": "New-AzureRmApplicationGatewayIdentity",
1293+
"Remove-AzApplicationGatewayIdentity": "Remove-AzureRmApplicationGatewayIdentity",
1294+
"Set-AzApplicationGatewayIdentity": "Set-AzureRmApplicationGatewayIdentity",
12911295
"Add-AzApplicationGatewayIPConfiguration": "Add-AzureRmApplicationGatewayIPConfiguration",
12921296
"Get-AzApplicationGatewayIPConfiguration": "Get-AzureRmApplicationGatewayIPConfiguration",
12931297
"New-AzApplicationGatewayIPConfiguration": "New-AzureRmApplicationGatewayIPConfiguration",

src/Network/Network.Test/Network.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<PackageReference Include="Microsoft.Azure.Management.ContainerInstance" Version="2.0.0" />
2121
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="4.4.1" />
2222
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.19.0-preview" />
23+
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.10.0-preview" />
2324
</ItemGroup>
2425

2526
<ItemGroup>

src/Network/Network.Test/NetworkResourcesController.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Management.Compute;
1717
using Microsoft.Azure.Management.ContainerInstance;
18+
using Microsoft.Azure.Management.ManagedServiceIdentity;
1819
using Microsoft.Azure.Management.Network;
1920
using Microsoft.Azure.Management.Redis;
2021
using Microsoft.Azure.Management.OperationalInsights;
@@ -48,6 +49,8 @@ public sealed class NetworkResourcesController
4849

4950
public OperationalInsightsManagementClient OperationalInsightsManagementClient { get; private set; }
5051

52+
public ManagedServiceIdentityClient ManagedServiceIdentityClient { get; private set; }
53+
5154
public static NetworkResourcesController NewInstance => new NetworkResourcesController();
5255

5356
public NetworkResourcesController()
@@ -64,7 +67,8 @@ public void RunPsTest(XunitTracingInterceptor logger, params string[] scripts)
6467
{"Microsoft.Compute", null},
6568
{"Microsoft.Features", null},
6669
{"Microsoft.Authorization", null},
67-
{"Microsoft.Storage", null}
70+
{"Microsoft.Storage", null},
71+
{"Microsoft.ManagedServiceIdentity", null}
6872
};
6973
var providersToIgnore = new Dictionary<string, string>
7074
{
@@ -128,6 +132,7 @@ public void RunPsTestWorkflow(
128132
_helper.GetRMModulePath("AzureRM.Compute.psd1"),
129133
_helper.GetRMModulePath("AzureRM.ContainerInstance.psd1"),
130134
_helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"),
135+
_helper.GetRMModulePath("AzureRM.ManagedServiceIdentity.psd1"),
131136
"AzureRM.Storage.ps1",
132137
_helper.GetRMModulePath("AzureRM.Storage.psd1"),
133138
"AzureRM.Resources.ps1");
@@ -161,6 +166,7 @@ private void SetupManagementClients(MockContext context)
161166
StorageManagementClient = GetStorageManagementClient(context);
162167
RedisManagementClient = GetRedisManagementClient(context);
163168
OperationalInsightsManagementClient = GetOperationalInsightsManagementClient(context);
169+
ManagedServiceIdentityClient = GetManagedServiceIdentityClient(context);
164170

165171
_helper.SetupManagementClients(
166172
resourceManagerResourceManagementClient,
@@ -169,7 +175,13 @@ private void SetupManagementClients(MockContext context)
169175
ContainerInstanceManagementClient,
170176
StorageManagementClient,
171177
RedisManagementClient,
172-
OperationalInsightsManagementClient);
178+
OperationalInsightsManagementClient,
179+
ManagedServiceIdentityClient);
180+
}
181+
182+
private static ManagedServiceIdentityClient GetManagedServiceIdentityClient(MockContext context)
183+
{
184+
return context.GetServiceClient<ManagedServiceIdentityClient>(TestEnvironmentFactory.GetTestEnvironment());
173185
}
174186

175187
private static NetworkManagementClient GetNetworkManagementClient(MockContext context)
@@ -203,3 +215,4 @@ private static ContainerInstanceManagementClient GetContainerInstanceManagementC
203215
}
204216
}
205217
}
218+

src/Network/Network.Test/ScenarioTests/ApplicationGatewayTests.ps1

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,12 @@ function Test-ApplicationGatewayCRUDRewriteRuleSet
644644
# Get Application Gateway
645645
$getgw = Get-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname
646646

647-
$rewriteRuleSet = Get-AzureRmApplicationGatewayRewriteRuleSet -Name $rewriteRuleSetName -ApplicationGateway $getgw
647+
$rewriteRuleSet = Get-AzApplicationGatewayRewriteRuleSet -Name $rewriteRuleSetName -ApplicationGateway $getgw
648648
Assert-NotNull $rewriteRuleSet
649649
Assert-AreEqual $rewriteRuleSet.RewriteRules.Count 1
650650
Assert-NotNull $rewriteRuleSet.RewriteRules[0].ActionSet
651651

652-
$rewriteRuleSet = Get-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
652+
$rewriteRuleSet = Get-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
653653
Assert-NotNull $rewriteRuleSet
654654
Assert-AreEqual $rewriteRuleSet.Count 1
655655

@@ -685,8 +685,8 @@ function Test-ApplicationGatewayCRUDRewriteRuleSet
685685
Assert-NotNull $autoscaleConfig01
686686
Assert-AreEqual $autoscaleConfig01.MinCapacity 3
687687

688-
Set-AzureRmApplicationGatewayAutoscaleConfiguration -ApplicationGateway $getgw -MinCapacity 3 -MaxCapacity 10
689-
$autoscaleConfig02 = Get-AzureRmApplicationGatewayAutoscaleConfiguration -ApplicationGateway $getgw
688+
Set-AzApplicationGatewayAutoscaleConfiguration -ApplicationGateway $getgw -MinCapacity 3 -MaxCapacity 10
689+
$autoscaleConfig02 = Get-AzApplicationGatewayAutoscaleConfiguration -ApplicationGateway $getgw
690690
Assert-NotNull $autoscaleConfig02
691691
Assert-AreEqual $autoscaleConfig02.MinCapacity 3
692692
Assert-AreEqual $autoscaleConfig02.MaxCapacity 10
@@ -701,29 +701,29 @@ function Test-ApplicationGatewayCRUDRewriteRuleSet
701701
$getgw01 = Set-AzApplicationGateway -ApplicationGateway $getgw
702702

703703
#Rewrite Rule Set
704-
Assert-ThrowsLike { Add-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName -RewriteRule $rewriteRule } "*already exists*"
705-
$rewriteRuleSet = Add-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName2 -RewriteRule $rewriteRule
706-
$getgw = Set-AzureRmApplicationGateway -ApplicationGateway $getgw01
704+
Assert-ThrowsLike { Add-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName -RewriteRule $rewriteRule } "*already exists*"
705+
$rewriteRuleSet = Add-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName2 -RewriteRule $rewriteRule
706+
$getgw = Set-AzApplicationGateway -ApplicationGateway $getgw01
707707

708-
$rewriteRuleSet = Get-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
708+
$rewriteRuleSet = Get-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
709709
Assert-NotNull $rewriteRuleSet
710710
Assert-AreEqual $rewriteRuleSet.Count 2
711711

712-
$rewriteRuleSet = Remove-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName2
713-
$getgw = Set-AzureRmApplicationGateway -ApplicationGateway $getgw01
712+
$rewriteRuleSet = Remove-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw01 -Name $rewriteRuleSetName2
713+
$getgw = Set-AzApplicationGateway -ApplicationGateway $getgw01
714714

715-
$rewriteRuleSet = Get-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
715+
$rewriteRuleSet = Get-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw
716716
Assert-NotNull $rewriteRuleSet
717717
Assert-AreEqual $rewriteRuleSet.Count 1
718718

719-
$headerConfiguration = New-AzureRmApplicationGatewayRewriteRuleHeaderConfiguration -HeaderName "ghi" -HeaderValue "jkl"
720-
$actionSet = New-AzureRmApplicationGatewayRewriteRuleActionSet -RequestHeaderConfiguration $headerConfiguration
721-
$rewriteRule2 = New-AzureRmApplicationGatewayRewriteRule -Name $rewriteRuleName -ActionSet $actionSet
719+
$headerConfiguration = New-AzApplicationGatewayRewriteRuleHeaderConfiguration -HeaderName "ghi" -HeaderValue "jkl"
720+
$actionSet = New-AzApplicationGatewayRewriteRuleActionSet -RequestHeaderConfiguration $headerConfiguration
721+
$rewriteRule2 = New-AzApplicationGatewayRewriteRule -Name $rewriteRuleName -ActionSet $actionSet
722722

723-
Assert-ThrowsLike { Set-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name "fakeName" -RewriteRule $rewriteRule2 } "*does not exist*"
724-
$rewriteRuleSet = Set-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name $rewriteRuleSetName -RewriteRule $rewriteRule2
725-
$getgw = Set-AzureRmApplicationGateway -ApplicationGateway $getgw01
726-
$rewriteRuleSet = Get-AzureRmApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name $rewriteRuleSetName
723+
Assert-ThrowsLike { Set-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name "fakeName" -RewriteRule $rewriteRule2 } "*does not exist*"
724+
$rewriteRuleSet = Set-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name $rewriteRuleSetName -RewriteRule $rewriteRule2
725+
$getgw = Set-AzApplicationGateway -ApplicationGateway $getgw01
726+
$rewriteRuleSet = Get-AzApplicationGatewayRewriteRuleSet -ApplicationGateway $getgw -Name $rewriteRuleSetName
727727
Assert-AreEqual $rewriteRuleSet.RewriteRules[0].Name $rewriteRule2.Name
728728

729729
# check sku
@@ -764,6 +764,7 @@ function Test-ApplicationGatewayCRUD3
764764

765765
$rgname = Get-ResourceGroupName
766766
$appgwName = Get-ResourceName
767+
$identityName = Get-ResourceName
767768
$vnetName = Get-ResourceName
768769
$gwSubnetName = Get-ResourceName
769770
$publicIpName = Get-ResourceName
@@ -791,6 +792,9 @@ function Test-ApplicationGatewayCRUD3
791792
$vnet = Get-AzvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
792793
$gwSubnet = Get-AzVirtualNetworkSubnetConfig -Name $gwSubnetName -VirtualNetwork $vnet
793794

795+
# Create Managed Identity
796+
$identity = New-AzUserAssignedIdentity -Name $identityName -Location $location -ResourceGroup $rgname
797+
794798
# Create public ip
795799
$publicip = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Static -sku Standard
796800

@@ -821,8 +825,11 @@ function Test-ApplicationGatewayCRUD3
821825
# security part
822826
$sslPolicy = New-AzApplicationGatewaySslPolicy -PolicyType Custom -MinProtocolVersion TLSv1_1 -CipherSuite "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256"
823827

828+
# appgw identity
829+
$appgwIdentity = New-AzApplicationGatewayIdentity -UserAssignedIdentity $identity.Id
830+
824831
# Create Application Gateway
825-
$appgw = New-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Zone 1,2 -Location $location -Probes $probeHttp -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01 -HttpListeners $listener01 -RequestRoutingRules $rule01 -Sku $sku -SslPolicy $sslPolicy -TrustedRootCertificate $trustedRoot01 -AutoscaleConfiguration $autoscaleConfig
832+
$appgw = New-AzApplicationGateway -Identity $appgwIdentity -Name $appgwName -ResourceGroupName $rgname -Zone 1,2 -Location $location -Probes $probeHttp -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01 -HttpListeners $listener01 -RequestRoutingRules $rule01 -Sku $sku -SslPolicy $sslPolicy -TrustedRootCertificate $trustedRoot01 -AutoscaleConfiguration $autoscaleConfig
826833

827834
# Get Application Gateway
828835
$getgw = Get-AzApplicationGateway -Name $appgwName -ResourceGroupName $rgname
@@ -852,7 +859,7 @@ function Test-ApplicationGatewayCRUD3
852859
Assert-NotNull $autoscaleConfig01
853860
Assert-AreEqual $autoscaleConfig01.MinCapacity 3
854861

855-
# Next setup preparation
862+
# Next: Manual sku gateway
856863

857864
# remove autoscale config
858865
$getgw = Remove-AzApplicationGatewayAutoscaleConfiguration -ApplicationGateway $getgw -Force
@@ -868,6 +875,25 @@ function Test-ApplicationGatewayCRUD3
868875
Assert-AreEqual $sku01.Name Standard_v2
869876
Assert-AreEqual $sku01.Tier Standard_v2
870877

878+
# Next: Set Identity on an existing gateway without identity
879+
# First, Removing identity from the gateway
880+
Remove-AzApplicationGatewayIdentity -ApplicationGateway $getgw01
881+
882+
# Set Application Gateway
883+
$getgw02 = Set-AzApplicationGateway -ApplicationGateway $getgw01
884+
Assert-Null $(Get-AzApplicationGatewayIdentity -ApplicationGateway $getgw01)
885+
886+
# Set identity
887+
Set-AzApplicationGatewayIdentity -ApplicationGateway $getgw02 -UserAssignedIdentityId $identity.Id
888+
889+
# Set Application Gateway
890+
$getgw03 = Set-AzApplicationGateway -ApplicationGateway $getgw02
891+
$identity01 = Get-AzApplicationGatewayIdentity -ApplicationGateway $getgw03
892+
Assert-AreEqual $identity01.UserAssignedIdentities.Count 1
893+
Assert-NotNull $identity01.UserAssignedIdentities.Values[0].PrincipalId
894+
Assert-NotNull $identity01.UserAssignedIdentities.Values[0].ClientId
895+
896+
871897
# Stop Application Gateway
872898
$getgw1 = Stop-AzApplicationGateway -ApplicationGateway $getgw01
873899

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.ApplicationGatewayTests/TestApplicationGatewayCRUD3.json

Lines changed: 5792 additions & 1706 deletions
Large diffs are not rendered by default.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 System;
16+
using System.Collections.Generic;
17+
using System.Management.Automation;
18+
using Microsoft.Azure.Commands.Network.Models;
19+
using MNM = Microsoft.Azure.Management.Network.Models;
20+
21+
namespace Microsoft.Azure.Commands.Network
22+
{
23+
public class AzureApplicationGatewayIdentityBase : NetworkBaseCmdlet
24+
{
25+
[Parameter(
26+
Mandatory = true,
27+
ValueFromPipelineByPropertyName = true,
28+
HelpMessage = "ResourceId of the user assigned identity to be assigned to Application Gateway.")]
29+
[ValidateNotNullOrEmpty]
30+
[Alias("UserAssignedIdentity")]
31+
public string UserAssignedIdentityId { get; set; }
32+
33+
public override void ExecuteCmdlet()
34+
{
35+
base.ExecuteCmdlet();
36+
}
37+
38+
public PSManagedServiceIdentity NewObject()
39+
{
40+
var identity = new PSManagedServiceIdentity
41+
{
42+
Type = MNM.ResourceIdentityType.UserAssigned,
43+
UserAssignedIdentities = new Dictionary<string, PSManagedServiceIdentityUserAssignedIdentitiesValue>
44+
{
45+
{ this.UserAssignedIdentityId, new PSManagedServiceIdentityUserAssignedIdentitiesValue() }
46+
}
47+
};
48+
49+
return identity;
50+
}
51+
}
52+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 System.Management.Automation;
17+
18+
namespace Microsoft.Azure.Commands.Network
19+
{
20+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApplicationGatewayIdentity"), OutputType(typeof(PSManagedServiceIdentity))]
21+
public class GetAzureApplicationGatewayIdentityCommand : NetworkBaseCmdlet
22+
{
23+
[Parameter(
24+
Mandatory = true,
25+
ValueFromPipeline = true,
26+
HelpMessage = "The applicationGateway")]
27+
public PSApplicationGateway ApplicationGateway { get; set; }
28+
29+
public override void ExecuteCmdlet()
30+
{
31+
base.ExecuteCmdlet();
32+
WriteObject(this.ApplicationGateway.Identity, true);
33+
}
34+
}
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 System.Collections.Generic;
16+
using Microsoft.Azure.Commands.Network.Models;
17+
using System.Management.Automation;
18+
19+
namespace Microsoft.Azure.Commands.Network
20+
{
21+
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ApplicationGatewayIdentity", SupportsShouldProcess = true), OutputType(typeof(PSManagedServiceIdentity))]
22+
public class NewAzureApplicationGatewayIdentityCommand : AzureApplicationGatewayIdentityBase
23+
{
24+
public override void ExecuteCmdlet()
25+
{
26+
if (ShouldProcess("AzureApplicationGatewayIdentity", Microsoft.Azure.Commands.Network.Properties.Resources.CreatingResourceMessage))
27+
{
28+
base.ExecuteCmdlet();
29+
WriteObject(this.NewObject());
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)