Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 57 ยท Identity and Governance

Role-Based Access Control

Learn how Azure role-based access control works: role definitions, assignments, scope inheritance, built-in and custom roles, and least privilege.

Azure RBAC answers one question: who can do what, and where? Microsoft Entra ID proves who someone is (see Microsoft Entra ID). Role-based access control decides what that identity may do to Azure resources. Without it, every sign-in would either see everything or nothing.

An RBAC grant always has three parts: a security principal (a user, group, service principal or managed identity), a role definition (a named set of permissions) and a scope (the place where the role applies). Together they form a role assignment. This lesson explains each part, how inheritance works, and how to keep permissions small. The real portal and CLI need an account, so they appear as read-only snippets. The runnable examples are JavaScript stand-ins that evaluate assignments the way the platform does, in simplified form.

Role definitions

A role definition is a JSON document listing what a role can do. The important fields are:

  • Actions: control-plane operations that are allowed, such as Microsoft.Compute/virtualMachines/start/action. Wildcards are allowed: */read means "read anything".
  • NotActions: operations subtracted from Actions. This is a subtraction, not a deny.
  • DataActions and NotDataActions: the same idea for the data plane, such as reading the contents of a blob.
  • AssignableScopes: where the role may be assigned.

The control plane and the data plane are separate. Being allowed to create a storage account does not mean you can read the blobs inside it; that needs a data role such as Storage Blob Data Reader. Many beginners meet this as a surprising "authorization failed" error on a resource they own.

Built-in roles

Azure ships hundreds of built-in roles. Four of them are the foundation and appear in almost every conversation about access:

Role What it allows
Owner Everything, including assigning roles to others
Contributor Everything except managing access (cannot assign roles)
Reader View resources, change nothing
User Access Administrator Manage role assignments only, no access to resources

Contributor is the usual day-to-day role for builders. Owner is powerful because it can grant itself and others access, so it should be rare. Beyond these four there are service-specific roles such as Virtual Machine Contributor, Storage Blob Data Contributor or Key Vault Secrets User. Prefer the narrow one over a broad one.

Scope and inheritance

A scope is a path through the hierarchy you met in Accounts, Tenants and Subscriptions: management group, subscription, resource group, resource. A role assigned at a scope applies to that scope and everything below it.

flowchart TB
    MG["Management group"] --> SUB["Subscription"]
    SUB --> RG["Resource group"]
    RG --> RES["Resource"]
    A1["Reader assigned here"] -.-> SUB
    A2["Contributor assigned here"] -.-> RG
    SUB -. "inherited by every child" .-> RG
    RG -. "inherited by every child" .-> RES

An assignment at a higher scope flows down. You cannot take a permission away at a lower scope by assigning a smaller role.

The last sentence of the caption is the key rule. RBAC is additive: when a person has several assignments that cover a resource, their effective permissions are the union of all of them. If Ana is Reader on the whole subscription and Virtual Machine Operator on one resource group, she can read everything and also start VMs in that group. A narrower assignment never reduces a wider one.

Assigning roles with the CLI

A role assignment names a principal, a role and a scope. These commands are read-only here because they change a real subscription:

Terminal
# Give a group the Reader role on a whole subscription
az role assignment create \
  --assignee-object-id <group-object-id> \
  --assignee-principal-type Group \
  --role "Reader" \
  --scope /subscriptions/<subscription-id>

# Give one person Contributor on a single resource group
az role assignment create \
  --assignee "[email protected]" \
  --role "Contributor" \
  --resource-group web

# See who has access at a scope
az role assignment list --scope /subscriptions/<subscription-id> --output table

Assign roles to groups whenever you can. Adding a person to a group is easier to audit and to undo than hunting down individual assignments.

A scope evaluator: a stand-in

The real authorization engine is Azure's own service, and its full rules are richer than anything we can run here. The stand-in below captures the core ideas: an assignment applies when its scope is a prefix of the resource's path, permissions add up across assignments, and NotActions subtract from a single role. The names and paths are invented.

JS Evaluate role assignments by scope

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Read the output line by line. Ana can start the VM only because of the narrower role on the web group; the same action on the database server is refused. Ben is Contributor, so he can delete the VM, but the NotActions line stops him from writing role assignments. And Ben has no assignment covering the data group, so he cannot even read the server. That last case shows why scope matters as much as the role.

Least privilege

Least privilege means giving each identity the smallest role at the smallest scope that lets it do its job, for as long as it needs it. In practice:

  • Choose a narrow built-in role before Contributor, and Contributor before Owner.
  • Choose a resource group or a resource before the subscription.
  • Give roles to groups and review membership.
  • Use Privileged Identity Management (PIM), a feature of Entra ID P2, so powerful roles are eligible and activated for a limited time with approval, instead of being permanent.
  • Give applications managed identities with only the data roles they need (see Managed Identities and Service Principals).

The second stand-in is a tiny review tool. It scores each assignment by role power times scope breadth and lists the risky ones. The scoring is a teaching device, not an Azure feature.

JS Flag over-privileged assignments

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Ana's Reader on the subscription and Ben's Contributor on one resource group pass the review. The pipeline bot with Contributor on the whole subscription is flagged: a common real-world finding, because CI systems often get more access than a single deployment needs.

Custom roles

When no built-in role fits, you can create a custom role from a JSON definition. Start from a built-in role that is close and remove what you do not need. This example allows reading and restarting VMs and nothing else:

JSON
{
  "Name": "VM Restarter",
  "Description": "Can view and restart virtual machines.",
  "Actions": [
    "Microsoft.Compute/virtualMachines/read",
    "Microsoft.Compute/virtualMachines/restart/action"
  ],
  "NotActions": [],
  "AssignableScopes": ["/subscriptions/<subscription-id>"]
}
Terminal
az role definition create --role-definition vm-restarter.json

Custom roles cost effort to maintain: the set of operations changes as services evolve, and there are limits on how many a tenant can hold. Use them when a built-in role is clearly too broad, not as a first move.

Deny assignments

Besides role assignments there are deny assignments, which block specific actions for specific principals even if a role would otherwise allow them, and which take precedence over role assignments. You normally cannot create them yourself. Azure creates them on your behalf, for example when a managed application or a protected deployment needs to stop even owners from tampering with its resources. For ordinary protection against accidents, use resource locks, covered in Azure Policy, Locks and Tags.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A user is Reader on a subscription and Contributor on one resource group in it. What can they do in that resource group?

    RBAC is additive. Effective permissions are the union of all assignments that cover the resource.
  2. 2. Which built-in role can create resources but cannot assign roles to other people?

    Contributor excludes authorization writes. Owner can also manage access, and User Access Administrator can manage only access.
  3. 3. What is the difference between Actions and DataActions in a role definition?

    Managing a storage account is control plane. Reading a blob's content is data plane and needs a data role.
  4. 4. Which approach best follows least privilege for a deployment pipeline that only updates one web app?

    Pick the smallest role at the smallest scope that does the job.

Summary

  • A role assignment combines a principal, a role definition and a scope.
  • Roles are inherited downward through management group, subscription, resource group and resource, and permissions from several assignments are added together.
  • Owner, Contributor, Reader and User Access Administrator are the foundation; prefer narrow service roles.
  • The control plane and the data plane use different permissions.
  • Apply least privilege: small roles, small scopes, groups, time-limited elevation and managed identities for apps.
  • Custom roles are for gaps; deny assignments are created by Azure features, and locks protect against accidents.

Next: Managed Identities and Service Principals.