Skip to content

Commit dcdc8f3

Browse files
authored
Merge pull request #206193 from rolyon/rolyon-rbac-custom-roles-delete
[Azure RBAC] Find role assignments to delete a custom role
2 parents 6ec0e94 + 991bcc8 commit dcdc8f3

File tree

6 files changed

+66
-48
lines changed

6 files changed

+66
-48
lines changed

articles/role-based-access-control/custom-roles-cli.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.service: role-based-access-control
1111
ms.topic: how-to
1212
ms.tgt_pltfrm: na
1313
ms.workload: identity
14-
ms.date: 06/17/2020
14+
ms.date: 07/28/2022
1515
ms.author: rolyon
1616
ms.reviewer: bagovind
1717
---
@@ -222,18 +222,20 @@ az role definition update --role-definition ~/roles/vmoperator.json
222222

223223
## Delete a custom role
224224

225-
To delete a custom role, use [az role definition delete](/cli/azure/role/definition#az-role-definition-delete). To specify the role to delete, use the role name or the role ID. To determine the role ID, use [az role definition list](/cli/azure/role/definition#az-role-definition-list).
225+
1. Remove any role assignments that use the custom role. For more information, see [Find role assignments to delete a custom role](custom-roles.md#find-role-assignments-to-delete-a-custom-role).
226226

227-
```azurecli
228-
az role definition delete --name {roleNameOrId}
229-
```
230-
231-
The following example deletes the *Virtual Machine Operator* custom role.
232-
233-
```azurecli
234-
az role definition delete --name "Virtual Machine Operator"
235-
```
227+
1. Use [az role definition delete](/cli/azure/role/definition#az-role-definition-delete) to delete the custom role. To specify the role to delete, use the role name or the role ID. To determine the role ID, use [az role definition list](/cli/azure/role/definition#az-role-definition-list).
236228

229+
```azurecli
230+
az role definition delete --name {roleNameOrId}
231+
```
232+
233+
The following example deletes the *Virtual Machine Operator* custom role.
234+
235+
```azurecli
236+
az role definition delete --name "Virtual Machine Operator"
237+
```
238+
237239
## Next steps
238240
239241
- [Tutorial: Create an Azure custom role using Azure CLI](tutorial-custom-role-cli.md)

articles/role-based-access-control/custom-roles-portal.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: karenhoran
88
ms.service: role-based-access-control
99
ms.topic: how-to
1010
ms.workload: identity
11-
ms.date: 08/27/2021
11+
ms.date: 07/28/2022
1212
ms.author: rolyon
1313
---
1414

@@ -318,9 +318,9 @@ Follow these steps to view your custom roles.
318318
319319
## Delete a custom role
320320
321-
1. As described earlier in this article, open your list of custom roles.
321+
1. Remove any role assignments that use the custom role. For more information, see [Find role assignments to delete a custom role](custom-roles.md#find-role-assignments-to-delete-a-custom-role).
322322
323-
1. Remove any role assignments that using the custom role.
323+
1. As described earlier in this article, open your list of custom roles.
324324
325325
1. Click the ellipsis (**...**) for the custom role you want to delete and then click **Delete**.
326326

articles/role-based-access-control/custom-roles-powershell.md

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.service: role-based-access-control
1111
ms.topic: how-to
1212
ms.tgt_pltfrm: na
1313
ms.workload: identity
14-
ms.date: 03/18/2020
14+
ms.date: 07/28/2022
1515
ms.author: rolyon
1616
ms.reviewer: bagovind
1717
ms.custom: devx-track-azurepowershell
@@ -365,35 +365,37 @@ Set-AzRoleDefinition -InputFile "C:\CustomRoles\customrole1.json"
365365

366366
## Delete a custom role
367367

368-
To delete a custom role, use the [Remove-AzRoleDefinition](/powershell/module/az.resources/remove-azroledefinition) command.
369-
370-
The following example removes the *Virtual Machine Operator* custom role.
371-
372-
```azurepowershell
373-
Get-AzRoleDefinition "Virtual Machine Operator"
374-
Get-AzRoleDefinition "Virtual Machine Operator" | Remove-AzRoleDefinition
375-
```
376-
377-
```Example
378-
PS C:\> Get-AzRoleDefinition "Virtual Machine Operator"
379-
380-
Name : Virtual Machine Operator
381-
Id : 88888888-8888-8888-8888-888888888888
382-
IsCustom : True
383-
Description : Can monitor and restart virtual machines.
384-
Actions : {Microsoft.Storage/*/read, Microsoft.Network/*/read, Microsoft.Compute/*/read,
385-
Microsoft.Compute/virtualMachines/start/action...}
386-
NotActions : {}
387-
AssignableScopes : {/subscriptions/00000000-0000-0000-0000-000000000000,
388-
/subscriptions/11111111-1111-1111-1111-111111111111}
389-
390-
PS C:\> Get-AzRoleDefinition "Virtual Machine Operator" | Remove-AzRoleDefinition
391-
392-
Confirm
393-
Are you sure you want to remove role definition with name 'Virtual Machine Operator'.
394-
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
395-
```
396-
368+
1. Remove any role assignments that use the custom role. For more information, see [Find role assignments to delete a custom role](custom-roles.md#find-role-assignments-to-delete-a-custom-role).
369+
370+
1. Use the [Remove-AzRoleDefinition](/powershell/module/az.resources/remove-azroledefinition) command to delete the custom role.
371+
372+
The following example removes the *Virtual Machine Operator* custom role.
373+
374+
```azurepowershell
375+
Get-AzRoleDefinition "Virtual Machine Operator"
376+
Get-AzRoleDefinition "Virtual Machine Operator" | Remove-AzRoleDefinition
377+
```
378+
379+
```Example
380+
PS C:\> Get-AzRoleDefinition "Virtual Machine Operator"
381+
382+
Name : Virtual Machine Operator
383+
Id : 88888888-8888-8888-8888-888888888888
384+
IsCustom : True
385+
Description : Can monitor and restart virtual machines.
386+
Actions : {Microsoft.Storage/*/read, Microsoft.Network/*/read, Microsoft.Compute/*/read,
387+
Microsoft.Compute/virtualMachines/start/action...}
388+
NotActions : {}
389+
AssignableScopes : {/subscriptions/00000000-0000-0000-0000-000000000000,
390+
/subscriptions/11111111-1111-1111-1111-111111111111}
391+
392+
PS C:\> Get-AzRoleDefinition "Virtual Machine Operator" | Remove-AzRoleDefinition
393+
394+
Confirm
395+
Are you sure you want to remove role definition with name 'Virtual Machine Operator'.
396+
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
397+
```
398+
397399
## Next steps
398400
399401
- [Tutorial: Create an Azure custom role using Azure PowerShell](tutorial-custom-role-powershell.md)

articles/role-based-access-control/custom-roles-rest.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ms.service: role-based-access-control
1212
ms.workload: multiple
1313
ms.tgt_pltfrm: rest-api
1414
ms.topic: how-to
15-
ms.date: 03/19/2020
15+
ms.date: 07/28/2022
1616
ms.author: rolyon
1717
ms.reviewer: bagovind
1818

@@ -314,6 +314,8 @@ To update a custom role, use the [Role Definitions - Create Or Update](/rest/api
314314
315315
To delete a custom role, use the [Role Definitions - Delete](/rest/api/authorization/roledefinitions/delete) REST API. To call this API, you must be signed in with a user that is assigned a role that has the `Microsoft.Authorization/roleDefinitions/delete` permission on all the `assignableScopes`. Of the built-in roles, only [Owner](built-in-roles.md#owner) and [User Access Administrator](built-in-roles.md#user-access-administrator) include this permission.
316316
317+
1. Remove any role assignments that use the custom role. For more information, see [Find role assignments to delete a custom role](custom-roles.md#find-role-assignments-to-delete-a-custom-role).
318+
317319
1. Use the [Role Definitions - List](/rest/api/authorization/roledefinitions/list) or [Role Definitions - Get](/rest/api/authorization/roledefinitions/get) REST API to get the GUID identifier of the custom role. For more information, see the earlier [List custom roles](#list-custom-roles) section.
318320
319321
1. Start with the following request:

articles/role-based-access-control/custom-roles.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ manager: karenhoran
77
ms.service: role-based-access-control
88
ms.topic: conceptual
99
ms.workload: identity
10-
ms.date: 06/28/2022
10+
ms.date: 07/28/2022
1111
ms.author: rolyon
1212
---
1313

@@ -190,6 +190,18 @@ Just like built-in roles, the `AssignableScopes` property specifies the scopes t
190190
| Update a custom role | `Microsoft.Authorization/ roleDefinitions/write` | Users that are granted this action on all the `AssignableScopes` of the custom role can update custom roles in those scopes. For example, [Owners](built-in-roles.md#owner) and [User Access Administrators](built-in-roles.md#user-access-administrator) of management groups, subscriptions, and resource groups. |
191191
| View a custom role | `Microsoft.Authorization/ roleDefinitions/read` | Users that are granted this action at a scope can view the custom roles that are available for assignment at that scope. All built-in roles allow custom roles to be available for assignment. |
192192

193+
## Find role assignments to delete a custom role
194+
195+
Before you can delete a custom role, you must remove any role assignments that use the custom role. If you try to delete a custom role with role assignments, you get the message: `There are existing role assignments referencing role (code: RoleDefinitionHasAssignments)`.
196+
197+
Here are steps to help find the role assignments before deleting a custom role:
198+
199+
- List the [custom role definition](role-definitions-list.md).
200+
- In the [assignable scopes](role-definitions.md#assignablescopes) section, get the management groups, subscriptions, and resource groups.
201+
- Iterate over the assignable scopes and [list the role assignments](role-assignments-list-portal.md).
202+
- [Remove the role assignments](role-assignments-remove.md) that use the custom role.
203+
- [Delete the custom role](custom-roles-portal.md#delete-a-custom-role).
204+
193205
## Custom role limits
194206

195207
The following list describes the limits for custom roles.

articles/role-based-access-control/troubleshooting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: role-based-access-control
99
ms.workload: identity
1010
ms.tgt_pltfrm: na
1111
ms.topic: troubleshooting
12-
ms.date: 07/27/2022
12+
ms.date: 07/28/2022
1313
ms.author: rolyon
1414
ms.custom: seohack1, devx-track-azurecli, devx-track-azurepowershell
1515
---
@@ -277,7 +277,7 @@ There are role assignments still using the custom role.
277277

278278
**Solution**
279279

280-
Remove those role assignments and try to delete the custom role again.
280+
Remove the role assignments that use the custom role and try to delete the custom role again. For more information, see [Find role assignments to delete a custom role](custom-roles.md#find-role-assignments-to-delete-a-custom-role).
281281

282282
### Symptom - Unable to add more than one management group as assignable scope
283283

0 commit comments

Comments
 (0)