02 / 13Identity and access
Azure RBAC security hardening
Harden Azure RBAC: group-based assignments at the right scope, few Owners, PIM eligibility, narrow custom roles, conditional delegation and access reviews.
- Service
- Azure RBAC
- Category
- Identity and access
- Baseline
- 9 controls
- Updated
On this page
Azure role-based access control (Azure RBAC) decides who can do what to which Azure resource. It is separate from Microsoft Entra roles: a Global Administrator has no rights on subscriptions by default (until they elevate access), and a subscription Owner has no rights in the directory. Left to grow on its own, RBAC drifts toward the same pattern in almost every tenant: Owner and Contributor handed to individual users at subscription scope, service principals with Owner and long-lived client secrets, guests who kept their access after a project ended, and custom roles with wildcard actions. Attackers who phish one of those users or find one of those secrets in a repository get the whole subscription, and cloud intrusion reports from Microsoft and Mandiant keep describing exactly that path: valid cloud credentials, then new role assignments for persistence. This page maps to the Microsoft cloud security benchmark Privileged Access controls (PA-1, PA-2, PA-4, PA-7) and to the identity and access management section of the CIS Microsoft Azure Foundations Benchmark. The management group hierarchy and the tenant root scope are covered on the Azure Policy page; the directory side (Global Administrator, Conditional Access, PIM settings) is on the Entra ID page.
Baseline controls
CIS numbers refer to the CIS Microsoft Azure Foundations Benchmark v7.0.0.
| Control | Why | How to check | ID |
|---|---|---|---|
| Assign to groups at the narrowest scope | Direct user assignments never get cleaned up | az role assignment list --all --query "[?principalType=='User']" | MCSB PA-7 |
| Two to three subscription Owners | Every Owner is a full takeover path | az role assignment list --role Owner --scope /subscriptions/<id> | MCSB PA-1 / CIS 5.7 |
| No standing privileged access | Stolen sessions only work while a role is active | PIM > Azure resources > Assignments | MCSB PA-2 |
| No guest, blocked or orphaned principals | Forgotten access is invisible access | Policy compliance for the guest and blocked owner policies | MCSB PA-4 / CIS 5.3.5 |
| Narrow custom roles, no wildcards | Actions: ["*"] is an Owner in disguise | az role definition list --custom-role-only true | MCSB PA-7 / CIS 5.4 |
| Constrained delegation of role assignment | User Access Administrator lets teams grant themselves anything | Look for Owner or User Access Administrator held by app teams | MCSB PA-7 / CIS 5.12 |
| Workload identities without secrets | Client secrets leak through code and pipelines | az ad sp list --all with passwordCredentials | MCSB IM-3 / CIS 5.11 |
| Locks and deny assignments on scaffolding | Owners can delete logs and hub networks | az lock list | CIS 6.2 |
| Regular access reviews | Permissions accumulate as people change teams | PIM > Azure resources > Access reviews | MCSB PA-4 / CIS 5.3.4 |
Assign roles to groups at the right scope
A role assignment has three parts: a security principal (user, group, service principal or managed identity), a role definition (allowed Actions, NotActions, DataActions, NotDataActions) and a scope (management group, subscription, resource group or resource). Assignments inherit downward, and effective access is the union of every assignment that applies, minus any deny assignments. NotActions is not a deny: it only subtracts from that one role, so another role can still grant the same action.
Control plane and data plane are separate. Contributor manages a storage account but cannot read blobs through Entra authentication. It can, however, call Microsoft.Storage/storageAccounts/listkeys/action and read everything with the account key, which is why the storage page disables shared key access.
Assign roles to Microsoft Entra security groups and manage membership there, ideally through PIM for Groups or access packages. Direct user assignments scatter across hundreds of resources and nobody removes them when someone changes teams.
az role assignment create \
--assignee-object-id <group-object-id> \
--assignee-principal-type Group \
--role "Reader" \
--scope /providers/Microsoft.Management/managementGroups/landingzones
Always pass --assignee-object-id together with --assignee-principal-type. It skips the Graph lookup and fails loudly if the ID is wrong, instead of matching an unexpected principal by display name or UPN.
A role model that works for most landing zone subscriptions:
| Who | Role | Scope |
|---|---|---|
| Platform team | Owner (eligible through PIM) | Platform management groups |
| Application team | Contributor (eligible) | Their resource groups |
| Application team | Reader (active) | Their subscription |
| Security team | Security Reader, Reader | Top management group |
| CI/CD workload identity | Custom deploy role | One resource group |
| Auditors | Reader | Top management group |
Verify
List every assignment held directly by a user across the tenant with Azure Resource Graph:
authorizationresources
| where type =~ "microsoft.authorization/roleassignments"
| extend principalType = tostring(properties.principalType),
scope = tostring(properties.scope),
roleId = tostring(split(properties.roleDefinitionId, "/")[-1])
| where principalType == "User"
| summarize assignments = count() by scope, roleId
| order by assignments desc
Join the role IDs against authorizationresources | where type =~ "microsoft.authorization/roledefinitions" to get names, or check the three that matter most: Owner 8e3af657-a8ff-443c-a75c-2fe8c4bcb635, Contributor b24988ac-6180-42a0-ab88-20f7382dd24c, User Access Administrator 18d7d88d-d35e-4fb5-a5c3-7773c20a72d9.
Limit subscription Owners
Owner can do everything, including granting Owner to someone else. Keep it to a small named group per subscription, and make sure more than one person holds it so a single departure does not lock you out. Defender for Cloud and Azure Policy both check this with two built-in definitions:
- A maximum of 3 owners should be designated for your subscription
- There should be more than one owner assigned to your subscription
az role assignment list \
--role Owner \
--scope /subscriptions/<sub-id> \
--include-inherited \
--query "[].{who:principalName, type:principalType, scope:scope}" -o table
--include-inherited matters: an Owner assignment at a management group counts for every subscription below it, and that is where forgotten assignments hide. Both definitions are part of the Microsoft cloud security benchmark initiative, so assigning that initiative at your top management group (see Azure Policy) reports every subscription that drifts.
The classic administrator model (Account Administrator, Service Administrator, co-administrators) was retired in 2024. If Subscription > Access control (IAM) > Classic administrators still shows anything, convert it to an RBAC assignment.
Make privileged roles eligible with PIM
Standing Owner and Contributor assignments mean a stolen token or session is immediately useful. Microsoft Entra Privileged Identity Management (PIM) for Azure resources turns them into eligible assignments that a user activates for a limited time, with MFA, a justification and optionally an approval. PIM requires Microsoft Entra ID P2 or Microsoft Entra ID Governance licenses for the users involved.
Portal: Microsoft Entra Privileged Identity Management > Azure resources > (select scope) > Assignments > Add assignments, assignment type Eligible.
The same through the Azure RBAC REST API:
az rest --method PUT \
--url "https://management.azure.com/subscriptions/<sub-id>/providers/Microsoft.Authorization/roleEligibilityScheduleRequests/$(uuidgen)?api-version=2020-10-01" \
--body '{
"properties": {
"principalId": "<group-object-id>",
"roleDefinitionId": "/subscriptions/<sub-id>/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635",
"requestType": "AdminAssign",
"scheduleInfo": {
"expiration": { "type": "AfterDuration", "duration": "P365D" }
}
}
}'
Then edit the role settings (PIM > Azure resources > Settings > Owner): maximum activation of a few hours, require MFA (or a Conditional Access authentication context) on activation, require justification, and require approval for Owner and User Access Administrator. Remove the old active assignment once the eligible one is in place.
Keep exceptions explicit: break glass accounts (covered on the Entra ID page) and workload identities stay active, everything held by a human becomes eligible.
Remove guest, blocked and orphaned assignments
Three kinds of principals should not hold privileged Azure roles:
- Guests. A B2B guest's account is protected by their home tenant, not yours. Built-in policies: Guest accounts with owner permissions on Azure resources should be removed and Guest accounts with write permissions on Azure resources should be removed.
- Blocked accounts. Disabled users who still hold Owner are a reactivation away from full access. Built-in policy: Blocked accounts with owner permissions on Azure resources should be removed.
- Orphaned assignments. When a user, group or service principal is deleted, its assignments stay behind and show as Identity not found in the portal. They grant nothing, but they clutter every review and hide real findings.
# Assignments whose principal no longer resolves
az role assignment list --all \
--query "[?principalName==''].{id:id, scope:scope, role:roleDefinitionName}" -o table
# Remove one
az role assignment delete --ids <role-assignment-id>
Resource Graph does not know which users are guests, so resolve them from Microsoft Graph and compare with the assignment list:
az ad user list --filter "userType eq 'Guest'" --query "[].id" -o tsv > guests.txt
az role assignment list --all --query "[].{p:principalId, role:roleDefinitionName, scope:scope}" -o tsv \
| grep -F -f guests.txt
Write narrow custom roles
Contributor allows almost everything except managing access. A pipeline that only deploys web apps does not need to create virtual networks, run commands on VMs or read storage keys. A custom role narrows it:
{
"Name": "Web App Deployer",
"Description": "Deploy and configure App Service apps in one resource group.",
"Actions": [
"Microsoft.Web/sites/*",
"Microsoft.Web/serverfarms/read",
"Microsoft.Resources/deployments/*",
"Microsoft.Resources/subscriptions/resourceGroups/read",
"Microsoft.Insights/components/read"
],
"NotActions": [
"Microsoft.Web/sites/config/list/action",
"Microsoft.Web/sites/publishxml/action"
],
"DataActions": [],
"NotDataActions": [],
"AssignableScopes": ["/subscriptions/<sub-id>"]
}
az role definition create --role-definition @web-app-deployer.json
Actions that lead to privilege escalation or credential exposure, and that should never appear through a wildcard in a custom role:
| Action | What it gives |
|---|---|
Microsoft.Authorization/* | Create role assignments, so any role |
Microsoft.Storage/storageAccounts/listkeys/action | Full data access with the account key |
Microsoft.Compute/virtualMachines/runCommand/action | Code execution as SYSTEM or root, and the VM's managed identity |
Microsoft.Web/sites/config/list/action | App settings, often with connection strings and secrets |
Microsoft.KeyVault/vaults/write | Switch a vault's access model or policies |
Microsoft.ManagedIdentity/userAssignedIdentities/*/assign/action | Attach a privileged identity to your own compute |
Verify and enforce
az role definition list --custom-role-only true \
--query "[?contains(to_string(permissions[].actions), '\"*\"')].{name:roleName, scopes:assignableScopes}" -o table
The built-in policy Audit usage of custom RBAC roles flags every custom role in use, which is a useful inventory even if you keep some. Create custom roles at a management group (AssignableScopes with a management group ID) so there is one definition to review instead of one copy per subscription.
Constrain who can grant access
Teams often need to give their own managed identities access to their own storage. Giving them User Access Administrator or Owner for that also lets them grant themselves anything. Use Role Based Access Control Administrator with a condition that limits which roles they may assign and remove:
az role assignment create \
--assignee-object-id <app-team-group-id> \
--assignee-principal-type Group \
--role "Role Based Access Control Administrator" \
--scope /subscriptions/<sub-id>/resourceGroups/rg-app1 \
--condition-version "2.0" \
--condition "((!(ActionMatches{'Microsoft.Authorization/roleAssignments/write'})) OR (@Request[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAnyValues:GuidEquals {ba92f5b4-2d11-453d-a403-e96b0029c9fe, 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1})) AND ((!(ActionMatches{'Microsoft.Authorization/roleAssignments/delete'})) OR (@Resource[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAnyValues:GuidEquals {ba92f5b4-2d11-453d-a403-e96b0029c9fe, 2a2b9908-6ea1-4ae2-8e65-a410df84e7d1}))"
The two GUIDs are Storage Blob Data Contributor and Storage Blob Data Reader. The team can hand out those two roles in its resource group and nothing else. In the portal, the same option is Access control (IAM) > Add role assignment > Role Based Access Control Administrator > Conditions > Allow user to only assign selected roles to selected principals. You can also restrict the principal types (for example only service principals) so the team cannot grant data roles to arbitrary users.
Replace service principal secrets
Service principals with client secrets and Owner at subscription scope are the most common way a leaked credential becomes a tenant-wide incident. Move Azure-hosted workloads to managed identities and external pipelines (GitHub Actions, Azure DevOps, other clouds) to workload identity federation, as described on the Entra ID page.
Find service principals that still have password credentials and what they can do:
az ad app list --all \
--query "[?length(passwordCredentials) > \`0\`].{app:displayName, appId:appId, secretEnd:passwordCredentials[0].endDateTime}" -o table
az role assignment list --all \
--query "[?principalType=='ServicePrincipal' && roleDefinitionName=='Owner'].{sp:principalName, scope:scope}" -o table
For each one at Owner, replace Owner with a custom role at the resource group it actually deploys to, then replace the secret with a federated credential.
Protect critical resources with locks and deny assignments
RBAC decides who may act; locks and deny assignments stop actions regardless of role.
A CanNotDelete lock on resource groups that hold Log Analytics workspaces, Key Vaults, hub networks and Recovery Services vaults blocks accidental or malicious deletion. An Owner can remove a lock (it needs Microsoft.Authorization/locks/delete), so pair locks with an alert on that operation.
az lock create --name protect-logs --lock-type CanNotDelete \
--resource-group rg-management-logs
az lock list --query "[].{name:name, level:level, scope:id}" -o table
Deployment stacks can apply deny settings (denyDelete or denyWriteAndDelete) to the resources they manage, with explicit excluded principals such as your deployment pipeline. That creates real deny assignments that Owners cannot override, which suits platform resources only your pipeline should change.
az stack group create \
--name platform-logs \
--resource-group rg-management-logs \
--template-file logs.bicep \
--deny-settings-mode denyDelete \
--deny-settings-excluded-principals <pipeline-sp-object-id> \
--action-on-unmanage detachAll
At organization scale, the built-in policy Do not allow deletion of resource types uses the DenyAction effect to block deletion of chosen resource types (for example Log Analytics workspaces) regardless of role.
Review access regularly
Roles accumulate. Schedule access reviews of privileged Azure roles so owners of each scope confirm who still needs access, and let unanswered reviews remove access automatically.
Portal: Microsoft Entra Privileged Identity Management > Azure resources > (select subscription or management group) > Access reviews > New. Review Owner, User Access Administrator, Role Based Access Control Administrator and Contributor at least quarterly, with the subscription owners or a manager as reviewers and Auto apply results to resource enabled.
For groups that carry Azure roles, run the review on group membership instead (Identity Governance > Access reviews), which covers every role the group holds.
Between reviews, use the queries above plus Defender for Cloud recommendations as your continuous signal.
Logging and detection
Every role assignment change is a control plane operation in the Azure activity log. Export the activity log of every subscription to a Log Analytics workspace with a diagnostic setting (category Administrative), as shown on the Azure Monitor page. Changes made at management group scope land in the management group's activity log, not in the subscriptions below, so check those separately.
Alert on new role assignments, especially for privileged roles:
AzureActivity
| where OperationNameValue =~ "MICROSOFT.AUTHORIZATION/ROLEASSIGNMENTS/WRITE"
| where ActivityStatusValue == "Success"
| extend props = parse_json(Properties)
| extend roleDefinitionId = tostring(parse_json(tostring(props.requestbody)).Properties.RoleDefinitionId)
| where roleDefinitionId has_any ("8e3af657-a8ff-443c-a75c-2fe8c4bcb635",
"18d7d88d-d35e-4fb5-a5c3-7773c20a72d9",
"f58310d9-a9f6-439a-9e8d-f62e7b41a168")
| project TimeGenerated, Caller, CallerIpAddress, _ResourceId, roleDefinitionId
The third GUID is Role Based Access Control Administrator. Also alert on:
Microsoft.Authorization/roleDefinitions/write(new or edited custom roles).Microsoft.Authorization/locks/deleteandMicrosoft.Resources/deploymentStacks/delete(removing the protection before the attack).- Elevate access by a Global Administrator, logged in the Microsoft Entra audit log under the Azure RBAC (Elevated Access) service (see Azure Policy).
- PIM activations of Owner outside working hours (
AuditLogs | where LoggedByService == "PIM").
As a no-KQL baseline, create activity log alerts on the operation:
az monitor activity-log alert create \
--name alert-role-assignment-write \
--resource-group rg-monitoring \
--scope /subscriptions/<sub-id> \
--condition category=Administrative and operationName=Microsoft.Authorization/roleAssignments/write \
--action-group /subscriptions/<sub-id>/resourceGroups/rg-monitoring/providers/microsoft.insights/actionGroups/ag-security
Microsoft Defender for Resource Manager (part of Defender for Cloud) adds alerts for suspicious control plane activity, such as role assignments from unusual locations and known attacker tooling against Azure Resource Manager.
Common mistakes
- Assigning Owner to a user "just for the migration". Nobody removes it; six months later that account is phished and the attacker owns the subscription.
- Treating
NotActionsas a deny. A role withNotActionsonMicrosoft.Authorization/*combined with any other role that grants it still lets the user assign roles. - Giving app teams User Access Administrator to wire up managed identities. They can now grant themselves Owner. Use Role Based Access Control Administrator with a condition.
- Ignoring inherited assignments. Reviewing only subscription-level IAM misses Owners at management groups and at the tenant root.
- Leaving Contributor on pipelines. Contributor can run commands on VMs and list storage and App Service secrets, so a compromised pipeline is a compromised environment.
- Deleting a user without cleaning their assignments. The orphaned entries pile up until nobody reads the IAM blade any more.
- Locks without alerts. An attacker with Owner removes the lock first; without an alert on
locks/deleteyou learn it from the deletion.
References
- What is Azure role-based access control (Azure RBAC)? (Microsoft Learn)
- Best practices for Azure RBAC (Microsoft Learn)
- Azure built-in roles (Microsoft Learn)
- Delegate Azure role assignment management to others with conditions (Microsoft Learn)
- Assign Azure resource roles in Privileged Identity Management (Microsoft Learn)
- Deployment stacks (Microsoft Learn)
- Microsoft cloud security benchmark: Privileged Access (Microsoft Learn)
- CIS Microsoft Azure Foundations Benchmark (Center for Internet Security)
- MITRE ATT&CK T1098.003: Account Manipulation, Additional Cloud Roles (MITRE)
- Azure landing zone reference implementation (GitHub, Microsoft)
Filed under rbac, least-privilege, privileged-access
Written by
Florian Amette, Cloud Security Engineer & EditorSecurity engineer writing practical hardening pages for Microsoft Azure tenants and subscriptions, aligned with the CIS Microsoft Azure Foundations Benchmark.