Skip to content

Commit 394590a

Browse files
authored
Merge pull request Azure#5023 from darshanhs90/preview
update New Roleassignment creation calls to have delegation flag
2 parents 2549cf1 + 0d862f6 commit 394590a

35 files changed

+7436
-3785
lines changed

setup/azurecmdfiles.wxi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,9 @@
12061206
<Component Id="cmpEDD37ABAAA61D07995A186AEF9E62727" Guid="*">
12071207
<File Id="filDCDBE738CB8210E371547BD5AC4CCB6C" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\Microsoft.Azure.Commands.Resources.format.ps1xml" />
12081208
</Component>
1209+
<Component Id="cmpEE349C51ED897F3FA2EB83EC1B30FE67" Guid="*">
1210+
<File Id="fil9477562706B70731726149EAF65B1FB8" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\Microsoft.Azure.Management.Authorization.dll" />
1211+
</Component>
12091212
<Component Id="cmpF4C5AB0BA43DC11E22F9BA4B39EEB532" Guid="*">
12101213
<File Id="filFBCFA6A78D2871F4657A269FF2DFE1E5" KeyPath="yes" Source="$(var.sourceDir)\ResourceManager\AzureResourceManager\AzureRM.Resources\Microsoft.Azure.Management.ResourceManager.dll" />
12111214
</Component>
@@ -3462,6 +3465,7 @@
34623465
<ComponentRef Id="cmpEAECD7C56D29DB281ACD2868F2194EDB" />
34633466
<ComponentRef Id="cmp0714732719C5405F2BCE5004F205B22E" />
34643467
<ComponentRef Id="cmpEDD37ABAAA61D07995A186AEF9E62727" />
3468+
<ComponentRef Id="cmpEE349C51ED897F3FA2EB83EC1B30FE67" />
34653469
<ComponentRef Id="cmpF4C5AB0BA43DC11E22F9BA4B39EEB532" />
34663470
<ComponentRef Id="cmp8F0D94EDAEEDE0C50766C20F5F1D03D9" />
34673471
<ComponentRef Id="cmp890B1E2923E26CE2A15A652293EA92BE" />

src/ResourceManager/Resources/AzureRM.Resources.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ CLRVersion = '4.0'
5454
RequiredModules = @(@{ModuleName = 'AzureRM.Profile'; ModuleVersion = '4.0.0'; })
5555

5656
# Assemblies that must be loaded prior to importing this module
57-
RequiredAssemblies = '.\Microsoft.Azure.Management.ResourceManager.dll',
58-
'.\Microsoft.Azure.ResourceManager.dll'
57+
RequiredAssemblies = '.\Microsoft.Azure.Management.ResourceManager.dll',
58+
'.\Microsoft.Azure.ResourceManager.dll',
59+
'.\Microsoft.Azure.Management.Authorization.dll'
5960

6061
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
6162
# ScriptsToProcess = @()

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
- Users can now use Set-AzureRMRoleRoleDefinition with assignable scopes including new scopes irrespective of the position of the scope
2727
* Allow scopes to end with "/"
2828
- Users can now use RoleDefinition and RoleAssignment commandlets with scopes ending with "/" ,consistent with API and CLI
29+
* Allow users to create RoleAssignment using delegation flag
30+
- Users can now use New-AzureRMRoleAssignment with an option of adding the delegation flag
2931
* Fix RoleAssignment get to respect the scope parameter
3032

3133
## Version 5.0.0

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
<SpecificVersion>False</SpecificVersion>
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Graph.RBAC.3.4.0-preview\lib\net452\Microsoft.Azure.Graph.RBAC.dll</HintPath>
6363
</Reference>
64+
<Reference Include="Microsoft.Azure.Management.Authorization, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
65+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.6.0-preview\lib\net452\Microsoft.Azure.Management.Authorization.dll</HintPath>
66+
</Reference>
6467
<Reference Include="Microsoft.Azure.Insights">
6568
<HintPath>..\..\..\packages\Microsoft.Azure.Insights.0.10.0-preview\lib\net45\Microsoft.Azure.Insights.dll</HintPath>
6669
</Reference>
@@ -246,10 +249,6 @@
246249
<Project>{d3804b64-c0d3-48f8-82ec-1f632f833c9e}</Project>
247250
<Name>Commands.Common.Authentication</Name>
248251
</ProjectReference>
249-
<ProjectReference Include="..\..\..\Common\Commands.Common.Authorization\Commands.Common.Authorization.csproj">
250-
<Project>{24508e26-154d-47f1-80ee-439bf0710996}</Project>
251-
<Name>Commands.Common.Authorization</Name>
252-
</ProjectReference>
253252
<ProjectReference Include="..\..\..\Common\Commands.Common.Graph.RBAC\Commands.Common.Graph.RBAC.csproj">
254253
<Project>{269acf73-0a34-42dc-ab9c-4b15931a489d}</Project>
255254
<Name>Commands.Common.Graph.RBAC</Name>
@@ -712,6 +711,9 @@
712711
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaPropertiesValidation.json">
713712
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
714713
</None>
714+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaDelegation.json">
715+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
716+
</None>
715717
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaGetByScope.json">
716718
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
717719
</None>

src/ResourceManager/Resources/Commands.Resources.Test/Models.ResourceGroups/ResourceClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
2828
using Microsoft.Azure.Commands.Resources.Models;
2929
using Microsoft.Azure.Commands.ScenarioTest;
30-
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
30+
using Microsoft.Azure.Management.Authorization;
3131
using Microsoft.Azure.Management.ResourceManager;
3232
using Microsoft.Azure.Management.ResourceManager.Models;
3333
using Microsoft.Rest.Azure;

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourcesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2424
using Microsoft.Azure.Graph.RBAC.Version1_6;
2525
using Microsoft.Azure.Insights;
26-
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
26+
using Microsoft.Azure.Management.Authorization;
2727
using Microsoft.Azure.Management.ResourceManager;
2828
using Microsoft.Azure.Test.HttpRecorder;
2929
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
using Microsoft.Azure.Graph.RBAC.Version1_6;
1717
using Microsoft.Azure.Graph.RBAC.Version1_6.Models;
18-
using Microsoft.Azure.Management.Authorization.Version2015_07_01;
18+
using Microsoft.Azure.Management.Authorization;
1919
using Microsoft.Azure.Management.ResourceManager;
2020
using Microsoft.Azure.Management.ResourceManager.Models;
2121
using Microsoft.Azure.ServiceManagemenet.Common.Models;
@@ -115,6 +115,13 @@ public void RaDeletionByScopeAtRootScope()
115115
{
116116
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScopeAtRootScope");
117117
}
118+
119+
[Fact]
120+
[Trait(Category.AcceptanceType, Category.CheckIn)]
121+
public void RaDelegation()
122+
{
123+
ResourcesController.NewInstance.RunPsTest("Test-RaDelegation");
124+
}
118125

119126
[Fact]
120127
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleAssignmentTests.ps1

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ Tests retrieval of classic administrators
1818
#>
1919
function Test-RaClassicAdmins
2020
{
21-
# Setup
22-
$subscription = Get-AzureRmSubscription
23-
24-
# Test
25-
$classic = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | Where-Object { $_.Scope -ieq ('/subscriptions/' + $subscription[0].Id) -and $_.RoleDefinitionName.ToLower().Contains('administrator')}
26-
27-
# Assert
28-
Assert-NotNull $classic
29-
Assert-True { $classic.Length -ge 1 }
21+
# Setup
22+
$subscription = Get-AzureRmSubscription
23+
24+
# Test
25+
$classic = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | Where-Object { $_.Scope -ieq ('/subscriptions/' + $subscription[0].Id) -and $_.RoleDefinitionName.ToLower().Contains('administrator')}
26+
27+
# Assert
28+
Assert-NotNull $classic
29+
Assert-True { $classic.Length -ge 1 }
3030
}
3131

3232
<#
@@ -41,11 +41,11 @@ function Test-RaNegativeScenarios
4141
# Bad OID returns zero role assignments
4242
$badOid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
4343
$badObjectResult = "Cannot find principal using the specified options"
44-
$assignments = Get-AzureRmRoleAssignment -ObjectId $badOid
44+
$assignments = Get-AzureRmRoleAssignment -ObjectId $badOid
4545
Assert-AreEqual 0 $assignments.Count
4646

47-
# Bad OID throws if Expand Principal Groups included
48-
Assert-Throws { Get-AzureRmRoleAssignment -ObjectId $badOid -ExpandPrincipalGroups } $badObjectResult
47+
# Bad OID throws if Expand Principal Groups included
48+
Assert-Throws { Get-AzureRmRoleAssignment -ObjectId $badOid -ExpandPrincipalGroups } $badObjectResult
4949

5050
# Bad UPN
5151
$badUpn = '[email protected]'
@@ -110,9 +110,9 @@ function Test-RaByScope
110110

111111
# Assert
112112
Assert-NotNull $newAssignment
113-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114-
Assert-AreEqual $scope $newAssignment.Scope
115-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
113+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114+
Assert-AreEqual $scope $newAssignment.Scope
115+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
116116

117117
VerifyRoleAssignmentDeleted $newAssignment
118118
}
@@ -142,8 +142,8 @@ function Test-RaByResourceGroup
142142

143143
# Assert
144144
Assert-NotNull $newAssignment
145-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
145+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
147147

148148
VerifyRoleAssignmentDeleted $newAssignment
149149
}
@@ -177,8 +177,8 @@ function Test-RaByResource
177177

178178
# Assert
179179
Assert-NotNull $newAssignment
180-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181-
Assert-AreEqual $groups[0].DisplayName $newAssignment.DisplayName
180+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181+
Assert-AreEqual $groups[0].DisplayName $newAssignment.DisplayName
182182

183183
VerifyRoleAssignmentDeleted $newAssignment
184184
}
@@ -261,9 +261,9 @@ function Test-RaByServicePrincipal
261261

262262
# Assert
263263
Assert-NotNull $newAssignment
264-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265-
Assert-AreEqual $scope $newAssignment.Scope
266-
Assert-AreEqual $servicePrincipals[0].DisplayName $newAssignment.DisplayName
264+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265+
Assert-AreEqual $scope $newAssignment.Scope
266+
Assert-AreEqual $servicePrincipals[0].DisplayName $newAssignment.DisplayName
267267

268268
VerifyRoleAssignmentDeleted $newAssignment
269269
}
@@ -282,7 +282,7 @@ function Test-RaByUpn
282282
Assert-AreEqual 1 $resourceGroups.Count "No resource group found. Unable to run the test."
283283

284284
# Test
285-
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f8dac632-b879-42f9-b4ab-df2aab22a149")
285+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f8dac632-b879-42f9-b4ab-df2aab22a149")
286286
$newAssignment = New-AzureRmRoleAssignment `
287287
-SignInName $users[0].UserPrincipalName `
288288
-RoleDefinitionName $definitionName `
@@ -293,8 +293,8 @@ function Test-RaByUpn
293293

294294
# Assert
295295
Assert-NotNull $newAssignment
296-
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297-
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
296+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
298298

299299
VerifyRoleAssignmentDeleted $newAssignment
300300
}
@@ -305,11 +305,11 @@ function Test-RaUserPermissions
305305
param([string]$rgName, [string]$action)
306306
# Test
307307
$rg = Get-AzureRmResourceGroup
308-
$errorMsg = "User should have access to only 1 RG. Found: {0}" -f $rg.Count
309-
Assert-AreEqual 1 $rg.Count $errorMsg
308+
$errorMsg = "User should have access to only 1 RG. Found: {0}" -f $rg.Count
309+
Assert-AreEqual 1 $rg.Count $errorMsg
310310

311-
# User should not be able to create another RG as he doesnt have access to the subscription.
312-
Assert-Throws{ New-AzureRmResourceGroup -Name 'NewGroupFromTest' -Location 'WestUS'}
311+
# User should not be able to create another RG as he doesnt have access to the subscription.
312+
Assert-Throws{ New-AzureRmResourceGroup -Name 'NewGroupFromTest' -Location 'WestUS'}
313313
}
314314

315315
<#
@@ -430,6 +430,42 @@ function Test-RaPropertiesValidation
430430
VerifyRoleAssignmentDeleted $newAssignment
431431
}
432432

433+
<#
434+
.SYNOPSIS
435+
Tests verifies creation and retrieval of a RoleAssignments using delegation flag
436+
#>
437+
function Test-RaDelegation
438+
{
439+
# Setup
440+
$definitionName = 'Reader'
441+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
442+
$subscription = Get-AzureRmSubscription
443+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
444+
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
445+
$assignmentScope = $scope +"/"
446+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
447+
448+
# Test
449+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
450+
$newAssignment = New-AzureRmRoleAssignment `
451+
-ObjectId $users[0].Id.Guid `
452+
-RoleDefinitionName $definitionName `
453+
-Scope $assignmentScope `
454+
-AllowDelegation
455+
456+
# Assert
457+
Assert-NotNull $newAssignment
458+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
459+
Assert-AreEqual $scope $newAssignment.Scope
460+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
461+
Assert-AreEqual $true $newAssignment.CanDelegate
462+
463+
# cleanup
464+
DeleteRoleAssignment $newAssignment
465+
466+
VerifyRoleAssignmentDeleted $newAssignment
467+
}
468+
433469
<#
434470
.SYNOPSIS
435471
Tests verifies get of RoleAssignment by Scope

0 commit comments

Comments
 (0)