Custom roles in Azure

If the built-in roles don't meet the specific needs of your organization, you can create your own custom roles. Just like built-in roles, you can assign custom roles to users, groups, and service principals at subscription, resource group, and resource scopes. Custom roles are stored in an Azure Active Directory (Azure AD) tenant and can be shared across subscriptions. Each tenant can have up to 2000 custom roles. Custom roles can be created using Azure PowerShell, Azure CLI, or the REST API.

Custom role example

The following shows what a custom role looks like as displayed in JSON format. This custom role can be used for monitoring and restarting virtual machines.

{
  "Name":  "Virtual Machine Operator",
  "Id":  "88888888-8888-8888-8888-888888888888",
  "IsCustom":  true,
  "Description":  "Can monitor and restart virtual machines.",
  "Actions":  [
                  "Microsoft.Storage/*/read",
                  "Microsoft.Network/*/read",
                  "Microsoft.Compute/*/read",
                  "Microsoft.Compute/virtualMachines/start/action",
                  "Microsoft.Compute/virtualMachines/restart/action",
                  "Microsoft.Authorization/*/read",
                  "Microsoft.Resources/subscriptions/resourceGroups/read",
                  "Microsoft.Insights/alertRules/*",
                  "Microsoft.Insights/diagnosticSettings/*",
                  "Microsoft.Support/*"
  ],
  "NotActions":  [

                 ],
  "DataActions":  [

                  ],
  "NotDataActions":  [

                     ],
  "AssignableScopes":  [
                           "/subscriptions/{subscriptionId1}",
                           "/subscriptions/{subscriptionId2}",
                           "/subscriptions/{subscriptionId3}"
                       ]
}

When you create a custom role, it appears in the Azure portal with an orange resource icon.

Custom role icon

Steps to create a custom role

  1. Determine the permissions you need

    When you create a custom role, you need to know the resource provider operations that are available to define your permissions. To view the list of operations, you can use the Get-AzureRMProviderOperation or az provider operation list commands. To specify the permissions for your custom role, you add the operations to the Actions or NotActions properties of the role definition. If you have data operations, you add those to the DataActions or NotDataActions properties.

  2. Create the custom role

    You can use Azure PowerShell or Azure CLI to create the custom role. Typically, you start with an existing built-in role and then modify it for your needs. Then you use the New-AzureRmRoleDefinition or az role definition create commands to create the custom role. To create a custom role, you must have the Microsoft.Authorization/roleDefinitions/write permission on all AssignableScopes, such as Owner or User Access Administrator.

  3. Test the custom role

    Once you have your custom role, you have to test it to verify that it works as you expect. If you need to make adjustments later, you can update the custom role.

For a step-by-step tutorial on how to create a custom role, see Tutorial: Create a custom role using Azure PowerShell or Tutorial: Create a custom role using Azure CLI.

Custom role properties

A custom role has the following properties.

Property Required Type Description
Name Yes String The display name of the custom role. Must be unique to your tenant. Can include letters, numbers, spaces, and special characters. Maximum number of characters is 128.
Id Yes String The unique ID of the custom role. For Azure PowerShell and Azure CLI, this ID is automatically generated when you create a new role.
IsCustom Yes String Indicates whether this is a custom role. Set to true for custom roles.
Description Yes String The description of the custom role. Can include letters, numbers, spaces, and special characters. Maximum number of characters is 1024.
Actions Yes String[] An array of strings that specifies the management operations that the role allows to be performed. For more information, see Actions.
NotActions No String[] An array of strings that specifies the management operations that are excluded from the allowed Actions. For more information, see NotActions.
DataActions No String[] An array of strings that specifies the data operations that the role allows to be performed to your data within that object. For more information, see DataActions (Preview).
NotDataActions No String[] An array of strings that specifies the data operations that are excluded from the allowed DataActions. For more information, see NotDataActions (Preview).
AssignableScopes Yes String[] An array of strings that specifies the scopes that the custom role is available for assignment. Currently cannot be set to the root scope ("/") or a management group scope. For more information, see AssignableScopes and Organize your resources with Azure management groups.

Who can create, delete, update, or view a custom role

Just like built-in roles, the AssignableScopes property specifies the scopes that the role is available for assignment. The AssignableScopes property for a custom role also controls who can create, delete, update, or view the custom role.

Task Operation Description
Create/delete a custom role Microsoft.Authorization/ roleDefinition/write Users that are granted this operation on all the AssignableScopes of the custom role can create (or delete) custom roles for use in those scopes. For example, Owners and User Access Administrators of subscriptions, resource groups, and resources.
Update a custom role Microsoft.Authorization/ roleDefinition/write Users that are granted this operation on all the AssignableScopes of the custom role can update custom roles in those scopes. For example, Owners and User Access Administrators of subscriptions, resource groups, and resources.
View a custom role Microsoft.Authorization/ roleDefinition/read Users that are granted this operation 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.

Next steps