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.

Overview and What You Will Learn

In this lab, you will assign a built-in RBAC role to a user scoped to a single Resource Group, verify that access actually works as expected, and understand why picking the correct scope matters as much as picking the correct role.

Why This Matters in Production

At a payments company like Razorpay, a contractor granted Contributor access at the Subscription level instead of a single Resource Group can accidentally modify or delete production resources belonging to teams they were never supposed to touch. RBAC scoped correctly the first time prevents this category of incident entirely, rather than relying on people simply being careful.

Core Principles

Every RBAC assignment in Azure has exactly three parts, and all three must be set correctly for access to work as intended.

◈ DIAGRAM
+------------------------------------------------+
| RBAC Assignment |
| |
| Security Principal -> WHO (user, group, app) |
| Role -> WHAT (permitted actions) |
| Scope -> WHERE (which resources) |
+------------------------------------------------+

Scope can be set at four levels, and permissions granted higher up automatically apply to everything beneath.

◈ DIAGRAM
+-----------------------+
| Management Group | <- broadest, affects every subscription inside
+-----------------------+
|
v
+-----------------------+
| Subscription |
+-----------------------+
|
v
+-----------------------+
| Resource Group |
+-----------------------+
|
v
+-----------------------+
| Individual Resource | <- narrowest, affects only this one thing
+-----------------------+

Three built-in roles cover almost every real scenario: Owner (full access, including granting access to others), Contributor (full access to manage resources, but cannot grant access), and Reader (view-only, no changes at all).

Remember

Owner includes the ability to grant other people access - a capability most day-to-day tasks never actually need. Default to Contributor unless a specific requirement genuinely calls for Owner.

Detailed Step-by-Step Practical Lab

  1. Create a Resource Group to scope the access assignment to:
Bash
az group create --name rg-rbac-lab-mumbai --location centralindia
  1. List the built-in roles available, to see the options beyond just Owner/Contributor/Reader:
Bash
az role definition list --output table
  1. Get the object ID of the user you want to assign access to:
Bash
az ad user show \
--id priya.sharma@yourtenant.onmicrosoft.com \
--query id --output tsv
  1. Assign the Contributor role, scoped only to the lab Resource Group, not the whole subscription:
Bash
az role assignment create \
--assignee priya.sharma@yourtenant.onmicrosoft.com \
--role "Contributor" \
--resource-group rg-rbac-lab-mumbai
Note

Using --resource-group instead of no scope flag at all is what keeps this assignment narrow. Omitting it and using --scope with a subscription-level path instead would grant Contributor across every Resource Group in the entire subscription.

  1. Verify the assignment was created correctly and check exactly what scope it applies to:
Bash
az role assignment list \
--assignee priya.sharma@yourtenant.onmicrosoft.com \
--output table
  1. Confirm the user cannot act outside that scope by attempting an action in a different Resource Group (as that user, via their own CLI session) and observing the expected access-denied result.

  2. Remove the role assignment once the lab is complete:

Bash
az role assignment delete \
--assignee priya.sharma@yourtenant.onmicrosoft.com \
--role "Contributor" \
--resource-group rg-rbac-lab-mumbai
  1. Clean up the Resource Group:
Bash
az group delete --name rg-rbac-lab-mumbai --yes --no-wait

Production Best Practices & Common Pitfalls

Common Mistake

Assigning the Owner role by default "just in case something needs more permission later." Owner's ability to grant access to others is rarely actually needed for daily work, and it meaningfully expands what a compromised account could do. Start with Contributor and escalate only when a specific need genuinely requires it.

Tip

Use Groups instead of individual user assignments wherever more than one or two people need the same access. Assigning a role to a group once, then adding and removing members from that group, is far easier to audit than tracking dozens of individual role assignments.

  • Prefer the narrowest scope that gets the job done. If someone only needs access to one Resource Group, scope the assignment there, not at the Subscription level "to save time."
  • Review role assignments periodically, not just when they are created. Access that made sense six months ago for a project that has since ended is exactly the kind of forgotten permission that causes an incident later.

Quick Reference & Troubleshooting Commands

Command Description
az role assignment create Assign a role to a principal at a given scope
az role assignment list List current role assignments for a principal
az role assignment delete Remove a role assignment
az role definition list List all available built-in roles

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.