Azure CLI field notes. az ad remains the CLI command group; Azure AD is now Microsoft Entra ID.
| Workload | Preferred identity |
|---|---|
| Azure-hosted service | System- or user-assigned managed identity |
| External CI/CD | Workload identity federation (OIDC), no stored client secret |
| Legacy/non-federated automation | Service principal with certificate; rotate credentials |
An app registration defines the application; its service principal is the tenant-local identity. Azure RBAC assignments authorize access to Azure resources. Microsoft Entra directory roles are separate.
az account show --query "{tenant:tenantId,subscription:id}" -o json
az ad sp list --display-name "<name>" --query "[].{appId:appId,objectId:id}" -o table
az ad sp show --id "<app-id>"
az role assignment list --assignee "<sp-object-id>" --all -o table
Prefer managed identity or OIDC federation. When a service principal is required:
az ad sp create-for-rbac --name "<name>"
az role assignment create --assignee "<app-id>" --role Reader --scope "/subscriptions/<subscription-id>/resourceGroups/<rg>"
Note: create-for-rbac can emit a credential. Do not log or commit its output. Assign the narrowest role at the narrowest scope; avoid subscription-wide Contributor by default.
Configure a federated identity credential on the app registration or user-assigned managed identity. Match issuer, subject, and audience to the trusted workload. For GitHub Actions, grant id-token: write and use azure/login@v2 with client, tenant and subscription IDs. Restrict the subject to the intended branch or environment; protect deployment environments separately.