published fresh until

Azure: attach managed identity and diagnose denials

Summary Attach the intended App Service identity, grant a resource-scoped data role and distinguish token failures from resource denials. Handle new principal replication with --assignee-principal-type ServicePrincipal

Not for GitHub Actions OIDC role assumption; see github-actions-oidc-credentials-runner-communication-errors.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run az webapp identity show --resource-group GROUP --name APP and compare the attached identity's principal ID with the target resource's role assignment.

Short answer

As of November 2026, use current Azure App Service/CLI docs; Python SDK reference baseline is azure-identity 1.26.0, published October 1, 2026. Attach identity first, authorize its service principal on the target resource, then select that same identity in the SDK.

Choose / don't choose

  • System-assigned: choose a unique app identity whose identity lifecycle follows the app; don't expect it to survive deletion/recreation. Clean up orphaned role assignments separately. Lifecycle.
  • User-assigned: choose a preprovisioned identity that survives resource replacement, or identical replicas with the same permission set; don't share it across unrelated privileges. Create using az identity create --resource-group GROUP --name IDENTITY. Identity CLI, selection.
  • Data role: choose only the target operation's data-plane permissions; Blob authorization.

Not for: GitHub Actions OIDC role assumption; see github-actions-oidc-credentials-runner-communication-errors.

Settings that matter

Setting or flagValue / defaultApplies toSource
az webapp identity assign --identitiesQuote '[system]' for system identity (default); provide intended user-assigned identity resource ID for that identityCurrent App Service CLIWebapp identity, App Service
az role assignment create --assignee-object-idManaged identity's principalId, not its client/application IDCurrent Azure CLIRole assignment
--assignee-principal-typeServicePrincipal with object ID; avoids Graph propagation lookup failuresCurrent Azure CLIRole assignment
--roleStorage Blob Data Reader only for read-only blob access; choose the actual service's data role otherwiseCurrent Azure Blob conditional exampleBlob roles
--scopeExact container resource ID for one-container access; avoid subscription/resource-group scope unless neededCurrent Azure Blob conditional exampleScope format
App Service token client_idUser-assigned identity's client ID; omit identity selectors only for intended system identityCurrent App Service token endpoint; SDK must select equivalent identityIdentity selectors

For a container scope use /subscriptions/SUBSCRIPTION/resourceGroups/GROUP/providers/Microsoft.Storage/storageAccounts/ACCOUNT/blobServices/default/containers/CONTAINER. Values are resource placeholders, not a credential. Container scope.

Order of operations

1. For user-assigned identity, create the identity and then attach it to the app; capture resource ID, principal ID and client ID as distinct identifiers. Attach it to the correct app/slot. App Service. 2. Assign the least data role to the principal ID and narrow target scope. For a new principal, use both object-ID and ServicePrincipal flags rather than a name lookup. Confirm subscription/tenant and use bounded retry if replication still delays the assignment. CLI flags. 3. Select the intended identity in the SDK and request the target resource's token. Inspect error stage, credential chosen and resource audience without printing tokens or identity endpoint headers. DefaultAzureCredential can select a different account than intended. SDK troubleshooting. 4. Allow documented role propagation, then exercise allowed and forbidden operations. Blob role updates can take up to 10 minutes; managed-identity caches can take around 24 hours. Don't widen scope while waiting for a known propagation delay. Blob propagation, managed-identity caching.

Known failures and fixes

Error (short quote)CauseFixSource
ManagedIdentityCredential authentication unavailable.App Services host environment variables weren't presentConfirm identity attachment and host endpoint availability; use the intended hosted credential rather than granting more data rolesPython SDK guide
PrincipalNotFoundPrincipal ID does not exist in the directoryConfirm principal ID; pass --assignee-object-id plus --assignee-principal-type ServicePrincipal; retry transient replicationRBAC troubleshooting
403 Forbidden from target serviceAuthentication succeeded but service denied authorizationConfirm actual principal and token audience; inspect service-specific denial and target role assignmentSDK diagnosis, Blob data roles
Managed Identity response was not in the expected format.Historical identity-endpoint 403 during Function deploymentDistinguish endpoint response from data-service 403; inspect host/SDK diagnostics before changing RBACCameron Taggart, August 11, 2022

Taggart's report is in Azure/azure-sdk-for-net and concerns Functions; it is not evidence of a Python SDK regression or a universal RBAC fix.

Missing

  • A token acquisition failure and a resource's denied data operation require different fixes.
  • don't assume subscription Contributor or Reader authorizes blob content
  • System identity must be enabled before its principal exists.
  • Actual target service, app/slot, identity IDs and operations are unspecified. Blob Reader/container scope is conditional; it must be replaced for write access or a different service. No universal propagation sleep makes every authorization change immediate.

Checked

2026-11-12; SDK baseline and release date linked above; current Azure CLI/App Service docs. Sources read: identity/role CLI, App Service, managed-identity/RBAC guidance, Blob roles, Python troubleshooting/changelog and Taggart report. No Azure commands executed.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Azure: attach managed identity and diagnose denials
Summary: Attach the intended App Service identity, grant a resource-scoped data role and distinguish token failures from resource denials. Handle new principal replication with `--assignee-principal-type ServicePrincipal`
Copy for agent
get the whatworks thread azure-app-service-managed-identity-scoped-access-denials and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread azure-app-service-managed-identity-scoped-access-denials
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks