1---2name: azure-role-selector-23description: Select the least-privilege Azure RBAC role for an identity, compare built-in and custom role options, and produce assignment commands or Bicep snippets. Use this skill when the user asks which Azure role to assign for permissions, scopes, identities, data-plane access, control-plane access, custom roles, or access requirements.4---56# Azure role selector78Select the minimal Azure RBAC role that grants the requested actions at the narrowest safe scope, then return the matching built-in or custom role option with Azure CLI assignment commands and a Bicep role assignment snippet.910## When to invoke1112- "Which Azure RBAC role should I assign for this identity?"13- "Find the least-privilege role for these Azure permissions."14- "Generate an az role assignment command for this service principal."15- "Should this use a built-in role or a custom role?"16- "Provide a Bicep snippet for this role assignment."1718## Prerequisites and context1920- Use `Azure MCP/documentation` to find minimal built-in role definitions and confirm `Actions`, `NotActions`, `DataActions`, and `NotDataActions`.21- Use `Azure MCP/extension_cli_generate` to generate Azure CLI commands and to create a custom role definition when no built-in role matches the required permissions.22- Use `Azure MCP/bicepschema` and `Azure MCP/get_bestpractices` to produce Bicep role assignment snippets and current Azure best-practice guidance.23- Require the identity, scope, and permissions. If any are missing, infer only when the repository or user request provides clear evidence; otherwise state the missing input.2425## Inputs to resolve2627| Input | Required detail | Examples |28| --- | --- | --- |29| Identity | Principal type and object/principal ID or resolvable name | user, group, service principal, managed identity |30| Scope | Narrowest resource boundary that needs access | management group, subscription, resource group, storage account, Key Vault |31| Permissions | Operations the identity must perform | read metrics, restart web app, pull image, read blobs, manage secrets |32| Plane | Control plane or data plane | `Actions` for ARM management; `DataActions` for data access |33| Duration | Permanent, temporary, or Privileged Identity Management workflow | standing assignment, eligible assignment, break-glass |3435## Selection criteria3637| Decision | Rule |38| --- | --- |39| Least privilege | Choose the narrowest built-in role whose allowed operations cover the required actions without broad unrelated permissions. |40| Scope minimization | Assign at the resource scope when possible; move to resource group, subscription, or management group only when the required operation spans that scope. |41| Built-in before custom | Prefer a built-in role when it matches cleanly. Create a custom role only when built-ins are too broad or miss required operations. |42| Control plane vs data plane | Do not confuse ARM management with data access. For example, managing a storage account is different from reading blobs. |43| Wildcards | Treat `*`, broad `Microsoft.Authorization/*`, and owner-like roles as high risk unless the request explicitly requires administration. |44| Deny exclusions | Check `NotActions` and `NotDataActions`; an apparent match is invalid if exclusions remove a required operation. |4546## Role matching workflow47481. Normalize the user's requested access into Azure operation names where possible.492. Determine the target scope and whether each permission is control-plane `Actions` or data-plane `DataActions`.503. Query Azure role documentation with `Azure MCP/documentation` and compare candidate built-in roles.514. Select the least-privilege built-in role when one covers the requested permissions.525. If no built-in role matches, use `Azure MCP/extension_cli_generate` to produce a custom role definition containing only the required `Actions` or `DataActions`.536. Generate an assignment command with `Azure MCP/extension_cli_generate`.547. Generate a Bicep snippet with `Azure MCP/bicepschema` and validate it against `Azure MCP/get_bestpractices`.5556## Common Azure RBAC distinctions5758| Request pattern | Check carefully |59| --- | --- |60| "Read a resource" | Reader may cover management metadata but not data-plane contents such as blobs, secrets, queues, or database rows. |61| "Deploy resources" | Contributor can create resources but cannot grant access; role assignment requires `Microsoft.Authorization/roleAssignments/write`. |62| "Manage access" | User Access Administrator grants role assignment management without full Owner permissions. |63| "Use Key Vault" | Separate secret, key, and certificate data operations from vault management operations. |64| "Use Storage" | Separate storage account management from blob, queue, table, or file data access roles. |65| "Pull container images" | Registry pull is narrower than contributor permissions on the registry. |66| "Managed identity access" | The consuming identity needs permissions at the target resource; the app host may also need permission to use or attach the identity. |6768## Assignment artifacts6970| Artifact | Include | Notes |71| --- | --- | --- |72| Azure CLI command | `az role assignment create --assignee <principal> --role "<role-name-or-id>" --scope <scope>` | Prefer role ID for custom roles or ambiguous names. |73| Custom role JSON | `Name`, `IsCustom`, `Description`, `Actions`, `NotActions`, `DataActions`, `NotDataActions`, `AssignableScopes` | Include only when no suitable built-in role exists. |74| Bicep snippet | `Microsoft.Authorization/roleAssignments` with deterministic `guid()` name | Role assignment name must be stable for the same principal, role, and scope. |75| Explanation | Why the selected role is least privilege and which broader roles were rejected | Mention major excluded permissions and risk. |7677## Gotchas7879- **Reader is not data reader**: many Azure services require data-plane roles even when the identity can view the resource in the portal.80- **Contributor cannot assign roles**: access management needs role assignment permissions, commonly via Owner or User Access Administrator.81- **Scope inheritance is powerful**: subscription-scope assignments flow to every child resource; prefer the smallest scope that satisfies the requirement.82- **Custom roles need assignable scopes**: a custom role cannot be assigned outside its `AssignableScopes`.83- **Role names can be ambiguous**: use role definition IDs when generating durable automation.8485## Output template8687````markdown88## Azure role selection8990**Status:** built-in selected | custom role required | blocked91**Identity:** <principal type and identifier>92**Scope:** `<scope>`93**Plane:** control plane | data plane | both9495### Recommendation96| Role | Type | Why it matches | Broader roles rejected |97| --- | --- | --- | --- |98| `<role name or custom role name>` | built-in/custom | <required permissions covered> | <roles and reason> |99100### Assignment command101```bash102az role assignment create --assignee <principal-id> --role "<role-name-or-id>" --scope <scope>103```104105### Bicep106```bicep107resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {108 name: guid(<scope-id>, '<principal-id>', '<role-definition-id>')109 scope: <scope-symbol>110 properties: {111 principalId: '<principal-id>'112 roleDefinitionId: '<role-definition-resource-id>'113 principalType: '<User|Group|ServicePrincipal|ForeignGroup|Device>'114 }115}116```117118### Custom role definition119<include only when no built-in role matches>120````121122## Quality gate123124- [ ] The identity, scope, and required permissions are stated or listed as blockers.125- [ ] `Azure MCP/documentation` was used to compare built-in role definitions.126- [ ] The selected role is the least-privilege match and broader roles are explicitly rejected.127- [ ] Control-plane `Actions` and data-plane `DataActions` are not confused.128- [ ] `NotActions` and `NotDataActions` do not exclude required permissions.129- [ ] `Azure MCP/extension_cli_generate` was used for assignment commands and custom role definitions when needed.130- [ ] `Azure MCP/bicepschema` and `Azure MCP/get_bestpractices` were used for the Bicep snippet.131- [ ] The CLI command and Bicep snippet use the narrowest safe scope.