Skip to content

Commit ee61f8f

Browse files
authored
Merge pull request #26612 from SebastianClaesson/patch-1
Adding examples for constrained role delegation
2 parents 551bb4f + 9822b3b commit ee61f8f

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/Resources/Resources/help/New-AzRoleAssignment.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,82 @@ New-AzRoleAssignment -RoleDefinitionName "Reader" -ApplicationId $servicePrincip
178178

179179
Grant reader access to a service principal
180180

181+
### Example 6
182+
```powershell
183+
$Condition = '(
184+
(
185+
!(ActionMatches{''Microsoft.Authorization/roleAssignments/write''})
186+
)
187+
OR
188+
(
189+
@Request[Microsoft.Authorization/roleAssignments:PrincipalType] StringEqualsIgnoreCase ''ServicePrincipal''
190+
)
191+
)
192+
AND
193+
(
194+
(
195+
!(ActionMatches{''Microsoft.Authorization/roleAssignments/delete''})
196+
)
197+
OR
198+
(
199+
@Resource[Microsoft.Authorization/roleAssignments:PrincipalType] StringEqualsIgnoreCase ''ServicePrincipal''
200+
)
201+
)'
202+
203+
$DelegationParams = @{
204+
AllowDelegation = $true
205+
Condition = $Condition
206+
Scope = "/subscriptions/11112222-bbbb-3333-cccc-4444dddd5555"
207+
RoleDefinitionName = 'User Access Administrator'
208+
ObjectId = "00001111-aaaa-2222-bbbb-3333cccc4444"
209+
}
210+
211+
New-AzRoleAssignment @DelegationParams
212+
```
213+
214+
Grant User Access Administrator over an azure subscription with constrained delegation.<br>
215+
The constrained delegation will only allow that the delegated user/service principal/group may only create/delete/update new role assignments for a service principal and any roles.
216+
217+
### Example 7
218+
```powershell
219+
$Condition = '(
220+
(
221+
!(ActionMatches{''Microsoft.Authorization/roleAssignments/write''})
222+
)
223+
OR
224+
(
225+
@Request[Microsoft.Authorization/roleAssignments:PrincipalType] StringEqualsIgnoreCase ''ServicePrincipal''
226+
AND
227+
NOT @Request[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAnyValues:GuidEquals {8e3af657-a8ff-443c-a75c-2fe8c4bcb635,18d7d88d-d35e-4fb5-a5c3-7773c20a72d9}
228+
)
229+
)
230+
AND
231+
(
232+
(
233+
!(ActionMatches{''Microsoft.Authorization/roleAssignments/delete''})
234+
)
235+
OR
236+
(
237+
@Resource[Microsoft.Authorization/roleAssignments:PrincipalType] StringEqualsIgnoreCase ''ServicePrincipal''
238+
AND
239+
NOT @Resource[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAnyValues:GuidEquals {8e3af657-a8ff-443c-a75c-2fe8c4bcb635,18d7d88d-d35e-4fb5-a5c3-7773c20a72d9}
240+
)
241+
)'
242+
243+
$DelegationParams = @{
244+
AllowDelegation = $true
245+
Condition = $Condition
246+
Scope = "/subscriptions/11112222-bbbb-3333-cccc-4444dddd5555"
247+
RoleDefinitionName = 'User Access Administrator'
248+
ObjectId = "00001111-aaaa-2222-bbbb-3333cccc4444"
249+
}
250+
251+
New-AzRoleAssignment @DelegationParams
252+
```
253+
254+
Grant User Access Administrator over an azure subscription with constrained delegation.<br>
255+
The constrained delegation will only allow that the delegated user/service principal/group may only create/delete/update new role assignments for a service principal, excluding the [Owner](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/privileged#owner) and [User Access Administrator](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/privileged#user-access-administrator) role.
256+
181257
## PARAMETERS
182258

183259
### -AllowDelegation
@@ -491,7 +567,8 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
491567
### Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleAssignment
492568
493569
## NOTES
494-
Keywords: azure, azurerm, arm, resource, management, manager, resource, group, template, deployment
570+
Learn more about role assignment delegation - https://learn.microsoft.com/en-us/azure/role-based-access-control/delegate-role-assignments-portal?tabs=template
571+
<br>Keywords: azure, azurerm, arm, resource, management, manager, resource, group, template, deployment
495572
496573
## RELATED LINKS
497574

tools/StaticAnalysis/Exceptions/Az.Resources/ExampleIssues.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@
212212
"Az.Resources","New-AzPolicySetDefinition","3","3","Invalid_Cmdlet","5000","1",": is not a valid command name.",": '/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498', 'groupNames': [ 'group1' ]","Check the spell of :."
213213
"Az.Resources","New-AzPolicySetDefinition","3","7","Invalid_Cmdlet","5000","1",": is not a valid command name.",": '/providers/Microsoft.Authorization/policyDefinitions/464dbb85-3d5f-4a1d-bb09-95a9b5dd19cf', 'groupNames': [ 'group2' ]","Check the spell of :."
214214
"Az.Resources","New-AzRoleAssignment","5","2","Mismatched_Parameter_Value_Type","5111","2","New-AzRoleAssignment -ApplicationId $servicePrincipal.ApplicationId is not an expected parameter value type.","-ApplicationId","Use correct parameter value type. Expected Type is string. Now the type is .(Command)."
215+
"Az.Resources","New-AzRoleAssignment","1","1","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment -ResourceGroupName rg1 -SignInName [email protected] -RoleDefinitionName Reader -AllowDelegation","Check the spell of New-AzRoleAssignment."
216+
"Az.Resources","New-AzRoleAssignment","3","1","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment -SignInName [email protected] -RoleDefinitionName Owner -Scope '/subscriptions/00001111-aaaa-2222-bbbb-3333cccc4444/resourcegroups/rg1/providers/Microsoft.Web/sites/site1'","Check the spell of New-AzRoleAssignment."
217+
"Az.Resources","New-AzRoleAssignment","4","1","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment -ObjectId 00001111-aaaa-2222-bbbb-3333cccc4444 -RoleDefinitionName 'Virtual Machine Contributor' -ResourceName Devices-Engineering-ProjectRND -ResourceType Microsoft.Network/virtualNetworks/subnets -ParentResource virtualNetworks/VNET-EASTUS-01 -ResourceGroupName Network","Check the spell of New-AzRoleAssignment."
218+
"Az.Resources","New-AzRoleAssignment","5","1","Invalid_Cmdlet","5000","1","New-AzADServicePrincipal is not a valid command name.","New-AzADServicePrincipal -DisplayName 'testServiceprincipal'","Check the spell of New-AzADServicePrincipal."
219+
"Az.Resources","New-AzRoleAssignment","5","2","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment -RoleDefinitionName 'Reader' -ApplicationId $servicePrincipal.ApplicationId","Check the spell of New-AzRoleAssignment."
220+
"Az.Resources","New-AzRoleAssignment","6","29","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment @DelegationParams","Check the spell of New-AzRoleAssignment."
221+
"Az.Resources","New-AzRoleAssignment","7","33","Invalid_Cmdlet","5000","1","New-AzRoleAssignment is not a valid command name.","New-AzRoleAssignment @DelegationParams","Check the spell of New-AzRoleAssignment."
215222
"Az.Resources","Remove-AzADAppCredential","1","1","Unassigned_Variable","5110","2","Remove-AzADAppCredential -DisplayName $name is a null-valued parameter value.","-DisplayName","Assign value for $name."
216223
"Az.Resources","Remove-AzADAppCredential","1","1","Unassigned_Variable","5110","2","Remove-AzADAppCredential -KeyId $keyid is a null-valued parameter value.","-KeyId","Assign value for $keyid."
217224
"Az.Resources","Remove-AzADAppCredential","2","1","Unassigned_Variable","5110","2","Get-AzADApplication -DisplayName $name is a null-valued parameter value.","-DisplayName","Assign value for $name."

0 commit comments

Comments
 (0)