1. Resources
  2. Detection rules
  3. Command Run on an AKS Cluster Through Run Command

Command Run on an AKS Cluster Through Run Command detection rules

Someone runs a command inside an Azure Kubernetes Service cluster through the Azure API (command invoke), with no network path to the cluster. A pod executes it, so an Azure role becomes code execution in the cluster.

Platform
Azure
Severity
High
Log source
Azure Activity log
Last updated
Tactic
Execution
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
An Azure role with the runCommand action on the cluster, such as the Cluster Admin Role or Contributor, and a cluster where Run command is not disabled.
Impact
Code execution and administration inside the cluster from outside its network, including access to Secrets and to the managed identity of the node.
Response
Contain the caller, disable Run command on the cluster while you investigate and remove what the command created or changed.
Mitigation
Disable Run command with the disableRunCommand property where it is not needed and keep the roles that carry the action to a few identities.
Operation
MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/RUNCOMMAND/ACTION
Threat groups
TeamTNT

How the attack works

Azure Kubernetes Service (AKS) has a Run command feature, az aks command invoke in the Azure CLI, that Microsoft describes as a way to remotely invoke commands such as kubectl and helm on a cluster through the Azure API without connecting to the cluster directly. It exists for private clusters, where the API server is not reachable from outside the virtual network. Microsoft documents that AKS creates a pod to run the command, named command-<ID> in the aks-command namespace, and that the Azure RBAC actions Microsoft.ContainerService/managedClusters/runCommand/action and Microsoft.ContainerService/managedClusters/commandResults/read control who may use it. Microsoft's Azure Threat Research Matrix lists it as an execution technique (AZT301.5).

For an attacker the feature removes the network boundary of a private cluster: an Azure role on the cluster resource is enough to create workloads, read Secrets or change role bindings from anywhere, with files attached to the request if needed. A pod in the cluster can also reach the instance metadata service of its node, which Microsoft documents as accessible from all pods by default, and with it the managed identity of the node. The runCommand action is recorded in the Azure Activity log with its caller. Microsoft does not document that the command text is part of that record, and commands run directly with kubectl never pass through Azure Resource Manager, so the Activity log shows that the feature was used and by whom, not what was run.

What an attacker needs

  • A role with Microsoft.ContainerService/managedClusters/runCommand/action on the cluster or on a scope above it. The Azure Kubernetes Service Cluster Admin Role lists the action, and the Azure Kubernetes Service Contributor Role, Contributor and Owner include it through wildcards.
  • A cluster where Run command is not disabled. Microsoft documents the property apiServerAccessProfile.disableRunCommand for switching it off.
  • Kubernetes permissions for what the command does. The request can carry a cluster token that Microsoft Entra ID issued for the caller. Microsoft's reference does not state which permissions apply on a cluster without Microsoft Entra integration, so check that on your own clusters.

Impact

Code execution and administration inside the cluster from outside its network: new workloads, changed role bindings, Secrets read through the command output, and tokens of the managed identity of the node where pods are allowed to reach the instance metadata service. What the attacker creates in the cluster stays after the Azure role is removed.

Detection rules

AKS Run Command Invoked

Detects a successful use of the Run command feature of an Azure Kubernetes Service cluster (Microsoft.ContainerService/managedClusters/runCommand/action), which is what az aks command invoke and the Run command page of the portal call. AKS creates a pod in the cluster that runs the submitted command, so the caller acts inside the cluster through the Azure API with no network path to the API server. Microsoft does not document that the command text is part of the Activity log record, so the event shows that the feature was used and by whom, not what was run.

LevelMediumStatusExperimentalLog sourceAzure Activity log
title: AKS Run Command Invoked
id: ff334d18-3a43-40c2-8b39-f9ddee126ff5
status: experimental
description: >-
  Detects a successful use of the Run command feature of an Azure Kubernetes
  Service cluster
  (Microsoft.ContainerService/managedClusters/runCommand/action), which is
  what az aks command invoke and the Run command page of the portal call.
  AKS creates a pod in the cluster that runs the submitted command, so the
  caller acts inside the cluster through the Azure API with no network path
  to the API server. Microsoft does not document that the command text is
  part of the Activity log record, so the event shows that the feature was
  used and by whom, not what was run.
references:
  - https://attack.mitre.org/techniques/T1609/
  - https://learn.microsoft.com/en-us/azure/aks/access-private-cluster
  - https://learn.microsoft.com/en-us/rest/api/aks/managed-clusters/run-command
  - https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/containers
author: Forestall
date: 2026-11-18
tags:
  - attack.execution
  - attack.t1609
logsource:
  product: azure
  service: activitylogs
detection:
  selection:
    OperationNameValue: MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/RUNCOMMAND/ACTION
    ActivityStatusValue:
      - Success
      - Succeeded
  condition: selection
falsepositives:
  - Platform engineers and pipelines that manage private clusters through Run command because they have no network path to the API server. Exclude their identities in a filter_ selection by Caller once confirmed, per cluster where possible.
  - People who run kubectl commands from the Run command page of the Azure portal for troubleshooting. Baseline the callers for each cluster.
level: medium

False positives

  • Platform engineers and pipelines that manage private clusters through Run command because they have no network path to the API server. Exclude their identities in a filter_ selection by Caller once confirmed, per cluster where possible.
  • People who run kubectl commands from the Run command page of the Azure portal for troubleshooting. Baseline the callers for each cluster.

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.

Cluster updated and Run command used by the same caller shortly after

Detection hypothesisSequence of events

Where Run command is disabled, an attacker with write access to the cluster first updates the cluster to allow it again and then uses it. A write to the cluster followed by the runCommand action by the same caller shows the control being removed and the feature being used in order.

  1. In the Azure Activity log, the cluster is updated with status Success: MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/WRITE. Keep the Caller and the resource ID of the cluster.
  2. Within 60 minutes the same Caller runs MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/RUNCOMMAND/ACTION on the same cluster.
  3. Read the current apiServerAccessProfile.disableRunCommand property of the cluster, because the write event does not say which property changed.

EventsMICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/WRITEMICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/RUNCOMMAND/ACTION

LimitsAn engineer who upgrades or reconfigures a private cluster and then checks it with Run command looks the same, so the platform team has to be excluded by name. The 60 minutes are a starting point. An attacker who uses two identities for the two steps does not match.

Triage

  • Identify the Caller, the caller's IP address and the cluster, and whether this identity uses Run command routinely. On private clusters it can be the normal way of working.
  • Ask the caller what was run, and compare the answer with the cluster. The Activity log does not give the command.
  • Look in the kube-audit logs, if they are collected, for the pod created in the aks-command namespace at that time and for the requests that followed it.
  • Review what changed in the cluster after the event, such as new workloads, role bindings, service accounts and Secrets.
  • Review how the caller holds its role, and whether the role was assigned shortly before the command.

Response

Once the attack is confirmed:

  1. Contain the caller. Revoke its sessions, rotate its credentials and remove the role that carries the runCommand action until the use is explained.
  2. Disable Run command on the cluster while you investigate, if operations do not depend on it.
  3. Remove what the command created or changed in the cluster, such as workloads, role bindings, service accounts and their tokens.
  4. Rotate the Secrets that the command could read, and review the activity of the node and workload managed identities from the time of the command.
  5. Rotate the cluster certificates if the investigation shows that cluster credentials were read or created.

Mitigation

  • Disable Run command on clusters that do not need it by setting apiServerAccessProfile.disableRunCommand to true.
  • Keep the Azure Kubernetes Service Cluster Admin Role, the Azure Kubernetes Service Contributor Role, Contributor and Owner on clusters to a few identities, and assign them through Privileged Identity Management.
  • Use Microsoft Entra integration with Kubernetes RBAC or Azure RBAC for Kubernetes, so that what a caller can do in the cluster is limited by the caller's own permissions.
  • Create a diagnostic setting on every cluster that collects the kube-audit or kube-audit-admin category, so that the pods and requests behind a command can be traced.
  • Give the managed identities of the cluster and its nodes only the roles they need, and restrict pod access to the instance metadata service where the feature is available to you.

Frequently asked questions

Does the Activity log show which command was run?

Microsoft does not document that the command text is part of the Activity log record. The event gives the operation, the cluster and the caller. To learn what happened, read the kube-audit resource logs of the cluster, where a diagnostic setting collects them, starting with the pod that AKS created in the aks-command namespace, and compare the cluster with its expected state.

Are commands run with kubectl covered by this rule?

No. The rule reads the Azure Resource Manager action behind az aks command invoke and the Run command page of the portal. A person who connects to the API server with a kubeconfig and runs kubectl does not pass through Azure Resource Manager, so nothing is written to the Activity log. Those requests are in the kube-audit logs of the cluster.

Why does a private cluster not protect against this?

A private cluster keeps the API server off the public network. Run command was built to reach such clusters without a VPN or ExpressRoute. The request goes to the Azure API and AKS creates a pod inside the cluster that runs the command. The control is therefore the Azure role on the cluster, or disabling the feature with the disableRunCommand property.

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. Microsoft's Azure Threat Research Matrix lists AKS command invoke as an execution technique, and Microsoft's documentation describes the feature and the Azure RBAC actions that control it.

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.