- Article
- 8 minutes to read
Azure role-based access control (Azure RBAC) is the authorization system you use to manage access to Azure resources. To grant access, you assign roles to users, groups, service principals, or managed identities at a particular scope. This article describes how to assign roles using Azure CLI.
Prerequisites
To assign roles, you must have:
Microsoft.Authorization/roleAssignments/write
permissions, such as User Access Administrator or Owner- Bash in Azure Cloud Shell or Azure CLI
Steps to assign an Azure role
To assign a role consists of three elements: security principal, role definition, and scope.
Step 1: Determine who needs access
You can assign a role to a user, group, service principal, or managed identity. To assign a role, you might need to specify the unique ID of the object. The ID has the format: 11111111-1111-1111-1111-111111111111
. You can get the ID using the Azure portal or Azure CLI.
User
For an Azure AD user, get the user principal name, such as patlong@contoso.com or the user object ID. To get the object ID, you can use az ad user show.
az ad user show --id "{principalName}" --query "id" --output tsv
Group
For an Azure AD group, you need the group object ID. To get the object ID, you can use az ad group show or az ad group list.
az ad group show --group "{groupName}" --query "id" --output tsv
Service principal
For an Azure AD service principal (identity used by an application), you need the service principal object ID. To get the object ID, you can use az ad sp list. For a service principal, use the object ID and not the application ID.
az ad sp list --all --query "[].{displayName:displayName, id:id}" --output tsvaz ad sp list --display-name "{displayName}"
Managed identity
For a system-assigned or a user-assigned managed identity, you need the object ID. To get the object ID, you can use az ad sp list.
az ad sp list --all --filter "servicePrincipalType eq 'ManagedIdentity'"
To just list user-assigned managed identities, you can use az identity list.
az identity list
Step 2: Select the appropriate role
Permissions are grouped together into roles. You can select from a list of several Azure built-in roles or you can use your own custom roles. It's a best practice to grant access with the least privilege that is needed, so avoid assigning a broader role.
To list roles and get the unique role ID, you can use az role definition list.
az role definition list --query "[].{name:name, roleType:roleType, roleName:roleName}" --output tsv
Here's how to list the details of a particular role.
az role definition list --name "{roleName}"
For more information, see List Azure role definitions.
Step 3: Identify the needed scope
Azure provides four levels of scope: resource, resource group, subscription, and management group. It's a best practice to grant access with the least privilege that is needed, so avoid assigning a role at a broader scope. For more information about scope, see Understand scope.
Resource scope
For resource scope, you need the resource ID for the resource. You can find the resource ID by looking at the properties of the resource in the Azure portal. A resource ID has the following format.
/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}/{resourceSubType}/{resourceName}
Resource group scope
For resource group scope, you need the name of the resource group. You can find the name on the Resource groups page in the Azure portal or you can use az group list.
az group list --query "[].{name:name}" --output tsv
Subscription scope
For subscription scope, you need the subscription ID. You can find the ID on the Subscriptions page in the Azure portal or you can use az account list.
az account list --query "[].{name:name, id:id}" --output tsv
Management group scope
For management group scope, you need the management group name. You can find the name on the Management groups page in the Azure portal or you can use az account management-group list.
az account management-group list --query "[].{name:name, id:id}" --output tsv
Step 4: Assign role
To assign a role, use the az role assignment create command. Depending on the scope, the command typically has one of the following formats.
Resource scope
az role assignment create --assignee "{assignee}" \--role "{roleNameOrId}" \--scope "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{providerName}/{resourceType}/{resourceSubType}/{resourceName}"
Resource group scope
az role assignment create --assignee "{assignee}" \--role "{roleNameOrId}" \--resource-group "{resourceGroupName}"
Subscription scope
az role assignment create --assignee "{assignee}" \--role "{roleNameOrId}" \--subscription "{subscriptionNameOrId}"
Management group scope
az role assignment create --assignee "{assignee}" \--role "{roleNameOrId}" \--scope "/providers/Microsoft.Management/managementGroups/{managementGroupName}"
The following shows an example of the output when you assign the Virtual Machine Contributor role to a user at a resource group scope.
{ "canDelegate": null, "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/roleAssignments/{roleAssignmentId}", "name": "{roleAssignmentId}", "principalId": "{principalId}", "principalType": "User", "resourceGroup": "{resourceGroupName}", "roleDefinitionId": "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c", "scope": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}", "type": "Microsoft.Authorization/roleAssignments"}
Assign role examples
Assign a role for all blob containers in a storage account resource scope
Assigns the Storage Blob Data Contributor role to a service principal with object ID 55555555-5555-5555-5555-555555555555 at a resource scope for a storage account named storage12345.
az role assignment create --assignee "55555555-5555-5555-5555-555555555555" \--role "Storage Blob Data Contributor" \--scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Example-Storage-rg/providers/Microsoft.Storage/storageAccounts/storage12345"
Assign a role for a specific blob container resource scope
Assigns the Storage Blob Data Contributor role to a service principal with object ID 55555555-5555-5555-5555-555555555555 at a resource scope for a blob container named blob-container-01.
az role assignment create --assignee "55555555-5555-5555-5555-555555555555" \--role "Storage Blob Data Contributor" \--scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Example-Storage-rg/providers/Microsoft.Storage/storageAccounts/storage12345/blobServices/default/containers/blob-container-01"
Assign a role for a group in a specific virtual network resource scope
Assigns the Virtual Machine Contributor role to the Ann Mack Team group with ID 22222222-2222-2222-2222-222222222222 at a resource scope for a virtual network named pharma-sales-project-network.
az role assignment create --assignee "22222222-2222-2222-2222-222222222222" \--role "Virtual Machine Contributor" \--scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/pharma-sales/providers/Microsoft.Network/virtualNetworks/pharma-sales-project-network"
Assign a role for a user at a resource group scope
Assigns the Virtual Machine Contributor role to patlong@contoso.com user at the pharma-sales resource group scope.
az role assignment create --assignee "patlong@contoso.com" \--role "Virtual Machine Contributor" \--resource-group "pharma-sales"
Assign a role for a user using the unique role ID at a resource group scope
There are a couple of times when a role name might change, for example:
- You are using your own custom role and you decide to change the name.
- You are using a preview role that has (Preview) in the name. When the role is released, the role is renamed.
Even if a role is renamed, the role ID does not change. If you are using scripts or automation to create your role assignments, it's a best practice to use the unique role ID instead of the role name. Therefore, if a role is renamed, your scripts are more likely to work.
The following example assigns the Virtual Machine Contributor role to the patlong@contoso.com user at the pharma-sales resource group scope.
az role assignment create --assignee "patlong@contoso.com" \--role "9980e02c-c2be-4d73-94e8-173b1dc7cf3c" \--resource-group "pharma-sales"
Assign a role for all blob containers at a resource group scope
Assigns the Storage Blob Data Contributor role to a service principal with object ID 55555555-5555-5555-5555-555555555555 at the Example-Storage-rg resource group scope.
az role assignment create --assignee "55555555-5555-5555-5555-555555555555" \--role "Storage Blob Data Contributor" \--resource-group "Example-Storage-rg"
Alternately, you can specify the fully qualified resource group with the --scope
parameter:
az role assignment create --assignee "55555555-5555-5555-5555-555555555555" \--role "Storage Blob Data Contributor" \--scope "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Example-Storage-rg"
Assign a role for an application at a resource group scope
Assigns the Virtual Machine Contributor role to an application with service principal object ID 44444444-4444-4444-4444-444444444444 at the pharma-sales resource group scope.
az role assignment create --assignee "44444444-4444-4444-4444-444444444444" \--role "Virtual Machine Contributor" \--resource-group "pharma-sales"
Assign a role for a new service principal at a resource group scope
If you create a new service principal and immediately try to assign a role to that service principal, that role assignment can fail in some cases. For example, if you use a script to create a new managed identity and then try to assign a role to that service principal, the role assignment might fail. The reason for this failure is likely a replication delay. The service principal is created in one region; however, the role assignment might occur in a different region that hasn't replicated the service principal yet. To address this scenario, you should specify the principal type when creating the role assignment.
To assign a role, use az role assignment create, specify a value for --assignee-object-id
, and then set --assignee-principal-type
to ServicePrincipal
.
az role assignment create --assignee-object-id "{assigneeObjectId}" \--assignee-principal-type "{assigneePrincipalType}" \--role "{roleNameOrId}" \--resource-group "{resourceGroupName}" \--scope "/subscriptions/{subscriptionId}"
The following example assigns the Virtual Machine Contributor role to the msi-test managed identity at the pharma-sales resource group scope:
az role assignment create --assignee-object-id "33333333-3333-3333-3333-333333333333" \--assignee-principal-type "ServicePrincipal" \--role "Virtual Machine Contributor" \--resource-group "pharma-sales"
Assign a role for a user at a subscription scope
Assigns the Reader role to the annm@example.com user at a subscription scope.
az role assignment create --assignee "annm@example.com" \--role "Reader" \--subscription "00000000-0000-0000-0000-000000000000"
Assign a role for a group at a subscription scope
Assigns the Reader role to the Ann Mack Team group with ID 22222222-2222-2222-2222-222222222222 at a subscription scope.
az role assignment create --assignee "22222222-2222-2222-2222-222222222222" \--role "Reader" \--subscription "00000000-0000-0000-0000-000000000000"
Assign a role for all blob containers at a subscription scope
Assigns the Storage Blob Data Reader role to the alain@example.com user at a subscription scope.
az role assignment create --assignee "alain@example.com" \--role "Storage Blob Data Reader" \--scope "/subscriptions/00000000-0000-0000-0000-000000000000"
Assign a role for a user at a management group scope
Assigns the Billing Reader role to the alain@example.com user at a management group scope.
az role assignment create --assignee "alain@example.com" \--role "Billing Reader" \--scope "/providers/Microsoft.Management/managementGroups/marketing-group"
Next steps
- List Azure role assignments using Azure CLI
- Use the Azure CLI to manage Azure resources and resource groups
FAQs
How do I assign an Azure RBAC role? ›
- In the list of Resource groups, open the new example-group resource group.
- In the navigation menu, click Access control (IAM).
- Click the Role assignments tab to see the current list of role assignments.
- Click Add > Add role assignment.
To list all role assignments at a subscription scope, use az role assignment list.
How can custom RBAC roles be assigned? ›You can create custom roles using Azure portal, Azure PowerShell, Azure CLI, or the REST API. Create the custom role. The easiest way is to use the Azure portal. For steps on how to create a custom role using the Azure portal, see Create or update Azure custom roles using the Azure portal.
What's the main difference between Azure RBAC roles and Azure AD roles? ›While RBAC roles are used to manage access to Azure resources like VMs and storage accounts, Azure AD Administrator roles are used to manage Azure AD resources in a directory.
Which Azure CLI command is used to assign RBAC roles? ›To assign a role, use az role assignment create, specify a value for --assignee-object-id , and then set --assignee-principal-type to ServicePrincipal .
How can you implement role based access control RBAC )? ›- Inventory your systems. Figure out what resources you have for which you need to control access, if you don't already have them listed. ...
- Analyze your workforce and create roles. ...
- Assign people to roles. ...
- Never make one-off changes. ...
- Audit.
The Role-Based CLI Access feature allows the network administrator to define “views,” which are a set of operational commands and configuration capabilities that provide selective or partial access to EXEC and configuration mode commands.
How do I check my RBAC roles in Azure? ›- In the Azure portal, click All services and then select any scope. ...
- Click the specific resource.
- Click Access control (IAM).
- Click the Roles tab to see a list of all the built-in and custom roles.
The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It allows the execution of commands through a terminal using interactive command-line prompts or a script.
How do you assign user roles? ›- In the Service Manager console, click Administration.
- In the Administration pane, expand Security, and then select User Roles.
- In the User Roles pane, double-click Advanced Operators.
- In the Edit User Role dialog box, click Users.
- On the Users page, click Add.
Can a user have multiple roles in RBAC? ›
A User can have multiple Roles. A Group can have multiple Roles. A role can be assigned to multiple Users or Groups.
What are the three types of roles in Microsoft Azure? ›Account Administrator, Service Administrator, and Co-Administrator are the three classic subscription administrator roles in Azure.
Which CLI command can we use to create a custom RBAC role from a JSON file? ›To create a custom role, use az role definition create. The role definition can be a JSON description or a path to a file containing a JSON description.
Which Azure CLI command is used to deploy an arm template? ›To deploy a local template, use the --template-file parameter in the deployment command.
Which WP CLI command manage user role? ›wp role <command>
Manages user roles, including creating new roles and resetting to defaults. See references for Roles and Capabilities and WP User class.
Rule-based access controls are preventative – they don't determine access levels for employees. Instead, they work to prevent unauthorized access. Role-based models are proactive – they provide employees with a set of circumstances in which they can gain authorized access.
What RBAC role do you need to assign to give administrator access to an Azure subscription? ›To make a user an administrator of an Azure subscription, assign them the Owner role at the subscription scope. The Owner role gives the user full access to all resources in the subscription, including the permission to grant access to others.
Is RBAC rule based or role based? ›Rule Based Access Control (RBAC) allows system owners to personalise the type of access a user has based on their role within an organisation. Users can be grouped into roles based on their responsibilities within an organisation as this generally determines their system access needs.
What capability does the CLI role provide to a user? ›The access manager can define as many users in the system and give them the CLI role. These users have access to the CLI and all activities of their CLI sessions are associated with this user. A user with only the cli role does not have access to any features in the user interface.
What is the role of CLI? ›A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.
Which three types of views are available when configuring the role based CLI access feature? ›
There are 4 types of views: CLI view, root view, super view and lawful intercept view.
How do you check if RBAC is enabled? ›You can check this by executing the command kubectl api-versions ; if RBAC is enabled you should see the API version . rbac.authorization.k8s.io/v1 .
How do I get role assignments in Azure Powershell? ›To list all role assignments at a management group scope, use Get-AzRoleAssignment. To get the management group ID, you can find it on the Management groups blade in the Azure portal or you can use Get-AzManagementGroup.
How do I check my RBAC permissions? ›The first method to find out your current RBAC permissions is using Azure Portal. Click on the user icon located on the upper left corner, and then click on My permissions. A new blade will show up with a drop-down menu with the Subscriptions.
How do I use Azure CLI effectively? ›- az.
- az account.
- JMESPath query command results with Azure CLI.
- Output formats - Azure CLI.
- Sign in with Azure CLI — Login and Authentication. ...
- Azure CLI configuration options. ...
- az config.
- az account subscription.
- ls - List directory contents. ls -a - List all the content, including hidden files. ls -l - List the content and its information.
- cd foldername – Change the working directory to foldername. cd - Return to $HOME directory. ...
- cat file – Print contents of file on the screen. less file - View and paginate file.
Azure CLI has an installer that makes its commands executable in all four shell environments. Azure PowerShell is set of cmdlets packaged as a PowerShell module named Az ; not an executable. Windows PowerShell or PowerShell must be used to install the Az module.
How do I assign a role to multiple users? ›You can actually add multiple users to a role using transaction SU01. From SU01, use the menu Environment->Mass Changes. Here you can manually add the users, select them by address or authorisation data. Once you have your user list, you can then add or remove roles and/or profiles.
What are 2 ways to define a user's role? ›1. The name for a class of product users. 2. One of the key elements of a user story that defines the recipient of the value delivered by a user story.
How many RBAC roles does Azure have? ›In Azure, you can specify a scope at four levels: management group, subscription, resource group, or resource.
What is the highest scope where you can assign roles for RBAC? ›
You can have up to 4000 role assignments in each subscription. This limit includes role assignments at the subscription, resource group, and resource scopes. You can have up to 500 role assignments in each management group. For more information, see Troubleshoot Azure RBAC.
What is the difference between user based access and role based access? ›For most business applications, RBAC is superior to ACL in terms of security and administrative overhead. ACL is better suited for implementing security at the individual user level and for low-level data, while RBAC better serves a company-wide security system with an overseeing administrator.
Who can assign roles in Azure? ›To assign Azure roles, you must have: Microsoft. Authorization/roleAssignments/write permissions, such as User Access Administrator or Owner.
What is the difference between Azure IAM and RBAC? ›Azure role-based access control (Azure RBAC) is the authorization system you use to manage access to Azure resources. Access control (IAM) is the page that you typically use to assign roles to grant access to Azure resources.
What is the difference between RBAC and IAM in Azure? ›Save this answer. Show activity on this post. Azure AD is for Authentiction - User must prove who they are using a Username and Password IAM (RBAC) is for Authorization - a User is assigned a role or permissions to use a specific resource.
What is the difference between RBAC roles and Azure AD roles? ›While RBAC roles are used to manage access to Azure resources like VMs and storage accounts, Azure AD Administrator roles are used to manage Azure AD resources in a directory.
How do I create a role based access control in Azure? ›- Sign in to the Azure portal or Azure AD admin center.
- Select Azure Active Directory > Roles and administrators > New custom role.
- On the Basics tab, provide a name and description for the role and then click Next.
Just like built-in roles, you can assign custom roles to users, groups, and service principals at management group (in preview only), subscription, and resource group scopes. Custom roles can be shared between subscriptions that trust the same Azure AD tenant. There is a limit of 5,000 custom roles per tenant.
Which CLI command is used to add an RBAC role assignment? ›To assign a role, use the az role assignment create command.
What are the different types of admin roles in RBAC? ›- Owner – full access to all Azure resources.
- Contributor – create and manage all types of resources in Azure.
- Reader – a user with this role can only view Azure resources.
- User Access Administrator – it has permissions to manage user access to all types of resources.
What is the difference between Azure RBAC and policy? ›
Policy is focused on the properties of resources. RBAC focuses on what resources the users can access. You specify a set of rules to prevent over-provisioning of resources. You grant permission on what users can create.
Where should you click to add RBAC role assignments? ›- Click Access control (IAM). ...
- Click the Role assignments tab to view the role assignments at this scope.
- Click Add > Add role assignment.
To assign roles, you must be signed in with a user that is assigned a role that has role assignments write permission, such as Owner or User Access Administrator at the scope you are trying to assign the role. Similarly, to remove a role assignment, you must have the role assignments delete permission.
How do I assign a user access administrator to Azure? ›- Step 1: Open the subscription. Sign in to the Azure portal. ...
- Step 2: Open the Add role assignment page. Access control (IAM) is the page that you typically use to assign roles to grant access to Azure resources. ...
- Step 3: Select the Owner role. ...
- Step 4: Select who needs access. ...
- Step 5: Assign role.
Role-based access control (RBAC) refers to the idea of assigning permissions to users based on their role within an organization. It offers a simple, manageable approach to access management that is less prone to error than assigning permissions to users individually.
How do I set up role based access? ›- On the IPAM server, click ACCESS CONTROL in the upper navigation pane, and click Roles in the lower navigation pane. ...
- Click an existing role to view the allowed operations that are associated to the role.
With RBAC, permissions are associated with roles, and users or groups are assigned to appropriate roles. Roles are defined according to job competency, authority, and responsibility within the enterprise. Users and groups are easily reassigned from one role to another.
What are the 3 components necessary for any role-based access control RBAC assignment? ›The way you control access to resources using Azure RBAC is to assign Azure roles. This is a key concept to understand – it's how permissions are enforced. A role assignment consists of three elements: security principal, role definition, and scope.
How do I assign a role to an IAM user? ›In the AWS Management Console section, under Delegate console access, choose the IAM role name for the existing IAM role that you want to assign users to. If the role has not yet been created, see Creating a new role. On the Selected role page, under Manage users and groups for this role, choose Add.
What are the three primary rules for RBAC? ›The components of RBAC such as role-permissions, user-role and role-role relationships make it simple to perform user assignments.
Is RBAC rule based or role-based? ›
Rule Based Access Control (RBAC) allows system owners to personalise the type of access a user has based on their role within an organisation. Users can be grouped into roles based on their responsibilities within an organisation as this generally determines their system access needs.