An attacker runs code on a virtual machine (VM), or abuses a server-side request forgery flaw in an app on it. The attacker requests a managed identity token from http://169.254.169.254/metadata/identity/oauth2/token and replays it from their own machine. Remove the identity's role assignments first, because Azure caches its tokens for about 24 hours with no way to force a refresh, then hunt for the identity's calls from addresses the workload never uses.
Look here
Log
Search for
AADManagedIdentitySignInLogs
Tokens issued for new target resources: AADManagedIdentitySignInLogs | where ServicePrincipalId == "<principal-id>" | summarize count() by ResourceDisplayName, bin(TimeGenerated, 1h)
AzureActivity
Management calls by the identity from unexpected addresses: AzureActivity | where Caller == "<principal-id>" | summarize count() by CallerIpAddress, OperationNameValue
StorageBlobLogs
Blob calls by the identity from unexpected addresses. The CallerIpAddress value includes the port: StorageBlobLogs | where RequesterObjectId == "<principal-id>" and AuthenticationType == "OAuth" | summarize count() by CallerIpAddress
MicrosoftGraphActivityLogs
Graph calls by the identity, by address: MicrosoftGraphActivityLogs | where ServicePrincipalId == "<principal-id>" | summarize count() by IPAddress
AzureActivity, code execution
How the attacker got code execution, under Microsoft.Compute/virtualMachines: runCommand/action, runCommands/write (managed Run Command) and extensions/write
AzureActivity, persistence
Federated credentials added to the identity, logged as: Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write
Record the identity's roles in each subscription: az role assignment list --assignee <principal-id> --all
3
Record its roles at management group scope: az role assignment list --assignee <principal-id> --scope /providers/Microsoft.Management/managementGroups/<mg>
4
Remove those role assignments: az role assignment delete --ids <assignment-id>
5
Isolate the VM with a network security group that denies all traffic except the forensics subnet, per the cloud scenario
6
Detach a user-assigned identity from the VM: az vm identity remove -g <rg> -n <vm> --identities <identity-id>
7
List the identity's federated credentials: az identity federated-credential list --identity-name <identity> -g <rg>
8
Delete federated credentials you did not create destructive: az identity federated-credential delete --name <fic> --identity-name <identity> -g <rg> --yes
Eradicate and recover
#
Item
1
Rebuild the VM from a known-good image and retire the compromised one after evidence release
2
Fix the app flaw that reached the metadata endpoint, and check whether the app forwards a caller-supplied Metadata: true header
3
Grant the rebuilt workload a user-assigned identity with the fewest roles it needs, assigned directly to the identity
4
Keep watching the identity's calls for at least 24 hours after role removal
Watch out
Azure caches managed identity tokens for around 24 hours and offers no way to force a refresh. Group membership changes can take hours to apply, so remove direct role assignments.
Conditional Access for workload identities excludes managed identities.
Microsoft Learn: managed identities FAQ and best practice recommendations, including token caching; Conditional Access for workload identities; AADManagedIdentitySignInLogs, AzureActivity, StorageBlobLogs and MicrosoftGraphActivityLogs table references; resource provider operations for Compute and Managed Identity; Azure CLI reference for az role assignment, az vm identity and az identity federated-credential. Checked October 2026.