Skip to content

LearnCloud

Azure managed identity and automation review

Brief

A managed identity has no password to steal, so the risk moves to whoever can run code on the resource that carries it: edit the runbook, change the Logic App or run a command on the VM, and the code runs with the identity's roles. The review lists every identity, its roles in Azure and Microsoft Graph, what runs as it, and who can change that code.

Track
Cloud
Stage
Escalation
Reviewed
On this page
  1. Check first
  2. Azure
  3. The defender sees
  4. Done when
  5. Not covered
  6. Tools
  7. Related research
  8. Where this page fits
  9. Reviewed

All commands

Situation
Reader on the subscriptions in scope and Application.Read.All in Entra ID, with the Azure CLI and its resource-graph, automation and logic extensions. Every command on this page is a read: we never start a runbook, edit a workflow, run a command on a VM or request a token as an identity, and we review only the subscriptions and tenant the scope letter names.
Goal
An identity table: each managed identity, the resource that carries it, its Azure roles and Graph permissions, what runs as it, and which principals can change that code.
Outputs
Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.

Check first

  • The subscriptions in scope, and whether the review role sees all of them.
  • The client's list of automation: Automation accounts, Logic Apps, Function Apps and VMs that run scheduled jobs.
  • Which identities the client expects to hold Contributor, Owner or Graph write permissions, written down first.
  • Whether runbook source is in a repository, so we read it there instead of in the portal.
  • Where the Activity log and Entra sign-in logs are exported.

Steps

Azure

Which resources carry a managed identity?

az graph query --first 1000 -o table -q "Resources
  | where isnotempty(identity) | extend kind = tostring(identity.type)
  | project name, type, kind, resourceGroup"

Expected output

Name             Type                                     Kind                          ResourceGroup
---------------  ---------------------------------------  ----------------------------  ---------------
aa-ops           microsoft.automation/automationaccounts  SystemAssigned                rg-ops   # <- runbooks here run as this identity
la-invoice-sync  microsoft.logic/workflows                SystemAssigned, UserAssigned  rg-integration
vm-build-01      microsoft.compute/virtualmachines        UserAssigned                  rg-build

A system-assigned identity lives and dies with its resource. A user-assigned identity is a resource of its own that can be attached to many resources, so one identity's roles can be reachable from several places. We list user-assigned identities too, with where type =~ 'microsoft.managedidentity/userassignedidentities', and note every resource each is attached to.

Negative result. Only the resources on the client's list carry an identity, and no user-assigned identity is attached to more resources than its owners expect.

Fix. Remove identities from resources that no longer call anything, and prefer one user-assigned identity per workload over one shared across many.

What roles does each identity hold?

az role assignment list --assignee 5c1e7a90-2b3d-4f6a-8e1c-0d9f2a4b6c81 --all \
  --query '[].[roleDefinitionName,scope]' -o tsv

Expected output

Contributor	/subscriptions/00000000-1111-2222-3333-444444444444   # <- the runbook identity can change anything in the subscription
Key Vault Secrets User	/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-ops/providers/Microsoft.KeyVault/vaults/kv-ops
Connect-MgGraph -Scopes 'Application.Read.All' -NoWelcome
$graph = Get-MgServicePrincipal -Filter "appId eq '00000003-0000-0000-c000-000000000000'"
Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId '5c1e7a90-2b3d-4f6a-8e1c-0d9f2a4b6c81' -All |
  ForEach-Object { $id = $_.AppRoleId; ($graph.AppRoles | Where-Object Id -eq $id).Value }

Expected output

Group.ReadWrite.All   # <- can add any principal to any group that is not role-assignable, including groups holding Azure roles

The id is the identity's principal id from the resource's identity block. Azure roles and Microsoft Graph permissions are separate: a managed identity granted Graph application permissions holds them tenant-wide with no user present. Both sets go in the table.

Negative result. Each identity holds only the roles its job needs, scoped to the resources it touches, and no Graph write permission beyond what the client can explain.

Fix. Replace subscription-wide Contributor with a narrow role on the resource group or resource, and remove Graph application permissions the automation does not call.

What runs as the identity?

az automation runbook list --automation-account-name aa-ops --resource-group rg-ops \
  --query '[].[name,runbookType,state]' -o tsv
az logic workflow show --resource-group rg-integration --name la-invoice-sync --query definition -o json \
  | jq -r '(.triggers + .actions) | to_entries[] | [.key, .value.type, (.value.inputs.authentication.type // "-")] | @tsv'

Expected output

Rotate-Certs	PowerShell72	Published
Sync-Groups	PowerShell	Published
manual	Request	-   # <- an HTTP trigger: anyone with the callback URL starts a run
Post_to_ledger	Http	ManagedServiceIdentity

Every published runbook in the account can authenticate as its identity, so the identity's roles are the most any runbook author can reach. A Logic App with a Request trigger runs whenever its callback URL is called, and the URL carries its own signature, so whoever holds the URL starts a run as the identity. We read runbook source for what it calls, and we record variable and credential asset names, never values.

Negative result. Runbooks and workflows match the client's list, each calls only what its job needs, and HTTP triggers are restricted to known callers.

Fix. Split automation that needs different rights into separate accounts with separate identities, and restrict Logic App triggers with caller IP ranges or Entra authorization policies.

Who can run code on the resource that carries the identity?

az role assignment list --scope /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/rg-ops/providers/Microsoft.Automation/automationAccounts/aa-ops \
  --include-inherited --query '[].[principalName,principalType,roleDefinitionName]' -o tsv

Expected output

platform-admins	Group	Owner
ops-engineers	Group	Automation Contributor   # <- can edit a runbook that runs as Contributor on the subscription
svc-reporting	ServicePrincipal	Reader

This is the escalation path: Automation Contributor on one account reaches Contributor on the whole subscription through the runbook. The same reading applies to Logic App Contributor on a workflow, Website Contributor on a Function App, Virtual Machine Contributor through run command, and Managed Identity Operator on a user-assigned identity, which lets the holder attach it to a resource they control. We record each path and never exercise it.

Negative result. Everyone who can change code on the resource already holds at least the identity's own roles.

Fix. Treat write access to an automation resource as write access to everything its identity reaches, and grant it only to the people who hold those rights already. The cloud first hour covers the wider Azure role review.

The defender sees

Our reads leave little: Resource Graph queries and role assignment reads are not written to the Activity log, which records writes and actions, and our Graph sign-in appears in the Entra sign-in log. The events that matter are the ones an attacker on this path would cause: Microsoft.Automation/automationAccounts/runbooks/write and jobs/write, Microsoft.Logic/workflows/write, Microsoft.Compute/virtualMachines/runCommand/action and Microsoft.ManagedIdentity/userAssignedIdentities/assign/action, each from someone other than the deployment pipeline. Managed identity token use appears in the managed identity sign-in log. If none of those alert, editing a runbook is a silent route to subscription control.

Done when

Every resource with an identity is listed, each identity's role assignments and Graph app roles are recorded, every runbook and workflow that runs as a privileged identity is named, and each path from a lower role to the identity's roles is written down.

Not covered

Service principals with secrets (see the cloud persistence audit), workload identity federation from CI (see CI pipeline trust), and AKS pod identities; the outputs shown are representative examples on a placeholder tenant, not captured runs.