Over-Privileged Managed Identity

A managed identity attached to a VM, app or automation resource holds far broader roles than its workload needs, so anyone who runs code on that resource inherits those rights.

SeverityHigh
CVSS 3.17.5 CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.07.7 CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-250: Execution with Unnecessary Privileges
MITRE ATT&CKT1552.005 Cloud Instance Metadata API, T1078.004 Cloud Accounts, T1098.003 Additional Cloud Roles
CategoryBroken Access Control

Description

Managed identities give Azure resources, such as virtual machines, App Service and Functions apps, Automation accounts, Logic Apps and container workloads, an identity in Microsoft Entra ID without stored credentials. Code running on the resource requests tokens for the identity from a local endpoint: the Instance Metadata Service at 169.254.169.254 on virtual machines, or the endpoint named in the IDENTITY_ENDPOINT environment variable on App Service and Functions. Whatever roles the identity holds are therefore available to any code, and any person, able to run commands on the resource, so users who can do so, for example through VM Run Command or a code deployment, can escalate to the identity's privileges.

The finding applies where an identity holds far more than its workload needs. Common examples are Owner, Contributor or User Access Administrator at subscription or resource group scope; broad data roles such as Key Vault Administrator or Storage Blob Data Owner across many resources; Microsoft Graph application permissions that can change the directory or assign roles; and one user-assigned identity shared by many unrelated resources.

An attacker who gains code execution on the resource, through a vulnerability in the application, server-side request forgery that can reach the token endpoint with the required header, or a stolen deployment credential, can obtain tokens for the identity and use them from anywhere until they expire. With Owner or Contributor at subscription scope they can read and change every resource in the subscription, extract secrets and data and deploy their own resources, and with Owner or User Access Administrator they can grant access to other identities for persistence. The impact is limited where the identity's roles are narrow and scoped to the resources the workload uses.

The weakness is identified by listing each identity's Azure role assignments at every scope, its Microsoft Graph application permissions and any directory roles, and by mapping who can run code on the resources that use it. Tools such as AzureHound show these paths. During a test, a token is typically requested from the endpoint on a compromised resource and used to enumerate what the identity can do.

Remediation

  • Inventory every managed identity with its Azure role assignments at all scopes, Microsoft Graph application permissions and directory roles, and record what each workload actually needs.
  • Replace broad roles with the narrowest built-in or custom role at the narrowest scope, for example Storage Blob Data Reader on one storage account or Key Vault Secrets User on one vault, rather than Contributor on a subscription.
  • Remove Owner, User Access Administrator and high-impact Graph permissions from workload identities unless the workload's purpose genuinely requires them, and document any exception.
  • Give each workload its own identity rather than sharing one user-assigned identity across unrelated resources.
  • Treat the ability to run code on a resource as equivalent to holding its identity: restrict the roles that allow VM Run Command, extension installation, code deployment and runbook editing on resources with privileged identities.
  • Fix server-side request forgery and code execution weaknesses in the workloads, and monitor managed identity sign-in logs and the Activity Log for unexpected actions.
az role assignment list --assignee "$PRINCIPAL_ID" --all --output table

Confirm the fix by listing the identity's role assignments again and, with a token obtained on the resource, checking that actions outside the workload's needs are refused.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Azure and Microsoft 365 Findings

Every Azure and Microsoft 365 finding