Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

role-assignments-steps.md

Latest commit, file metadata and controls.

title description author manager ms.service ms.topic ms.date ms.author

Steps to assign an Azure role

[!INCLUDE Azure RBAC definition grant access ] This article describes the high-level steps to assign Azure roles using the Azure portal , Azure PowerShell , Azure CLI , or the REST API .

Step 1: Determine who needs access

You first need to determine who needs access. You can assign a role to a user, group, service principal, or managed identity. This is also called a security principal .

Security principal for a role assignment

  • User - An individual who has a profile in Microsoft Entra ID. You can also assign roles to users in other tenants. For information about users in other organizations, see Microsoft Entra B2B .
  • Group - A set of users created in Microsoft Entra ID. When you assign a role to a group, all users within that group have that role.
  • Service principal - A security identity used by applications or services to access specific Azure resources. You can think of it as a user identity (username and password or certificate) for an application.
  • Managed identity - An identity in Microsoft Entra ID that is automatically managed by Azure. You typically use managed identities when developing cloud applications to manage the credentials for authenticating to Azure services.

Step 2: Select the appropriate role

Permissions are grouped together into a role definition . It's typically just called a role . You can select from a list of several built-in roles. If the built-in roles don't meet the specific needs of your organization, you can create your own custom roles.

Role definition for a role assignment

Roles are organized into job function roles and privileged administrator roles.

Job function roles

Job function roles allow management of specific Azure resources. For example, the Virtual Machine Contributor role allows a user to create and manage virtual machines. To select the appropriate job function role, use these steps:

Begin with the comprehensive article, Azure built-in roles . The table at the top of the article is an index into the details later in the article.

In that article, navigate to the service category (such as compute, storage, and databases) for the resource to which you want to grant permissions. The easiest way to find what your looking for is typically to search the page for a relevant keyword, like "blob", "virtual machine", and so on.

Review the roles listed for the service category and identify the specific actions you need. Again, always start with the most restrictive role.

For example, if a security principal needs to read blobs in an Azure storage account, but doesn't need write access, then choose Storage Blob Data Reader rather than Storage Blob Data Contributor (and definitely not the administrator-level Storage Blob Data Owner role). You can always update the role assignments later as needed.

If you don't find a suitable role, you can create a custom role .

Privileged administrator roles

Privileged administrator roles are roles that grant privileged administrator access, such as the ability to manage Azure resources or assign roles to other users. The following roles are considered privileged and apply to all resource types.

Azure role Permissions

For best practices when using privileged administrator role assignments, see Best practices for Azure RBAC . For more information, see Privileged administrator role definition .

Step 3: Identify the needed scope

Scope is the set of resources that the access applies to. In Azure, you can specify a scope at four levels: management group , subscription, resource group , and resource. Scopes are structured in a parent-child relationship. Each level of hierarchy makes the scope more specific. You can assign roles at any of these levels of scope. The level you select determines how widely the role is applied. Lower levels inherit role permissions from higher levels.

Scope for a role assignment

When you assign a role at a parent scope, those permissions are inherited to the child scopes. For example:

  • If you assign the Reader role to a user at the management group scope, that user can read everything in all subscriptions in the management group.
  • If you assign the Billing Reader role to a group at the subscription scope, the members of that group can read billing data for every resource group and resource in the subscription.
  • If you assign the Contributor role to an application at the resource group scope, it can manage resources of all types in that resource group, but not other resource groups in the subscription.

[!INCLUDE Scope for Azure RBAC least privilege ] For more information, see Understand scope .

Step 4: Check your prerequisites

To assign roles, you must be signed in with a user that is assigned a role that has role assignments write permission, such as Role Based Access Control 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.

  • Microsoft.Authorization/roleAssignments/write
  • Microsoft.Authorization/roleAssignments/delete

If your user account doesn't have permission to assign a role within your subscription, you see an error message that your account "does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write'." In this case, contact the administrators of your subscription as they can assign the permissions on your behalf.

If you are using a service principal to assign roles, you might get the error "Insufficient privileges to complete the operation." This error is likely because Azure is attempting to look up the assignee identity in Microsoft Entra ID and the service principal cannot read Microsoft Entra ID by default. In this case, you need to grant the service principal permissions to read data in the directory. Alternatively, if you are using Azure CLI, you can create the role assignment by using the assignee object ID to skip the Microsoft Entra lookup. For more information, see Troubleshoot Azure RBAC .

Step 5: Assign role

Once you know the security principal, role, and scope, you can assign the role. You can assign roles using the Azure portal, Azure PowerShell, Azure CLI, Azure SDKs, or REST APIs.

You can have up to 4000 role assignments in each subscription. This limit includes role assignments at the subscription, resource group, and resource scopes. Eligible role assignments and role assignments scheduled in the future do not count towards this limit. You can have up to 500 role assignments in each management group. For more information, see Troubleshoot Azure RBAC limits .

Check out the following articles for detailed steps for how to assign roles.

  • Assign Azure roles using the Azure portal
  • Assign Azure roles using Azure PowerShell
  • Assign Azure roles using Azure CLI
  • Assign Azure roles using the REST API
  • Tutorial: Grant a user access to Azure resources using the Azure portal

create a role assignment

  • Adding or removing role assignments using Azure Portal

Go back to AZ-304 Tutorials

In this article you will learn about assigning roles using Azure portal and the process of adding and removing role assignments. 

However, Azure’s role-based access control (RBAC) refers to the authorization system for managing access to Azure resources. And, to grant access, you assign roles to users, groups, service principals, or managed identities at a particular scope. 

Prerequisites

For adding or removing role assignments, you must have:

  • Firstly, Microsoft.Authorization/roleAssignments/write 
  • Secondly, Microsoft.Authorization/roleAssignments/delete permissions, such as User Access Administrator or Owner

Access control (IAM)

Access control (IAM) is the page that is for assigning roles to grant access to Azure resources. It’s also known as identity and access management and appears in several locations in the Azure portal. There are questions for assigning roles to help in understanding about the Access control (IAM) page.

  • Who needs access? This refers to a user, group, service principal, or managed identity. 
  • What role do they need? Permissions are grouped together into roles, so you can select from a list of several built-in roles orcan use custom roles.
  • Where do they need access? This refers to the set of resources that the access applies to. However, “where” can be a management group, subscription, resource group, or a single resource such as a storage account.

Adding a role assignment

  • Firstly, in the Azure portal, click All services and then select the scope that you want to grant access to. 
  • Secondly, click the specific resource for that scope.
  • Then, Click Access control (IAM).
  • Fourthly, click the Role assignments tab for viewing the role assignments at this scope.
  • After that, click Add > Add role assignment. However, if you don’t have permissions to assign roles, the Add role assignment option will be disabled.

adding role assignments

  • Then, in the Role drop-down list, select a role such as Virtual Machine Contributor.
  • There in the Select list, select a user, group, service principal, or managed identity. And, if you don’t see the security principal in the list, you can type in the Select box to search the directory for display names, email addresses, and object identifiers.
  • Lastly, click Save to assign the role.

Assigning a user as an administrator of a subscription

For giving users the role of an administrator of an Azure subscription, first assign them the Owner role at the subscription scope. As the Owner role gives the user full access to all resources in the subscription, including the permission to grant access to others. However, these steps are the same as any other role assignment.

  • Firstly, in the Azure portal, click All services and then Subscriptions.
  • Then, click the subscription where you want to grant access.
  • Thirdly, click Access control (IAM).
  • After that, click the Role assignments tab to view the role assignments for this subscription.
  • Then, click Add > Add role assignment. However, if you don’t have permissions to assign roles, the Add role assignment option will be disabled.
  • And, in the Role drop-down list, select the Owner role.
  • Then, in the Select list, select a user.

AZ-304 Practice tests

Adding a role assignment for a managed identity

For adding role assignments for a managed identity use the Access control (IAM) page. However, when you use the Access control (IAM) page, you start with the scope and then select the managed identity and role. In this section, you will learn about an alternate way to add role assignments for a managed identity. Using these steps, you start with the managed identity and then select the scope and role.

System-assigned managed identity

  • Use these steps for assigning a role to a system-assigned managed identity by starting with the managed identity.
  • Firstly, in the Azure portal, open a system-assigned managed identity. Then, in the left menu, click Identity.

system assign role assignments

  • After that, under Permissions, click Azure role assignments. However, if roles are already assigned to the selected system-assigned managed identity then you will see the list of role assignments.
  • For changing the subscription, click the Subscription list. Then, click Add role assignment.
  • Then, use the drop-down lists to select the set of resources that the role assignment applies to such as Subscription, Resource group, or resource. And, if you don’t have role assignment write permissions for the selected scope, an inline message will be displayed.
  • After that, in the Role drop-down list, select a role such as Virtual Machine Contributor.

User-assigned managed identity

  • Use these steps for assigning a role to a user-assigned managed identity by starting with the managed identity.
  • Firstly, in the Azure portal, open a user-assigned managed identity. Then, in the left menu, click Identity.
  • After that, under Permissions, click Azure role assignments. However, if roles are already assigned to the selected user-assigned managed identity then you will see the list of role assignments.

user assign role assignments

Removing a role assignment

In Azure RBAC, for removing access from an Azure resource, you first remove a role assignment. Use these steps to remove a role assignment.

  • Firstly, Open Access control (IAM) at a scope, such as management group, subscription, resource group, or resource, where you want to remove access.
  • Then, click the Role assignments tab to view all the role assignments for this subscription.
  • After that, in the list of role assignments, add a checkmark next to the security principal with the role assignment you want to remove.
  • Then, Click Remove.
  • Lastly, in the remove role assignment message that appears, click Yes.

However, if you see a message that inherited role assignments cannot be removed, then you are trying to remove a role assignment at a child scope. So, you should open Access control (IAM) at the scope where the role was assigned and try again. 

AZ-304 online course

Reference: Microsoft Documentation

Prepare for Assured Success

RBAC in Azure: A Practical Guide

What is azure rbac.

Azure role-based access control (Azure RBAC) enables access management for Azure resources. It’s an authorization system built into the Azure Resource Manager. You can use Azure RBAC to define which specific users should be allowed access to Azure cloud resources and assign a set of privileges for each user group. Let’s learn more about the specifics.

Azure RBAC vs Azure ABAC

As mentioned earlier, Azure RBAC allows you to manage access to Azure resources, defining what users can do with resources and their access areas. It lets you use role definitions and role assignments to control access. However, it does not offer fine-grained access management and can be difficult when managing hundreds of role assignments.

Azure attribute-based access control (ABAC) works differently.

Azure ABAC allows you to add role assignment conditions to achieve fine-grained access control. It builds on Azure RBAC, letting you add attributes for specific actions. Each role assignment condition provides an additional, optional check to a role assignment. Once you set it up, the condition can filter down permissions provisioned as a part of the role definition and assignment. 

Azure RBAC Concepts

Azure rbac roles.

In Azure RBAC, a role definition is a set of permissions (role). It defines users’ actions, such as write, delete, and read. You can define high-level roles, such as an owner, or specific roles, such as a virtual machine (VM) reader.

create a role assignment

Azure provides various built-in roles, including a virtual machine contributor role that allows users to create and manage VMs. If the built-in roles do not satisfy your requirements, you can also define Azure custom roles. You can use data actions to grant access to data stored in a specific object. 

The term scope refers to a set of resources with specific access. It enables you to grant the relevant security principal to a certain role. Limiting the scope means limiting the scope of resources at risk if the security principal is compromised.

Azure RBAC lets you specify a scope at four levels, including a management group level, a subscription level, a resource group level, and a resource level. Azure structures scopes in a parent-child relationship, with each hierarchy level making the scope more specific. It lets you assign roles at any of the four levels. However, note that the level you choose determines how the role is applied. 

create a role assignment

Azure also lets you use management groups, a level of scope above subscriptions. However, management groups support complex hierarchies. The diagram below illustrates an example of a hierarchy of management groups and subscriptions.

Role Assignments

Role assignments enable you to attach role definitions to specific users, groups, service principals, or managed identities at a certain scope. When creating a role assignment, you grant specific access, and removing the assignment revokes this access.

Here is a diagram that illustrates an example of a role assignment: 

create a role assignment

This example assigns a contributor role to the marketing group—only for the pharma-sales resource group. It enables all users in the marketing group to create or manage Azure resources in the pharma-sales resource group. However, it does not provide marketing users with access to resources external to the pharma-sales resource group.

Azure Groups

Role assignments are transitive for groups, allowing users to gain permissions assigned to groups. If user A is a member of group B and group B is a member of group C with its own role assignment, user A gets the permissions in group C’s role assignment.

Azure RBAC uses an additive model to prevent issues when users get several overlapping role assignments. You can see an example of this principle in the image below. A certain user is granted a reader role by a resource group and a contributor role at the subscription level. The sum of the reader and contributor permissions is the contributor role. The reader role assignment has no impact.

create a role assignment

Best Practices for Azure RBAC

Only grant the access users need.

With Azure RBAC, you can create isolation between different teams, granting each team only the access they need to get the job done. 

Instead of granting unlimited permissions to everyone with an Azure subscription or resource, you can only allow specific actions within specific scopes. Avoid assigning broad roles, even if they seem more convenient at first. When you create a custom role, include only the permissions your users need. This ensures that there’s less risk if a principal account is compromised.

The following diagram shows the recommended pattern for granting permissions in Azure RBAC.

create a role assignment

Use Azure AD Privileged Identity Management

To protect privileged accounts from malicious cyberattacks, Azure Active Directory Privileged Identity Management (PIM) can be used to reduce privilege issuance time and improve visibility through reports and alerts. PIM helps protect privileged accounts by providing temporary privileged access to Azure AD and Azure resources. Access is time-limited, after which privileges are automatically revoked.

Assign Roles Using Unique Role ID Instead of the Role Name

Role names may change over time, but the role ID always stays the same. Some common examples of changes to role names is when you are using your own custom role and decide to change the name, or when you are using a preview role that has (Preview) in the name. When the role is released from preview, it is automatically renamed.

To ensure consistency over time, it is a good idea to always assign users to a role ID when assigning roles using scripting or automation. This way, scripts won’t break if the name changes in the future. 

Assign Roles to Groups and Limit Subscription Owners

To make it easier to manage role assignments, do not assign roles directly to users. Instead, assign roles to groups. Assigning roles to groups instead of users minimizes the number of role assignments. Note that Azure imposes restrictions on the total role assignments allowed per subscription.

Microsoft recommends having a maximum of 3 owners for each Azure subscription, to reduce the likelihood of a breach by a compromised or malicious insider.

Cloud RBAC with Frontegg

Frontegg provides out of the box RBAC model implementation. Customers can now create their own roles and permissions which represent their product models and use cases. Additionally, Frontegg empowers the end users to create custom roles to represent their permissions model, without having to change a single line of code in the product. Sounds too good to be true? Try it out now.  

Looking to take your User Management to the next level?

Rate this post

4.8 / 5. 1355

No reviews yet

create a role assignment

Full Solution, Easy Migration

Privacy overview.

CookieDurationDescription
_vis_opt_s3 months 8 daysVisual Website Optimizer sets this cookie to detect if there are new to or returning to a particular test.
_vis_opt_test_cookiesessionVisual Website Optimizer creates this cookie to determine whether or not cookies are enabled on the user's browser.
li_gc6 monthsLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.
lidc1 dayLinkedIn sets the lidc cookie to facilitate data center selection.
messagesUtk6 monthsHubSpot sets this cookie to recognize visitors who chat via the chatflows tool.
CookieDurationDescription
AWSALB7 daysAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.
CookieDurationDescription
_gcl_au3 monthsGoogle Tag Manager sets the cookie to experiment advertisement efficiency of websites using their services.
_hjSession_*1 hourHotjar sets this cookie to ensure data from subsequent visits to the same site is attributed to the same user ID, which persists in the Hotjar User ID, which is unique to that site.
_hjSessionUser_*1 yearHotjar sets this cookie to ensure data from subsequent visits to the same site is attributed to the same user ID, which persists in the Hotjar User ID, which is unique to that site.
_hp2_ses_props.*1 hourHeap sets this cookie to store the timestamp and cookie domain or path.
_omappvp1 year 1 month 4 daysThe _omappvp cookie is set to distinguish new and returning users and is used in conjunction with _omappvs cookie.
_omappvs20 minutesThe _omappvs cookie, used in conjunction with the _omappvp cookies, is used to determine if the visitor has visited the website before, or if it is a new visitor.
_vwo_uuid_v21 yearThis cookie is set by Visual Website Optimiser and calculates unique traffic on a website.
cb_anonymous_id1 yearClearbit sets this cookie to track page views and traits for Clearbit.
cb_group_id1 yearClearbit sets this cookie to track page views and traits for Clearbit.
CookieDurationDescription
bcookie1 yearLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.
cb_user_id1 yearClearbit sets this cookie to collect data on visitors. This information is used to assign visitors into segments, making website advertising more relevant.
CookieDurationDescription
__Host-session14 daysNo description available.
__tld__sessionDescription is currently not available.
_cfuvidsessionDescription is currently not available.
_crowdcontrol_session_keysessionDescription is currently not available.
_g2_session_idsessionDescription is currently not available.
_hp2_hld346349427843107.10650805795 minutesDescription is currently not available.
_hp2_hld6722177740337317.10650805795 minutesDescription is currently not available.
_hp2_hld8090462093010520.10650805795 minutesDescription is currently not available.
cbtest1 yearDescription is currently not available.
debugneverNo description available.
events_distinct_idsessionDescription is currently not available.
h1_device_id1 yearDescription is currently not available.
pfjscookies1 yearDescription is currently not available.

Azure RBAC: role assignments and ARM templates

John Reilly

This post is about Azure's role assignments and ARM templates. Role assignments can be thought of as "permissions for Azure".

If you're deploying to Azure, there's a good chance you're using ARM templates to do so. Once you've got past "Hello World", you'll probably find yourself in a situation when you're deploying multiple types of resource to make your solution. For instance, you may be deploying an App Service alongside Key Vault and Storage .

One of the hardest things when it comes to deploying software and having it work, is permissions. Without adequate permissions configured, the most beautiful code can do nothing . Incidentally, this is a good thing. We're deploying to the web; many people are there, not all good. As a different kind of web-head once said:

Spider-man saying with great power, comes great responsibility

Azure has great power and suggests you use it wisely .

Access management for cloud resources is critical for any organization that uses the cloud. Azure role-based access control (Azure RBAC) helps you manage who has access to Azure resources, what they can do with those resources, and what areas they have access to. Designating groups or individual roles responsible for specific functions in Azure helps avoid confusion that can lead to human and automation errors that create security risks. Restricting access based on the need to know and least privilege security principles is imperative for organizations that want to enforce security policies for data access.

This is good advice. With that in mind, how can we ensure that the different resources we're deploying to Azure can talk to one another?

Role (up for your) assignments ​

The answer is roles. There's a number of roles that exist in Azure that can be assigned to users, groups, service principals and managed identities. In our own case we're using managed identity for our resources. What we can do is use "role assignments" to give our managed identity access to given resources. Arturo Lucatero gives a great short explanation of this:

Whilst this explanation is delightfully simple, the actual implementation when it comes to ARM templates is a little more involved. Because now it's time to talk "magic" GUIDs. Consider the following truncated ARM template, which gives our managed identity (and hence our App Service which uses this identity) access to Key Vault and Storage:

Let's take a look at these three variables:

The three variables above contain the subscription resource ids for the roles Storage Blob Data Contributor , Key Vault Secrets Officer and Key Vault Crypto Officer . The first question on your mind is likely: "what is ba92f5b4-2d11-453d-a403-e96b0029c9fe and where does it come from?" Great question! Well, each of these GUIDs represents a built-in role in Azure RBAC. The ba92f5b4-2d11-453d-a403-e96b0029c9fe represents the Storage Blob Data Contributor role.

How can I look these up? Well, there's two ways; there's an article which documents them here or you could crack open the Cloud Shell and look up a role by GUID like so:

Or by name like so:

As you can see, the Actions section of the output above (and in even more detail on the linked article ) provides information about what the different roles can do. So if you're looking to enable one Azure resource to talk to another, you should be able to refer to these to identify a role that you might want to use.

Creating a role assignment ​

So now we understand how you identify the roles in question, let's take the final leap and look at assigning those roles to our managed identity. For each role assignment, you'll need a roleAssignments resource defined that looks like this:

Let's go through the above, significant property by significant property (it's also worth checking the official reference here ):

  • type - the type of role assignment we want to create, for a key vault it's "Microsoft.KeyVault/vaults/providers/roleAssignments" , for storage it's "Microsoft.Storage/storageAccounts/providers/roleAssignments" . The pattern is that it's the resource type, followed by "/providers/roleAssignments" .
  • dependsOn - before we can create a role assignment, we need the service principal we desire to permission (in our case a managed identity) to exist
  • properties.roleDefinitionId - the role that we're assigning, provided as an id. So for this example it's the keyVaultCryptoOfficer variable, which was earlier defined as [subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'ba92f5b4-2d11-453d-a403-e96b0029c9fe')] . (Note the use of the GUID)
  • properties.principalId - the id of the principal we're adding permissions for. In our case this is a managed identity (a type of service principal).
  • properties.scope - we're modifying another resource; our key vault isn't defined in this ARM template and we want to specify the resource we're granting permissions to.
  • properties.principalType - the type of principal that we're creating an assignment for; in our this is "ServicePrincipal" - our managed identity.

There is an alternate approach that you can use where the type is "Microsoft.Authorization/roleAssignments" . Whilst this also works, it displayed errors in the Azure tooling for VS Code . As such, we've opted not to use that approach in our ARM templates.

Many thanks to the awesome John McCormick who wrangled permissions with me until we bent Azure RBAC to our will.

  • Role (up for your) assignments
  • Creating a role assignment
  • Top of Page

create a role assignment

Defining RBAC Role Assignments in ARM Templates

It’s no secret I’m a big fan of Azure Resource Manager (ARM) templates. Getting started with ARM templates is hard, but well worth the effort, and make it significantly easier to have reproduceable, consistent deployments of your Azure resources.

One thing that I had been feeling left out, however, was being able to assign permissions to Azure resources during creation. Azure’s Role-based Access Control (RBAC) mechanism is a powerful way to control who can manage and access your resources, and having to do this through scripting was possible, but cumbersome at times.

A few days ago, I realized that you can actually create RBAC role assignments through ARM templates just like any other resource. This capability is not new by any means, I just had missed it before!

Creating an assignment

To create an assignment, you need the following information:

  • The ID of the role you want to assign. This is a long string that contains the subscription id and the role identifier (both GUIDs).
  • The object ID of the user/group/service principal you want to grant access to.
  • The scope at which you want to assign the role, which is going to be either a subscription, resource group, or resource id.

Here’s an example of creating such an assignment:

Here we grant the members of an Azure Active Directory group the Monitoring Contributor built-in role to the resource group the template is deployed to.

Also interesting here is that you don’t need to specify a location property in the resource.

Some gotchas

There are a couple of things to watch out for when doing this.

The first one is that to assign a role, you need the objectId of the AAD user/group/principal, rather than the name. This is cumbersome because there’s no way to resolve these within the ARM template itself, so you’ll always need to pass these as input parameters.

A more significant issue, however, is the name of the roleAssignment resource, which needs to be a unique GUID.

This is a problem if, for example, you’re assigning role permissions at the resource group or individual resource level, rather than globally at the subscription.

For example, in my case I was creating a template that would be used to deploy multiple copies of the same resources into different resource groups within the same subscription.

If the GUID that defines the role assignment name is hardcoded in the template, then each time I ran the template, the scope of the role assignment would get overwritten with the id of the last resource group it was deployed to. Clearly, this is undesirable.

What we need then, is a way to ensure that each deployment to a different resource group uses a different GUID for the role assignment, but at the same time, ensure that the same one is used when deploying to the same resource group.

Clearly, providing the assignment GUID as a parameter is an easy workaround, but very cumbersome.

A better workaround comes from the guid function! It takes one or more strings that are used to calculate a hash, very much like the uniquestring function; only this one generates a string in GUID format instead.

By using the guid function with the resource group id and some other consistent stuff as input, we can solve our problem in an elegant way:

  • Azure (41) ,
  • Security (2)

create a role assignment

Tomas Restrepo

Software developer located in Colombia.

  • ← Previous
  • Next →

avatar

Manage Azure Role Assignments Like a Pro with PowerShell

Azure Governance Future Trends and Predictions - AzureIs.Fun

Today’s blog post is a little bit different. I have a couple of examples of how you can use PowerShell snippets and simple commandlets to get or set role assignmnets in your Azure Subscriptions.

PowerShell examples for managing Azure Role assignments

List all role assignments in a subscription, get all role assignments for a specific resource group, get all role assignments for a specific user, add a role assignment to a user, remove a role assignment for a user, remove all role assignments for a specific user, list all built-in roles, list all custom roles, create a custom role, update a custom role, delete a custom role, list all users or groups assigned to a specific role, list all permissions granted by a specific role, list all resource groups that a user has access to, create a role assignment for a service principal, powershell script to manage azure role assignments.

And now there is a script that combines some of these examples into one usable function:

I hope this was useful. Let me know if you liked the format of this blog and if you want me to include more of these examples.

Vukasin Terzic

Recent Update

  • Writing your first Azure Terraform Configuration
  • Transition from ARM Templates to Terraform with AI
  • Getting started with Terraform for Azure
  • Terraform Configuration Essentials: File Types, State Management, and Provider Selection
  • Dynamically Managing Azure NSG Rules with PowerShell

Trending Tags

Retrieve azure resource group cost with powershell api.

The Future Of Azure Governance: Trends and Predictions

Further Reading

In my previous blog posts, I wrote about how simple PowerShell scripts can help speed up daily tasks for Azure administrators, and how you can convert them to your own API. One of these tasks is...

Azure Cost Optimization: 30 Ways to Save Money and Increase Efficiency

As organizations continue to migrate their applications and workloads to the cloud, managing and controlling cloud costs has become an increasingly critical issue. While Azure provides a robust s...

Custom PowerShell API for Azure Naming Policy

To continue our PowerShell API series, we have another example of a highly useful API that you can integrate into your environment. Choosing names for Azure resources can be a challenging task. ...

Daniel's Tech Blog

Cloud Computing, Cloud Native & Kubernetes

Assigning RBAC permissions with Azure Resource Manager templates

Recently, I updated my AKS ARM template supporting the latest AKS feature set and important RBAC role assignments for the AKS cluster.

After having a hard time, I managed to get the RBAC role assignment working.

When you now think what should be so complicated? Check out my tweet on Twitter getting the background information.

-> https://twitter.com/neumanndaniel/status/1294272253211947008

It is not as easy as it sounds. Just using the Microsoft.Authorization resource provider as in the ARM template reference only works on resource group level and above like subscriptions.

-> https://docs.microsoft.com/en-us/azure/templates/microsoft.authorization/roleassignments

Here starts our journey of todays blog post. I walk you through my findings and provide you with the necessary guidance doing the RBAC role assignment with ARM templates in the correct way. So, at least I can spare you some time when this topic arises.

create a role assignment

Let us start from the beginning why you can use the Microsoft.Authorization resource provider only on resource group level and above like subscriptions.

When using the RP Microsoft.Authorization we specifically using the resource type roleAssignments.

As you can deploy ARM templates only on MG (management group), subscription and RG (resource group) level, tenant level is also possible, the RP targets the resource at the deployment level. This excludes resources and their sub resources for instance a Virtual Network and its subnets.

Let us take a look at two ARM templates with an RBAC role assignment on subscription and RG level.

As seen above the template assigns a user object Network Contributor permission on the subscription level.

The Azure CLI command explicitly targets the subscription for the deployment.

Similar looks the template targeting the resource group.

Using the following ARM template assigning the Network Contributor permissions on a VNET subnet will not work.

We get an error message that the assignment scope does not match the scope of the deployment.

So, how you going to do an RBAC role assignment on a resource or sub resource?

Via a sub resource deployment. Each RP has a providers resource type roleAssignments which we can leverage in a sub resource deployment assigning the RBAC role to resources like a VNET or sub resources like a VNET subnet.

The template assumes that the target resource lives in the same RG that the deployment targets. If this is not the case, you must use a nested / linked template where you can specify the resource group.

One important part in the RBAC role assignment via sub resource deployments plays the dependency between the name and the type.

The segment length must be the same.

Not the name defines the segment length it is the type and the /providers/ does not count towards the length.

From the given example someone might think the segment length is five, but as I mentioned that /providers/ does not count the actual segment length is four.

Looking at the name this is true for our name.

I hope you got some useful insights into RBAC role assignments via Azure Resource Manager templates that can spare you some time in the foreseeable future.

create a role assignment

  • Español – América Latina
  • Português – Brasil
  • GKE Enterprise
  • Documentation
  • GKE on Azure

Create Azure role assignments

This page shows how you grant permissions to GKE on Azure so that it can access Azure APIs. You need to perform these steps when setting up a new GKE on Azure cluster or when updating permissions for an existing cluster. These permissions are necessary for GKE on Azure to manage Azure resources on your behalf, such as virtual machines, networking components, and storage.

Obtain service principal and subscription IDs

To grant permissions to GKE on Azure, you need to obtain your Azure service principal and subscription ID. The Azure service principal and subscription ID are associated with the Azure AD application you created for GKE on Azure. For details, see Create an Azure Active Directory application .

A service principal is an identity in Azure Active Directory (AD) that is used to authenticate to Azure and access its resources. An Azure subscription is a logical container that provides you with authorized access to Azure products and services. A subscription ID is a unique identifier associated with your Azure subscription.

To save your service principal and subscription IDs for quick reference, you can store them in shell variables. To create these shell variables, run the following command:

Replace APPLICATION_NAME with the name of your Azure AD application.

Create three custom roles

To grant GKE on Azure the permissions to manage your Azure resources, you need to create three custom roles and assign them to the service principal. Only the minimum permissions are added in the following instructions. You can add more permissions if you need to.

You need to create custom roles for the following types of access:

  • Subscription-level access : Permissions that apply to the entire Azure subscription, allowing management of all Azure resources within that subscription.
  • Cluster resource group-level access : Permissions specific to managing Azure resources within a particular resource group that contains your GKE on Azure clusters.
  • Virtual network resource group-level access : Permissions specific to managing Azure resources within a resource group that contains your Azure virtual network resources.

Create role for subscription-level access

Create a file named GKEOnAzureAPISubscriptionScopedRole.json .

Open GKEOnAzureAPISubscriptionScopedRole.json in an editor and add the following permissions:

Create the new custom role:

Assign the role to the service principal using the following command:

Create role for cluster resource group-level access

Create a file named GKEOnAzureClusterResourceGroupScopedRole.json .

Open GKEOnAzureClusterResourceGroupScopedRole.json in an editor and add the following permissions:

Create role for virtual network resource group-level access

Create a file named GKEOnAzureAPIVNetResourceGroupScopedRole.json .

Open GKEOnAzureAPIVNetResourceGroupScopedRole.json in an editor and add the following permissions:

What's next

  • Create a client certificate

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-05 UTC.

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Role Assignments - Create

Create or update a role assignment by scope and name.

URI Parameters

Name In Required Type Description
path True

string

The name of the role assignment. It can be any valid GUID.

path True

string

The scope of the operation or resource. Valid scopes are: subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'

query True

string

The API version to use for this operation.

Request Body

Name Required Type Description
properties.principalId True

string

The principal ID.

properties.roleDefinitionId True

string

The role definition ID.

properties.condition

string

The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'

properties.conditionVersion

string

Version of the condition. Currently the only accepted value is '2.0'

properties.delegatedManagedIdentityResourceId

string

Id of the delegated managed identity resource

properties.description

string

Description of role assignment

properties.principalType

The principal type of the assigned principal ID.

Name Type Description
200 OK

Returns the role assignment.

201 Created

Returns the role assignment.

Other Status Codes

Error response describing why the operation failed.

Permissions

To call this API, you must be assigned a role that has the following permissions. For more information, see Azure built-in roles .

Microsoft.Authorization/roleAssignments/write

Azure Active Directory OAuth2 Flow

Type: oauth2 Flow: implicit Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Name Description
user_impersonation impersonate your user account

Create role assignment for resource

Sample request.

To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue

Sample response

Create role assignment for resource group, create role assignment for subscription, definitions.

Name Description

The resource management error additional info.

The error detail.

Error response

The principal type of the assigned principal ID.

Role Assignments

Role assignment create parameters.

Error Additional Info

The resource management error additional info.

Name Type Description
info

object

The additional info.

type

string

The additional info type.

Error Detail

The error detail.

Name Type Description
additionalInfo

[]

The error additional info.

code

string

The error code.

details

[]

The error details.

message

string

The error message.

target

string

The error target.

Error Response

Error response

Name Type Description
error

The error object.

Principal Type

The principal type of the assigned principal ID.

Name Type Description
Device

string

ForeignGroup

string

Group

string

ServicePrincipal

string

User

string

Role Assignment

Role Assignments

Name Type Default value Description
id

string

The role assignment ID.

name

string

The role assignment name.

properties.condition

string

The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'

properties.conditionVersion

string

Version of the condition. Currently the only accepted value is '2.0'

properties.createdBy

string

Id of the user who created the assignment

properties.createdOn

string

Time it was created

properties.delegatedManagedIdentityResourceId

string

Id of the delegated managed identity resource

properties.description

string

Description of role assignment

properties.principalId

string

The principal ID.

properties.principalType

User

The principal type of the assigned principal ID.

properties.roleDefinitionId

string

The role definition ID.

properties.scope

string

The role assignment scope.

properties.updatedBy

string

Id of the user who updated the assignment

properties.updatedOn

string

Time it was updated

type

string

The role assignment type.

Role Assignment Create Parameters

Role assignment create parameters.

Name Type Default value Description
properties.condition

string

The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'

properties.conditionVersion

string

Version of the condition. Currently the only accepted value is '2.0'

properties.createdBy

string

Id of the user who created the assignment

properties.createdOn

string

Time it was created

properties.delegatedManagedIdentityResourceId

string

Id of the delegated managed identity resource

properties.description

string

Description of role assignment

properties.principalId

string

The principal ID.

properties.principalType

User

The principal type of the assigned principal ID.

properties.roleDefinitionId

string

The role definition ID.

properties.scope

string

The role assignment scope.

properties.updatedBy

string

Id of the user who updated the assignment

properties.updatedOn

string

Time it was updated

Additional resources

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Apply Azure RBAC to a resource using ARM

Is there a way to apply RBAC rules at the resource level via ARM? I was able to follow this Microsoft guide to add a user/role at the resource group level, but not at the resource. In particular, I am trying to add a new reader role to AppInsights via ARM. However, when I adjust the scope, the template just fails with this error:

I am left wondering what the scope variable is for if it cannot be changed. Is there some other place I should be modifying the scope to get this working?

Thanks in advance!

  • azure-rm-template

Community's user avatar

  • henrybeen.nl/… –  Ohad Schneider Commented May 22, 2019 at 18:08

5 Answers 5

The key is to drop the scope property, and instead nest the role assignment under the desired resource by using Microsoft.FooResource/BarSubType/providers/roleAssignments as the type, and using the following format for the name: {resourceName}/Microsoft.Authorization/{uniqueRoleAssignmentGuid} . Note that the GUID should be stable but unique to this role assignment, one easy option is guid(subscription().subscriptionId, 'some-sub-identifier-if-you-wish') .

Here is a template that shows you how to apply RBAC to a single resource, using a user-assigned managed identity defined in the same template:

Source: https://www.henrybeen.nl/creating-an-authorization-rule-using-an-arm-template/

Ohad Schneider's user avatar

  • 1 For me this is the right solution but its more clear to read the henrybeen example. The key is the name and the scope. –  AntuanSoft Commented May 24, 2019 at 13:40
  • Correct answer but as @AntuanSoft suggests: just read the answer by henrybeen –  pythonic833 Commented Jan 26 at 0:53

You apply RBAC rules at the resource level via an ARM and there is example template that applies RBAC rules at Azure VM here:

Hope this will help you.

Charles Xu's user avatar

  • Interesting. So you are saying that we can apply apply at the resource level, but it looks like the type and name fields have to change quite a bit in the ARM template. Could you help me in finding the appropriate resource type and name that would apply an RBAC to an AppInsight resource? –  Negatar Commented Sep 17, 2018 at 15:24
  • You can try to change like this "type": "microsoft.insights/components/providers/roleAssignments" for the resource. –  Charles Xu Commented Sep 18, 2018 at 8:04
  • I get an error when just changing the type: Deployment template validation failed: 'The template resource {guid} for type 'microsoft.insights/components/providers/roleAssignments' at line '1' and column '7721' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see aka.ms/arm-template/#resources for usage details.'. –  Negatar Commented Sep 18, 2018 at 18:49
  • The guid is the subscription id which the ApplicationInsight in. –  Charles Xu Commented Sep 19, 2018 at 0:52
  • Same error. The roleDefinitionId and principalId definitive work. Still can't find a type and name that work. Here is where I am at: { "type": "microsoft.insights/components/providers/roleAssignments", "apiVersion": "2017-05-01", "name": "[subscription().subscriptionId]", "properties": { "roleDefinitionId": "[variables('MonitoringReaderAzureSecurityGroup')]", "principalId": "[variables('AppInsightsReadOnlyPrincipalId')]" }, "dependsOn": [ "[resourceId('Microsoft.Insights/components/', parameters('websiteName'))]" ] } –  Negatar Commented Sep 19, 2018 at 16:38

Microsoft has finally provided documentation explaining this:

https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-template#resource-scope

Andrew Shepherd's user avatar

It is possible to apply RBAC on resource level using ARM.

The example what you referred shows how to apply RBAC on a particular resource group, where the scope is the path of the resource group.

Here, you are trying to assign a role to a particular resource. Changing the scope from resource group to resource (AppInsights) will work.

From the exception, I can see that the path of the resource may not be in the expected format.

The path of AppInsights should be in the following format,

Hope framing the scope like this helps!

Arunprabhu's user avatar

  • When you say 'path of AppInsights' and I assume you are meaning that I need to modify my scope setting. I added '/providers' to my scope like you suggested and have received the following (which is similar to what I got initially): The request to create role assignment '{guid}' is not valid. Role assignment scope '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{insightName}' must match the scope specified on the URI '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName} . Thoughts? –  Negatar Commented Sep 17, 2018 at 14:58

Agree that the documentation on this issue is less than useful. I have an array of Role IDs that I wanted to add as Owners at the App Insight resource, without making the users Owners at the Resource Group level. I didn't want to use the nested resource approach as I wanted to iterate over an array of objects to dynamically create the roles, so after tweaking the type, name, and scope attributes, the following resource block is what ended up working for me:

adam's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged json azure rbac azure-rm-template or ask your own question .

  • The Overflow Blog
  • The hidden cost of speed
  • The creator of Jenkins discusses CI/CD and balancing business with open source
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Filtering polygons by name in one column of QGIS Attribute Table
  • Is reading sheet music difficult?
  • How to clean a female disconnect connector
  • Audio mixing problem in cpp
  • Is it possible to travel to Uppsala from Stockholm with SL unlimited card?
  • Generating function for A261041
  • Power of Toffoli vs T in quantum logic
  • Do you believe something to be the truth or do you know the truth?
  • How to go from Asia to America by ferry
  • How to truncate text in latex?
  • Pólya trees counted efficiently
  • How long should a wooden construct burn (and continue to take damage) until it burns out (and stops doing damage)
  • What does こんなところ refer to here
  • Acceleration command in proportional navigation?
  • Plausible orbit to have a visible object slowly circle over the night sky
  • "With" as a function word to specify an additional circumstance or condition
  • What are the steps to write a book?
  • How can I make this equation look better?
  • Improper Subpanel Concerns
  • What prevents random software installation popups from mis-interpreting our consents
  • Is this host and 'parasite' interaction feasible?
  • How to simplify input to a table with many columns?
  • Can population variance from multiple studies be averaged to use for a sample size calculation?
  • What's the best format or way to generate a short-lived access token?

create a role assignment

IMAGES

  1. Project Team Roles And Responsibilities Template Excel

    create a role assignment

  2. 12 RACI Matrix Presentation Charts Templates with Project

    create a role assignment

  3. How to setup easy automatic role assignment

    create a role assignment

  4. How to setup easy automatic role assignment

    create a role assignment

  5. How to setup easy automatic role assignment

    create a role assignment

  6. PPT

    create a role assignment

VIDEO

  1. 22 Indirect Role Assignment

  2. Lesson108- Flow Azure key vault

  3. How To Create Role And Permissions For Team Members

  4. Role Assignment and Data access

  5. 11 Office 365 Exchange Online Permissions User roles Default Role Assignment Policy Arabic by R

  6. How to create a new custom role in Ans?

COMMENTS

  1. Assign Azure roles using the Azure portal

    Assign Azure roles using the Azure portal - Azure RBAC

  2. Understand Azure role assignments

    Role assignments enable you to grant a principal (such as a user, a group, a managed identity, or a service principal) access to a specific Azure resource. This article describes the details of role assignments. Role assignment. Access to Azure resources is granted by creating a role assignment, and access is revoked by removing a role assignment.

  3. az role assignment

    az role assignment create: Create a new role assignment for a user, group, or service principal. Core GA az role assignment delete: Delete role assignments. Core GA az role assignment list: List role assignments. Core GA az role assignment list-changelogs: List changelogs for role assignments. Core GA az role assignment update

  4. role-assignments-steps.md

    Steps to assign an Azure role

  5. Adding or removing role assignments using Azure Portal

    Adding a role assignment. Firstly, in the Azure portal, click All services and then select the scope that you want to grant access to. Secondly, click the specific resource for that scope. Then, Click Access control (IAM). Fourthly, click the Role assignments tab for viewing the role assignments at this scope. After that, click Add > Add role ...

  6. RBAC in Azure: A Practical Guide

    When creating a role assignment, you grant specific access, and removing the assignment revokes this access. Here is a diagram that illustrates an example of a role assignment: Image Source: Azure. This example assigns a contributor role to the marketing group—only for the pharma-sales resource group. It enables all users in the marketing ...

  7. Azure RBAC: role assignments and ARM templates

    Azure RBAC: role assignments and ARM templates | johnnyreilly

  8. Defining RBAC Role Assignments in ARM Templates

    Defining RBAC Role Assignments in ARM Templates

  9. Manage Azure Role Assignments Like a Pro with PowerShell

    Manage Azure Role Assignments Like a Pro with PowerShell

  10. Step-By-Step: Enabling Custom Role Based Access Control in Azure

    Once the role has been create you can use the following command to assign it to a group or user(s) az role assignment create --role "Restart Virtual Machines" --assignee [email protected] or assign it using the portal. As you can see bellow. We now have a new role (1) and it is assigned to the Rebecca user as per our last command. Here you go.

  11. Steps to assign an Azure role

    Steps to assign an Azure role - Azure RBAC

  12. Perform Role Assignments on Azure Resources from Azure Pipelines

    Perform Role Assignments on Azure Resources from ...

  13. Assigning RBAC permissions with Azure Resource Manager templates

    Let us take a look at two ARM templates with an RBAC role assignment on subscription and RG level. As seen above the template assigns a user object Network Contributor permission on the subscription level. The Azure CLI command explicitly targets the subscription for the deployment. Similar looks the template targeting the resource group.

  14. Delegate Azure role assignment management using conditions

    Figure 7: Review role assignment with conditions . How to delegate role assignment management using a new built-in role with built-in conditions . Now Dara wants to control who can sign into virtual machines using Microsoft Entra ID credentials. To do this, Dara needs to create role assignments for the Virtual Machine User Login or Virtual ...

  15. What Role or Scopes Does An Azure Service Principal Need to Create

    Also, ensure that the user ID through which you are creating this service principal and assigning the role to it has permissions to register and create applications in Azure AD. If not, then please assign that ID 'Application Administrator' Azure AD role or you should be allowed to create and register applications by an administrator even ...

  16. Assign Azure roles using Azure Resource Manager templates

    Assign Azure roles using Azure Resource Manager ...

  17. Create Azure role assignments

    Create Azure role assignments. This page shows how you grant permissions to GKE on Azure so that it can access Azure APIs. You need to perform these steps when setting up a new GKE on Azure cluster or when updating permissions for an existing cluster. These permissions are necessary for GKE on Azure to manage Azure resources on your behalf ...

  18. Create or update Azure custom roles using the Azure portal

    Create or update Azure custom roles using the Azure portal

  19. Role Assignments

    from azure.identity import DefaultAzureCredential from azure.mgmt.authorization import AuthorizationManagementClient """ # PREREQUISITES pip install azure-identity pip install azure-mgmt-authorization # USAGE python role_assignments_create_for_resource.py Before run the sample, please set the values of the client ID, tenant ID and client secret ...

  20. Create Role assignment dynamically in Terraform from input

    Create role assignment in terraform based on region. 3. Terraform Import azurerm_role_assignment. 1. Using the Terraform aws_iam_role datasource , get the statement from one AWS role and use it in creating another role in Terraform and append to it. 0. Creating Azure role assignments over a map of object_ids and roles.

  21. Apply Azure RBAC to a resource using ARM

    It is possible to apply RBAC on resource level using ARM. The example what you referred shows how to apply RBAC on a particular resource group, where the scope is the path of the resource group. Here, you are trying to assign a role to a particular resource. Changing the scope from resource group to resource (AppInsights) will work.