Skip to main content

Configuring Role-Based Access Control in Azure

Learn how Azure RBAC combines a principal, a role, and a scope to control exactly who can do what to which resources, with a hands-on lab.

Overview and What You Will Learn

Azure role-based access control (RBAC) decides who can do what to which resources by combining three things in a role assignment: a security principal, a role and a scope. In this lab you will assign the Contributor role to a user on a single resource group, prove the access stops at that scope, and remove it again.

  • Reading a built-in role's allowed and excluded actions
  • Creating a role assignment scoped to one resource group
  • Verifying where an assignment applies and where it does not
  • Testing the access as the assigned user
  • Choosing the narrowest scope and role that do the job

Why This Matters in Production

Scope is as important as role, because the same role is harmless on one resource group and dangerous on a whole subscription. Imagine a platform team at a company like Netflix that grants a contractor Contributor at the subscription level instead of on one resource group. The contractor can now change or delete resources owned by teams they never worked with. Scoping correctly the first time prevents that whole class of incident without relying on people being careful.

Core Principles

Every role assignment has exactly three parts, and all three must be right for access to work as intended. The principal is who gets access, the role is what they can do, and the scope is where it applies.

flowchart TD P[Security principal
WHO: user, group, app]:::src --> A((Role
assignment)):::tool R[Role
WHAT: permitted actions]:::soft --> A S[Scope
WHERE: which resources]:::warn --> A A --> X([Access granted
only there]):::ok classDef src fill:#DBEAFE,color:#1E293B classDef soft fill:#EDE9FE,color:#1E293B classDef warn fill:#FFEDD5,color:#1E293B classDef tool fill:#326CE5,color:#FFFFFF classDef ok fill:#10B981,color:#FFFFFF

Scope has four levels, and a permission granted at a higher level is inherited by everything below it. An assignment at a management group reaches every subscription inside it, while an assignment on one resource reaches only that resource.

flowchart TD MG[Management group
broadest]:::slate -->|inherits| SUB[Subscription]:::tool SUB -->|inherits| RG[Resource group]:::tool RG -->|inherits| RES[Resource
narrowest]:::ok classDef slate fill:#475569,color:#FFFFFF classDef tool fill:#326CE5,color:#FFFFFF classDef ok fill:#10B981,color:#FFFFFF

Three built-in roles cover most real scenarios:

Role What it can do
Owner Everything, including granting access to others
Contributor Create and manage resources, but not grant access
Reader View resources, with no changes
Remember

Owner includes the power to grant other people access, which most daily tasks never need. Default to Contributor, or an even narrower role, unless a requirement genuinely calls for Owner.

Detailed Step-by-Step Practical Lab

  1. Create two resource groups. The first receives the assignment and the second proves the assignment does not reach beyond it:
Bash
az group create --name rg-rbac-lab-central --location centralindia
az group create --name rg-rbac-lab-other --location centralindia
  1. Create a test user, or use an existing test account. You need the User Administrator role in the tenant for this step:
Bash
read -s -p "Temporary password for the test user: " USER_PASSWORD
az ad user create \
--display-name "Priya Sharma" \
--user-principal-name priya.sharma@devops.in \
--password "$USER_PASSWORD" \
--force-change-password-next-sign-in true
  1. Look at what the Contributor role allows and what it explicitly excludes. The excluded actions are why Contributor cannot grant access:
Bash
az role definition list --name "Contributor" \
--query "[0].permissions[0].notActions" --output tsv
az role definition list \
--query "[?roleType=='BuiltInRole'].roleName" --output tsv | sort | head -n 20
  1. Get the user's object ID, then assign Contributor on the first resource group only. Using the object ID and principal type avoids a directory lookup:
Bash
USER_ID=$(az ad user show \
--id priya.sharma@devops.in \
--query id --output tsv)
az role assignment create \
--assignee-object-id "$USER_ID" \
--assignee-principal-type User \
--role "Contributor" \
--resource-group rg-rbac-lab-central
Common Mistake

Leaving off --resource-group and --scope. Without a scope, az role assignment create defaults to the whole current subscription, so the same Contributor role would apply to every resource group in it.

  1. Verify the assignment and read its scope. The scope column should end in rg-rbac-lab-central:
Bash
az role assignment list \
--assignee "$USER_ID" \
--all \
--query "[].[roleDefinitionName,scope]" --output table
  1. Confirm nothing is assigned to this user on the other resource group, including through inheritance:
Bash
SUB_ID=$(az account show --query id --output tsv)
az role assignment list \
--assignee "$USER_ID" \
--scope "/subscriptions/$SUB_ID/resourceGroups/rg-rbac-lab-other" \
--include-inherited \
--query "[].roleDefinitionName" --output tsv
# Expected: no output, meaning no access reaches this group
  1. Test the access as the user. Role assignments can take up to about five minutes to take effect. Use a separate CLI profile so your own session stays signed in, and note that a tenant that requires MFA will prompt for it:
Bash
export AZURE_CONFIG_DIR=/tmp/priya-cli
az login --username priya.sharma@devops.in
az resource list --resource-group rg-rbac-lab-central
# Expected: succeeds, returning an empty list
az resource list --resource-group rg-rbac-lab-other
# Expected: fails with AuthorizationFailed
az logout
unset AZURE_CONFIG_DIR
  1. Remove the assignment and clean up. Deleting a resource group also removes assignments scoped to it, but removing the assignment explicitly confirms the command works:
Bash
az role assignment delete \
--assignee "$USER_ID" \
--role "Contributor" \
--resource-group rg-rbac-lab-central
az group delete --name rg-rbac-lab-central --yes --no-wait
az group delete --name rg-rbac-lab-other --yes --no-wait
az ad user delete --id priya.sharma@devops.in

Production Best Practices & Common Pitfalls

Common Mistake

Assigning Owner by default "just in case something needs more permission later". Owner's power to grant access is rarely needed for daily work and widens what a compromised account can do. Start with Contributor and escalate only for a specific need.

Tip

Assign roles to groups instead of individuals whenever more than one or two people need the same access. You assign the role once, then add and remove members, which is far easier to audit than dozens of individual assignments.

Security

Azure roles and Microsoft Entra roles are separate systems. A Global Administrator in Entra can elevate themselves to manage all Azure subscriptions, so protect those accounts with MFA and keep their number small.

  • Choose the narrowest scope that does the job. If someone needs one resource group, assign it there, not at the subscription "to save time".
  • Review assignments on a schedule. Access granted for a project that ended months ago is the kind of forgotten permission that becomes an incident later.
  • Use just-in-time access for privileged roles. Privileged Identity Management (Entra ID P2) makes Owner and similar roles time-limited and approval-based instead of permanent.
  • Prefer a narrower built-in role over Contributor. Roles such as Virtual Machine Contributor or Storage Blob Data Reader grant only what a task needs, and custom roles fill the remaining gaps.
  • Watch the assignment limit. A subscription supports a limited number of role assignments, currently 4,000, and group-based assignment keeps you far from it.

Quick Reference & Troubleshooting Commands

Command Description
az role assignment create Assign a role to a principal at a scope
az role assignment list --assignee --all List a principal's assignments and their scopes
az role assignment list --include-inherited Include assignments inherited from higher scopes
az role assignment delete Remove a role assignment
az role definition list --name Inspect a role's permitted and excluded actions

Explore More in Azure Fundamentals and Governance

All 6 Topics

Frequently Asked Questions

Is Configuring Role-Based Access Control in Azure free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Configuring Role-Based Access Control in Azure topic cover?

Learn how Azure RBAC combines a principal, a role, and a scope to control exactly who can do what to which resources, with a hands-on lab.

Found a mistake, an outdated step or a broken link?