Skip to content

Commit b9a9854

Browse files
Adding examples for constrained role delegation
Adding examples to showcase how constrained role delegation can be done with PowerShell.
1 parent 814b8b8 commit b9a9854

File tree

1 file changed

+78
-1
lines changed

1 file changed

+78
-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, b24988ac-6180-42a0-ab88-20f7382dd24c, 76cc9ee4-d5d3-4a45-a930-26add3d73475, 011d09a5-6c21-45a9-ab4d-b63d126504c7, e496a383-f933-4d51-9c43-45700124193f, e6001d50-2bb0-482e-87b3-9a20725bda43, 37bec740-8b2e-4938-891e-e26ec9617a4c, 16e9e0dd-a932-4453-9577-db71fb5d6b23, f58310d9-a9f6-439a-9e8d-f62e7b41a168, 18d7d88d-d35e-4fb5-a5c3-7773c20a72d9, a8889054-8d42-49c9-bc1c-52486c10e7cd, 32e6a4ec-6095-4e37-b54b-12aa350ba81f}
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, b24988ac-6180-42a0-ab88-20f7382dd24c, 76cc9ee4-d5d3-4a45-a930-26add3d73475, 011d09a5-6c21-45a9-ab4d-b63d126504c7, e496a383-f933-4d51-9c43-45700124193f, e6001d50-2bb0-482e-87b3-9a20725bda43, 37bec740-8b2e-4938-891e-e26ec9617a4c, 16e9e0dd-a932-4453-9577-db71fb5d6b23, a8889054-8d42-49c9-bc1c-52486c10e7cd, f58310d9-a9f6-439a-9e8d-f62e7b41a168, 32e6a4ec-6095-4e37-b54b-12aa350ba81f, 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 and non-privileged roles.
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

0 commit comments

Comments
 (0)