1---2name: azure-role-selector3description: 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<!-- Generated from harness/github-copilot/skills/azure-role-selector/SKILL.md by harness/claude-code/scripts/convert_from_copilot.py. Edit the source, not this file. -->78# Azure role selector910Select 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.1112## When to invoke1314- "Which Azure RBAC role should I assign for this identity?"15- "Find the least-privilege role for these Azure permissions."16- "Generate an az role assignment command for this service principal."17- "Should this use a built-in role or a custom role?"18- "Provide a Bicep snippet for this role assignment."1920## Prerequisites and context2122- Use `Azure MCP/documentation` to find minimal built-in role definitions and confirm `Actions`, `NotActions`, `DataActions`, and `NotDataActions`.23- 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.24- Use `Azure MCP/bicepschema` and `Azure MCP/get_bestpractices` to produce Bicep role assignment snippets and current Azure best-practice guidance.25- 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.2627## Inputs to resolve2829| Input | Required detail | Examples |30| --- | --- | --- |31| Identity | Principal type and object/principal ID or resolvable name | user, group, service principal, managed identity |32| Scope | Narrowest resource boundary that needs access | management group, subscription, resource group, storage account, Key Vault |33| Permissions | Operations the identity must perform | read metrics, restart web app, pull image, read blobs, manage secrets |34| Plane | Control plane or data plane | `Actions` for ARM management; `DataActions` for data access |35| Duration | Permanent, temporary, or Privileged Identity Management workflow | standing assignment, eligible assignment, break-glass |3637## Selection criteria3839| Decision | Rule |40| --- | --- |41| Least privilege | Choose the narrowest built-in role whose allowed operations cover the required actions without broad unrelated permissions. |42| 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. |43| 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. |44| Control plane vs data plane | Do not confuse ARM management with data access. For example, managing a storage account is different from reading blobs. |45| Wildcards | Treat `*`, broad `Microsoft.Authorization/*`, and owner-like roles as high risk unless the request explicitly requires administration. |46| Deny exclusions | Check `NotActions` and `NotDataActions`; an apparent match is invalid if exclusions remove a required operation. |4748## Role matching workflow49501. Normalize the user's requested access into Azure operation names where possible.512. Determine the target scope and whether each permission is control-plane `Actions` or data-plane `DataActions`.523. Query Azure role documentation with `Azure MCP/documentation` and compare candidate built-in roles.534. Select the least-privilege built-in role when one covers the requested permissions.545. 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`.556. Generate an assignment command with `Azure MCP/extension_cli_generate`.567. Generate a Bicep snippet with `Azure MCP/bicepschema` and validate it against `Azure MCP/get_bestpractices`.5758## Common Azure RBAC distinctions5960| Request pattern | Check carefully |61| --- | --- |62| "Read a resource" | Reader may cover management metadata but not data-plane contents such as blobs, secrets, queues, or database rows. |63| "Deploy resources" | Contributor can create resources but cannot grant access; role assignment requires `Microsoft.Authorization/roleAssignments/write`. |64| "Manage access" | User Access Administrator grants role assignment management without full Owner permissions. |65| "Use Key Vault" | Separate secret, key, and certificate data operations from vault management operations. |66| "Use Storage" | Separate storage account management from blob, queue, table, or file data access roles. |67| "Pull container images" | Registry pull is narrower than contributor permissions on the registry. |68| "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. |6970## Assignment artifacts7172| Artifact | Include | Notes |73| --- | --- | --- |74| 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. |75| Custom role JSON | `Name`, `IsCustom`, `Description`, `Actions`, `NotActions`, `DataActions`, `NotDataActions`, `AssignableScopes` | Include only when no suitable built-in role exists. |76| Bicep snippet | `Microsoft.Authorization/roleAssignments` with deterministic `guid()` name | Role assignment name must be stable for the same principal, role, and scope. |77| Explanation | Why the selected role is least privilege and which broader roles were rejected | Mention major excluded permissions and risk. |7879## Gotchas8081- **Reader is not data reader**: many Azure services require data-plane roles even when the identity can view the resource in the portal.82- **Contributor cannot assign roles**: access management needs role assignment permissions, commonly via Owner or User Access Administrator.83- **Scope inheritance is powerful**: subscription-scope assignments flow to every child resource; prefer the smallest scope that satisfies the requirement.84- **Custom roles need assignable scopes**: a custom role cannot be assigned outside its `AssignableScopes`.85- **Role names can be ambiguous**: use role definition IDs when generating durable automation.8687## Output template8889````markdown90## Azure role selection9192**Status:** built-in selected | custom role required | blocked93**Identity:** <principal type and identifier>94**Scope:** `<scope>`95**Plane:** control plane | data plane | both9697### Recommendation98| Role | Type | Why it matches | Broader roles rejected |99| --- | --- | --- | --- |100| `<role name or custom role name>` | built-in/custom | <required permissions covered> | <roles and reason> |101102### Assignment command103```bash104az role assignment create --assignee <principal-id> --role "<role-name-or-id>" --scope <scope>105```106107### Bicep108```bicep109resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {110 name: guid(<scope-id>, '<principal-id>', '<role-definition-id>')111 scope: <scope-symbol>112 properties: {113 principalId: '<principal-id>'114 roleDefinitionId: '<role-definition-resource-id>'115 principalType: '<User|Group|ServicePrincipal|ForeignGroup|Device>'116 }117}118```119120### Custom role definition121<include only when no built-in role matches>122````123124## Quality gate125126- [ ] The identity, scope, and required permissions are stated or listed as blockers.127- [ ] `Azure MCP/documentation` was used to compare built-in role definitions.128- [ ] The selected role is the least-privilege match and broader roles are explicitly rejected.129- [ ] Control-plane `Actions` and data-plane `DataActions` are not confused.130- [ ] `NotActions` and `NotDataActions` do not exclude required permissions.131- [ ] `Azure MCP/extension_cli_generate` was used for assignment commands and custom role definitions when needed.132- [ ] `Azure MCP/bicepschema` and `Azure MCP/get_bestpractices` were used for the Bicep snippet.133- [ ] The CLI command and Bicep snippet use the narrowest safe scope.