1. Resources
  2. Detection rules
  3. Deployment Script Created to Run Code as a Managed Identity

Deployment Script Created to Run Code as a Managed Identity detection rules

Someone creates an Azure deployment script. It runs a script in a temporary container under a user-assigned managed identity that the caller selects, so the caller acts with the roles of that identity.

Platform
Azure
Severity
High
Log source
Azure Activity log
Last updated
MITRE ATT&CK technique
T1648Serverless Execution
Tactic
Execution
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
Rights to deploy a deployment script and to assign a user-assigned managed identity, through Managed Identity Operator, Contributor or Owner on that identity.
Impact
Code execution with the Azure roles of the selected managed identity, which can be far broader than the roles of the caller.
Response
Contain the caller, undo what the managed identity did from the time of the script onward and reduce the roles of that identity.
Mitigation
Limit who can assign privileged user-assigned managed identities and deny the deployment script resource type where it is not used.
Operation
MICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITE
Threat groups
None listed in MITRE ATT&CK for this technique

How the attack works

A deployment script (Microsoft.Resources/deploymentScripts) is a resource that runs an Azure PowerShell or Azure CLI script as part of a template deployment. Microsoft documents that the deployment script service creates two supporting resources to run it, a storage account and a container instance, and that the caller can name a user-assigned managed identity in the identity property. When one is named, the service signs in with that identity before it invokes the script, and the identity must hold whatever access the script needs. The script itself is supplied inline or from a URL.

The feature lets a principal borrow an identity. Microsoft states that the deploying principal needs the Managed Identity Operator role on the managed identity, and broader roles on the identity or its resource group include the same right. A principal that may create deployment scripts and may assign an existing user-assigned identity therefore runs its own code with the roles of that identity, which can be far wider than its own, for example Owner on a subscription that the principal cannot even read. NetSPI described this path in March 2024. The create operation Microsoft.Resources/deploymentScripts/write is recorded in the Azure Activity log with its caller. The log does not contain the script or the identity it ran as, and the evidence in the resource group does not last: by default the supporting resources are deleted once the run reaches a final state, and the script resource is deleted when its retention interval expires.

What an attacker needs

  • Rights to deploy a deployment script in some resource group. Microsoft's least-privilege example for the deploying principal contains Microsoft.Resources/deploymentScripts/*, Microsoft.Resources/deployments/*, Microsoft.Storage/storageAccounts/* and Microsoft.ContainerInstance/containerGroups/*.
  • The right to assign the target identity: the Managed Identity Operator role on the user-assigned managed identity, or a broader role such as Contributor or Owner on the identity or its resource group.
  • A user-assigned managed identity that holds roles worth having.

Impact

Code execution with the Azure roles of the selected managed identity, and with any Microsoft Graph or other API permissions that identity was granted. From there the attacker assigns roles, reads secrets or changes resources as that identity. The traces in the resource group are short-lived, because the script resource and its container and storage account are cleaned up.

Detection rules

Azure Deployment Script Created or Updated

Detects a successful create or update of a deployment script (Microsoft.Resources/deploymentScripts/write). A deployment script runs an Azure PowerShell or Azure CLI script in a temporary container, and when its identity property names a user-assigned managed identity the script runs signed in as that identity. The caller therefore acts with the roles of the identity, which can be broader than its own. Microsoft does not document that the script or the identity is part of the Activity log record, so read the deployment script resource before the service removes it. Deployment scripts are common in infrastructure templates, so baseline the callers and the resource groups.

LevelMediumStatusExperimentalLog sourceAzure Activity log
title: Azure Deployment Script Created or Updated
id: a7cce56f-1fbe-48ac-832a-d12b45f3de5f
status: experimental
description: >-
  Detects a successful create or update of a deployment script
  (Microsoft.Resources/deploymentScripts/write). A deployment script runs an
  Azure PowerShell or Azure CLI script in a temporary container, and when its
  identity property names a user-assigned managed identity the script runs
  signed in as that identity. The caller therefore acts with the roles of the
  identity, which can be broader than its own. Microsoft does not document
  that the script or the identity is part of the Activity log record, so read
  the deployment script resource before the service removes it. Deployment
  scripts are common in infrastructure templates, so baseline the callers and
  the resource groups.
references:
  - https://attack.mitre.org/techniques/T1648/
  - https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template
  - https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/management-and-governance
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1648
logsource:
  product: azure
  service: activitylogs
detection:
  selection:
    OperationNameValue: MICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITE
    ActivityStatusValue:
      - Success
      - Succeeded
  condition: selection
falsepositives:
  - Infrastructure-as-code pipelines and landing zone deployments whose templates contain deployment scripts. Exclude the pipeline identities in a filter_ selection by Caller once confirmed.
  - Engineers who test a template by hand. Match the event to a change record and check which identity the script named.
level: medium

False positives

  • Infrastructure-as-code pipelines and landing zone deployments whose templates contain deployment scripts. Exclude the pipeline identities in a filter_ selection by Caller once confirmed.
  • Engineers who test a template by hand. Match the event to a change record and check which identity the script named.

Detection logic

Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.

Deployment script created, then operations by the managed identity it ran as

Detection hypothesisSequence of eventsJoins two logsNeeds your own lists

The create event alone does not show abuse, because pipelines create deployment scripts all the time. What shows it is the identity of the script doing things the caller could not do itself, such as assigning a role, in the minutes after the script was created.

  1. In the Azure Activity log, a deployment script is created with status Success: MICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITE. Keep the Caller, the time and the resource ID.
  2. Read the user-assigned managed identity from the identity property of the deployment script resource, or from the template in the deployment history, and look up its principal ID.
  3. Take the Activity log events of the next 60 minutes whose Caller is that principal ID. Microsoft documents that the Caller of an operation made by a service principal is its object ID.
  4. Review those events, and give priority to MICROSOFT.AUTHORIZATION/ROLEASSIGNMENTS/WRITE and to operations in subscriptions where the caller of the first step holds no role.

EventsMICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITEMICROSOFT.AUTHORIZATION/ROLEASSIGNMENTS/WRITE

LimitsA legitimate deployment script also acts through its identity, for example to assign a role that the template needs, so known pipelines and their templates have to be excluded. The second step fails once the script resource is deleted and the deployment history is gone. The 60 minutes are a starting point.

Deployment script created and deleted again by the same caller shortly after

Detection hypothesisSequence of events

A deployment that is part of normal infrastructure work leaves its script resource to the service, which removes it after the retention interval. A caller that creates a deployment script and deletes it by hand a few minutes later is removing the one resource that names the identity and holds the script.

  1. In the Azure Activity log, a deployment script is created with status Success: MICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITE. Keep the Caller and the resource ID.
  2. Within 60 minutes the same Caller deletes the same resource: MICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/DELETE with status Success.
  3. Recover what the script was from the deployment history of the resource group, if the deployment was not deleted as well.

EventsMICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/WRITEMICROSOFT.RESOURCES/DEPLOYMENTSCRIPTS/DELETE

LimitsPipelines that tear down what they deployed delete script resources too. Microsoft does not document under which caller the automatic clean-up by the service is logged, so check the Caller values in your own log before you rely on this. The 60 minutes are a starting point.

Triage

  • Identify the Caller, the caller's IP address and the resource group from the event, and whether this identity deploys templates with deployment scripts routinely. Infrastructure pipelines do.
  • Read the deployment script resource while it still exists and note the identity it names, the script content or its URL and the output. Microsoft documents a retention interval of 1 to 26 hours after which the resource is deleted.
  • Look for the supporting resources in the resource group. Microsoft documents that their names end in azscripts.
  • List the roles of the user-assigned identity the script used, in every subscription, and compare them with the roles of the caller.
  • Review the Activity log for operations whose caller is that identity from the time of the script onward, especially role assignments and credential changes.

Response

Once the attack is confirmed:

  1. Contain the caller. Revoke its sessions, rotate its credentials and remove its rights to deploy and to assign managed identities until the script is explained.
  2. Undo what the managed identity did from the time of the script onward. Role assignments, new credentials on applications and identities, and new resources come first.
  3. Reduce the roles of the managed identity to what its workload needs, or delete it if nothing legitimate uses it.
  4. Add federated credentials on the identity to the review, and remove those you cannot account for.
  5. Preserve the deployment script resource, its logs and the deployment history before the retention interval removes them.

Mitigation

  • Treat the right to assign a user-assigned managed identity as the right to act as it. Limit Managed Identity Operator, Contributor and Owner on privileged identities and on the resource groups that hold them.
  • Keep privileged user-assigned identities in a dedicated resource group that ordinary contributors cannot write to.
  • Give each user-assigned identity only the roles its workload needs, and delete identities that are no longer attached to anything.
  • Where deployment scripts are not used, deny the resource type Microsoft.Resources/deploymentScripts with Azure Policy. Where they are used, allow them only for the deployment pipelines.
  • Send the Azure Activity log of every subscription to your SIEM, so that the create event outlives the script resource.

Frequently asked questions

Does the Activity log show which identity the deployment script ran as?

Microsoft does not document that the identity is part of the Activity log record. The event gives the operation, the caller and the resource ID of the deployment script. The identity is a property of the script resource, which exists only for a limited time after the run, so read it early or take it from the template in the deployment history.

Why is creating a deployment script a privilege escalation?

The script does not run as the person who deploys it. When the identity property names a user-assigned managed identity, the deployment script service signs in with that identity before it invokes the script. A principal that can deploy the script and assign the identity acts with the roles of the identity, which may be broader than its own.

Which roles allow a principal to use an identity in a deployment script?

Microsoft states that the deploying principal needs the Managed Identity Operator role assigned on the managed identity resource. Roles that include every action on the identity or on its resource group, such as Contributor and Owner, cover the same right. Review who holds these roles on privileged identities.

Is there a public incident report for this technique?

No public incident report describes this at the audit event level as far as this page's sources go. The technique was described by NetSPI in March 2024 as security research, and Microsoft's documentation describes the identity property and the role the deploying principal needs.

References

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.