Impersonating users in an AAD-enabled Azure Kubernetes Service (AKS) enables administrators to act on behalf of other users, making management easier and operations smoother. When teams use impersonation effectively, they can simulate user roles, test access controls, and troubleshoot permission-related issues, all of which help ensure a secure and efficient Kubernetes environment. Additionally, auditing impersonation actions is crucial for organizations to track user activities, promoting transparency and accountability.
This article shows you how to:
How to impersonate other users in AAD-enabled AKS cluster, including both ABAC and non-ABAC scenario.
Use Log Analytics Workspace to check impersonation history.
Kubernetes v1.35.0 was released on Dec 18, 2025. As of now (Jan 16, 2026), your client version is likely not upgraded to the latest version required to meet the requirement.
Version 1.35.0 introduces--as-user-extra flag in kubectl, which is mandatory for impersonation in ABAC-enabled AKS cluster. So, be sure to check your kubectl version using the command below:
Terminal window
1
kubectlversion
If you are using Azure Cloud Shell, you can use the following command to overwrite the embedded kubectl:
Before performing impersonation, you may want to verify the type of AKS cluster you are using.
To check if your AKS cluster is AAD-enabled, use the command below:
Terminal window
1
azaksshow-n${aks}-g${rG}--queryaadProfile
If the result is null (empty, nothing), this article is not applicable to your AKS cluster, as it is not AAD-enabled. If the result is anything else, then your AKS cluster is AAD-enabled.
To check if your AKS cluster is ABAC-enabled, use the command below:
azroleassignmentcreate--role"Azure Kubernetes Service RBAC Reader"\
2
--assignee-object-id${externalUserId}-onone\
3
--scope${aksId}--assignee-principal-typeUser
TIP
If you are practising this on a newly created AKS cluster and haven’t granted yourself permission, remember to assign RBAC Cluster Admin role to yourself:
azroleassignmentcreate--role"Azure Kubernetes Service RBAC Cluster Admin"\
4
--assignee-object-id${userObjectId}-onone\
5
--scope${aksId}--assignee-principal-typeUser
You also need to run the command kubelogin remove-cache-dir to clear the cached token and force a refresh of the token to update permissions, especially after granting yourself permissions recently.
no - User does not have access to the resource in Azure. Update role assignment to allow access.
TIP
If you still need to use RBAC to control who can impersonate users in ABAC-enabled AKS cluster, here is the ClusterRole manifest that you can refer to:
The command below will grant the newly created account access to pods:
Terminal window
1
<<EOFkubectlapply-f-
2
apiVersion: rbac.authorization.k8s.io/v1
3
kind: ClusterRole
4
metadata:
5
name: pod-access-role
6
rules:
7
- apiGroups: [""]
8
resources: ["pods"]
9
verbs: ["get", "list"]
10
---
11
apiVersion: rbac.authorization.k8s.io/v1
12
kind: ClusterRoleBinding
13
metadata:
14
name: access-to-pod
15
subjects:
16
- apiGroup: rbac.authorization.k8s.io
17
kind: User
18
name: ${externalUserId}
19
roleRef:
20
apiGroup: rbac.authorization.k8s.io
21
kind: ClusterRole
22
name: pod-access-role
23
EOF
TIP
If you are practising this on a newly created AKS cluster and haven’t granted yourself permission, you can first use the “masterclient” admin account by running the following command:
Terminal window
1
azaksget-credentials-n${aks}-g${rG}--admin
Then, grant yourself impersonation and Pod/ClusterRole/ClusterRoleBinding creation permissions by using the following commands:
Then, switch back to your logged-in account and retry the steps in this section:
Terminal window
1
azaksget-credentials-n${aks}-g${rG}
Impersonating as the newly-create account
Terminal window
1
kubectlauthcan-igetpod--as${externalUserId}
2
kubectlauthcan-igetsecret--as${externalUserId}
Output:
1
yes
2
no
TIP
Do you notice the difference in impersonation between ABAC and non-ABAC environments? When impersonating in an ABAC-enabled AKS cluster, you need the argument --as-user-extra oid=${externalUserId}; this argument is not required in an non-ABAC AKS cluster.
Auditing impersonation actions in Kubernetes is vital for security, as it tracks user actions on behalf of others, allowing administrators to detect unauthorized access and analyze behavior. In this section, we will use Log Analytics Workspace and resource logs to retrieve control plane logs.
Enable control plane logs for ingestion
Follow the section “Enable Control Plane Logs for Ingestion” in this documentation.
In this article, only KubernetesAudit and KubernetesControlPlane will be utilized. You can adjust these options based on your environment.
Ingestion
The impersonation logs will only appear in the AKSControlPlane table. Use the query below to view the messages:
00000000-0000-0000-0000-000000000000[22222222-2222-2222-2222-222222222222,system:authenticated] is impersonating 11111111-1111-1111-1111-111111111111[system:authenticated]
1/15/2026, 10:43<17>.188 AM
00000000-0000-0000-0000-000000000000[22222222-2222-2222-2222-222222222222,system:authenticated] is impersonating 11111111-1111-1111-1111-111111111111[system:authenticated]
1/15/2026, 10:43<28>.079 AM
00000000-0000-0000-0000-000000000000[22222222-2222-2222-2222-222222222222,system:authenticated] is impersonating 11111111-1111-1111-1111-111111111111[system:authenticated]
In the output:
00000000-0000-0000-0000-000000000000 is representing the person who is impersonating.
11111111-1111-1111-1111-111111111111 is representing the person who is being impersonated.
22222222-2222-2222-2222-222222222222 is representing the group name of “system:authenticated”.
NOTE
The actual output of TimeGenerated should be in the format like “2026-01-15T10:43<06>.536207Z”. Here, the output like “1/15/2026, 10:43<06>.536 AM” is formatted by the Log Analytics Workspace Web.
To combine the message with the actual action, use the following Kusto query:
00000000-0000-0000-0000-000000000000[22222222-2222-2222-2222-222222222222,system:authenticated] is impersonating 11111111-1111-1111-1111-111111111111[system:authenticated]
{"authorization.k8s.io/decision":"allow", "authorization.k8s.io/reason":"RBAC: allowed by ClusterRoleBinding \"system:basic-user\" of ClusterRole \"system:basic-user\" to Group \"system\:authenticated\""}
00000000-0000-0000-0000-000000000000[22222222-2222-2222-2222-222222222222,system:authenticated] is impersonating 11111111-1111-1111-1111-111111111111[system:authenticated]
{"authorization.k8s.io/decision":"allow", "authorization.k8s.io/reason":"RBAC: allowed by ClusterRoleBinding \"system:basic-user\" of ClusterRole \"system:basic-user\" to Group \"system\:authenticated\""}
NOTE
It may take up to 30 minutes for data in AKSAudit to be collected.
The article starts with a user asking why kubectl auth can-i doesn’t work in the AKS GitHub repository. Following that, the Kubernetes SIG CLI team introduced a new feature that allows users to input --as-user-extra, making it possible to impersonate other users in ABAC-enabled AKS using just the CLI, without modifying any files. This feature was released about a month ago.
Now, I’ve decided to write this article to address the issue. I’ve also included a method for auditing impersonation actions, which lets users review their activities while impersonating others, adding some extra depth to the discussion.
And here’s the article I’ve put together.
Impersonating as other users and auditing impersonation actions in AAD-enabled AKS