SecurityAzure
Azure RBAC: scopes, built-in roles and custom roles
Azure RBAC grants access through role assignments. Each one names a security principal, a role definition and a scope. Microsoft's advice is to limit both the role and the scope.

Three parts of a role assignment
- Security principal. The object that requests access: a user, a group, a service principal or a managed identity.
- Role definition. A collection of permissions, also called a role. It lists the actions that can be performed.
- Scope. The resources the access covers.
Creating a role assignment grants access, and removing the assignment revokes it. Azure RBAC is an additive model: add up your role assignments and you have your effective permissions. Assignments are transitive for groups, so a user receives the permissions of a group that their own group belongs to. If a deny assignment applies, access is blocked before the role assignments are considered.
The four scope levels
You can assign a role at a management group, a subscription, a resource group or a single resource. Lower levels inherit role permissions from higher levels. In Microsoft's example, the Contributor role on a resource group lets a group of users create or manage any resource in that resource group.
/providers/Microsoft.Management/managementGroups/<management-group>
/subscriptions/<subscription-id>
/subscriptions/<subscription-id>/resourceGroups/<resource-group>A resource scope continues the third form with /providers/, the resource provider, the resource type and the resource name.
Built-in roles to know
- Owner. Full access to manage every resource, and the right to assign roles in Azure RBAC.
- Contributor. Full access to manage every resource, with no right to assign roles in Azure RBAC.
- Reader. View all resources, but make no changes.
- User Access Administrator. Manage user access to Azure resources.
- Role Based Access Control Administrator. Manage access by assigning roles in Azure RBAC. It does not allow managing access in other ways, such as Azure Policy.
Microsoft lists Owner, Contributor, User Access Administrator and Role Based Access Control Administrator among its privileged roles. Its advice: where a job function role does the work, do not assign a privileged administrator role. Virtual Machine Contributor, for example, allows a user to create and manage virtual machines.
A role definition lists control plane actions under Actions and data actions under DataActions. Data actions grant access to data within an object. Storage Blob Data Contributor, for one, reads, writes and deletes blobs through data actions.
A custom role in JSON
If the built-in roles do not meet your needs, you can create a custom role. This one uses four actions from Microsoft's Virtual Machine Operator example. Save it as vm-operator.json:
{
"Name": "Virtual Machine Operator",
"Description": "Can monitor and restart virtual machines.",
"Actions": [
"Microsoft.Compute/*/read",
"Microsoft.Compute/virtualMachines/start/action",
"Microsoft.Compute/virtualMachines/restart/action",
"Microsoft.Resources/subscriptions/resourceGroups/read"
],
"NotActions": [],
"DataActions": [],
"NotDataActions": [],
"AssignableScopes": [
"/subscriptions/<subscription-id>"
]
}az role definition create --role-definition vm-operator.jsonAssignableScopes lists the scopes where the role is available for assignment. It cannot be the root scope /, it cannot contain a wildcard, and it can hold only one management group. Microsoft recommends naming each action explicitly. A wildcard also grants the actions that are added in the future.
The az role assignment commands
az role assignment create \
--assignee <object-id> \
--role "Virtual Machine Operator" \
--scope /subscriptions/<subscription-id>/resourceGroups/<resource-group>
az role assignment list --assignee <object-id> \
--scope /subscriptions/<subscription-id>
az role assignment delete --assignee <object-id> \
--scope /subscriptions/<subscription-id>--role takes a role name or a role ID. In scripts, use the ID: even if a role is renamed, its ID does not change.
If you create a new service principal and assign it a role immediately, the assignment can fail. Microsoft attributes the failure to a replication delay. Pass --assignee-object-id and set --assignee-principal-type to ServicePrincipal in that case.
The delete command deletes all role assignments that match its arguments. Microsoft recommends running az role assignment list with the same arguments first.
Privileged Identity Management
Microsoft Entra Privileged Identity Management (PIM) grants privileged access to Microsoft Entra ID and to Azure resources just in time. With PIM, a role assignment can be eligible. An eligible user activates the role when they need it and can then use it for a preconfigured period of time. Activation can require a multifactor authentication check, a business justification or approval from designated approvers. PIM also offers time-bound assignments with start and end dates, access reviews and a downloadable audit history. PIM requires licenses, so read the Microsoft Entra licensing page before you plan around it.
Rules that keep access small
- Assign roles to groups in place of individual users. Microsoft says this makes assignments more manageable and minimizes their number. A subscription supports up to 5,000 role assignments.
- For a privileged role, use a narrow scope, such as a resource group or a resource.
- Have at most three subscription owners, as Microsoft recommends.
- When you assign a role that can create role assignments, consider adding a condition that constrains it.
- Use PIM for privileged roles, and run its access reviews to confirm that users still need them.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Azure Policy: audit, deny and fix resources that break the rules
Security · 4 min read
Definitions, effects and remediation in Azure Policy, and a rollout that audits before it denies.

Set up OIDC between GitHub Actions and Azure
Authentication · 2 min read
Five steps from an app registration to a workflow that logs in with no stored secret.

Landing zones: accounts, subscriptions and projects in order
Cloud operations · 5 min read
The account hierarchy, identity, network, logging and guardrails in each vendor's landing zone design.