11 / 13Containers and serverless
Azure Kubernetes Service (AKS) security hardening
Harden AKS clusters: private API server, Entra ID with Azure RBAC, workload identity, pod security policy, network policy, egress lockdown and audit logs.
- Service
- AKS
- Category
- Containers and serverless
- Baseline
- 11 controls
- Updated
On this page
Azure Kubernetes Service (AKS) runs a managed Kubernetes control plane and gives you the node pools, the network and everything that runs on them. The defaults favor getting started: a public API server reachable from anywhere, a local cluster-admin certificate that bypasses Entra ID, no network policy engine so every pod can talk to every other pod, and unrestricted outbound internet from nodes. The attack patterns are well documented: exposed dashboards and management interfaces used for cryptomining (catalogued in Microsoft's threat matrix for Kubernetes), stolen kubeconfig files with long-lived admin credentials, and pod-to-node escalation, such as the TLS bootstrap issue Mandiant reported in 2024 where code in a pod could reach node provisioning data and read cluster secrets. This page maps each control to the Microsoft cloud security benchmark (MCSB) security baseline for AKS. The CIS Azure Kubernetes Service (AKS) Benchmark covers node and workload settings in more depth; its recommendation numbers are not cited here.
Baseline controls
CIS numbers refer to the CIS Microsoft Azure Foundations Benchmark v7.0.0.
| Control | Why | How to check | ID |
|---|---|---|---|
| Private cluster or authorized IP ranges | API server not reachable from the whole internet | az aks show --query apiServerAccessProfile | MCSB NS-2 |
| Entra ID with Azure RBAC | Central identity, MFA, reviewable access | az aks show --query aadProfile | MCSB IM-1, PA-7 |
| Local accounts disabled | Removes the static cluster-admin credential | az aks show --query disableLocalAccounts | MCSB PA-1 |
| Workload identity | No secrets in pods, no node-wide identity | az aks show --query securityProfile.workloadIdentity | MCSB IM-3 |
| Azure Policy add-on and pod security | Blocks privileged and host-level pods | az aks show --query addonProfiles.azurepolicy | MCSB AM-2 |
| Network policy | Limits lateral movement between pods | az aks show --query networkProfile.networkPolicy | MCSB NS-1 |
| Node OS and cluster auto-upgrade | Unpatched nodes and versions are exploitable | az aks show --query autoUpgradeProfile | - |
| Defender for Containers | Runtime threat detection, image scanning | az aks show --query securityProfile.defender | MCSB LT-1, PV-5 / CIS 8.1.4.1 |
| Egress lockdown | Stops data exfiltration and C2 from pods | az aks show --query networkProfile.outboundType | - |
| Image provenance with ACR | Only trusted images, no shared registry password | az acr show --query adminUserEnabled | MCSB PV-3 |
| Control plane diagnostic logs | Audit trail of API calls | az monitor diagnostic-settings list --resource <aks-id> | MCSB LT-4 |
Private cluster and authorized IP ranges
The API server is the cluster's front door. You have three options, from strongest to weakest:
- Private cluster: the API server gets a private IP in your network through a private endpoint, and is only reachable from the VNet, peered networks or a jump host. Create it with
--enable-private-cluster; add--disable-public-fqdnso the cluster FQDN does not resolve publicly. - API Server VNet Integration (
--enable-apiserver-vnet-integration): the API server is projected into a delegated subnet of your VNet, and can be made private without a private endpoint. - Public API server with authorized IP ranges: keep it public but restrict it to known egress addresses of your offices, CI runners and admin jump hosts.
# Private cluster
az aks create -g rg-aks -n aks-prod \
--enable-private-cluster --disable-public-fqdn \
--network-plugin azure --vnet-subnet-id "$SUBNET_ID" \
--enable-managed-identity
# Existing public cluster: restrict to known ranges
az aks update -g rg-aks -n aks-prod \
--api-server-authorized-ip-ranges 203.0.113.0/24,198.51.100.10/32
For administration of a private cluster without network line of sight, az aks command invoke runs kubectl through the Azure control plane. It is convenient but it is also a bypass of your network control; if you do not use it, disable it (policy below).
Enforce
Assign "Azure Kubernetes Service Private Clusters should be enabled" (Audit or Deny) on production management groups, and "Authorized IP ranges should be defined on Kubernetes Services" where public clusters remain. "Azure Kubernetes Service Clusters should disable Command Invoke" audits the bypass, and "Disable Command Invoke on Azure Kubernetes Service clusters" fixes it with a Modify-style remediation. Network layout and private DNS zones for private endpoints are covered on the Virtual Network page.
Entra ID integration and Azure RBAC
AKS-managed Entra ID integration authenticates kubectl users with Microsoft Entra ID, so MFA and Conditional Access apply and leavers lose access when their account is disabled. With Azure RBAC for Kubernetes authorization, role assignments for the cluster live in Azure (reviewable, PIM eligible) instead of in RoleBindings scattered across namespaces.
az aks update -g rg-aks -n aks-prod \
--enable-aad \
--aad-admin-group-object-ids <entra-group-object-id> \
--enable-azure-rbac
Then assign the built-in data-plane roles at cluster or namespace scope:
AKS_ID=$(az aks show -g rg-aks -n aks-prod --query id -o tsv)
# Read-only for a team on one namespace
az role assignment create --assignee <group-object-id> \
--role "Azure Kubernetes Service RBAC Reader" \
--scope "$AKS_ID/namespaces/team-a"
# Cluster admin, eligible through PIM rather than permanent
az role assignment create --assignee <admin-group-object-id> \
--role "Azure Kubernetes Service RBAC Cluster Admin" --scope "$AKS_ID"
Keep the Azure Kubernetes Service Cluster Admin Role (which can fetch admin credentials with az aks get-credentials --admin) away from day-to-day users; it is a control-plane role, separate from the RBAC roles above. Use PIM for the admin group, as described on the Entra ID page and Azure RBAC page.
Verify:
az aks show -g rg-aks -n aks-prod \
--query "aadProfile.{managed:managed, azureRbac:enableAzureRbac, admins:adminGroupObjectIDs}"
Enforce with "Azure Kubernetes Service Clusters should enable Microsoft Entra ID integration" and "Role-Based Access Control (RBAC) should be used on Kubernetes Services".
Disable local accounts
Even with Entra ID integration, every AKS cluster has a local clusterAdmin certificate unless you turn it off. Anyone with Microsoft.ContainerService/managedClusters/listClusterAdminCredential/action gets a kubeconfig that bypasses Entra ID, MFA and Conditional Access, and the certificate stays valid until you rotate the cluster certificates.
az aks update -g rg-aks -n aks-prod --disable-local-accounts
# Verify
az aks show -g rg-aks -n aks-prod --query disableLocalAccounts
After this change az aks get-credentials --admin fails, which is the point. If credentials were ever downloaded before, rotate certificates with az aks rotate-certs (it causes downtime of the API server for a few minutes and requires users to re-fetch credentials). Enforce with "Azure Kubernetes Service Clusters should have local authentication methods disabled" (Audit or Deny).
Workload identity
Pods that call Azure APIs should use Microsoft Entra Workload ID: a Kubernetes service account is federated with a user-assigned managed identity, and the pod exchanges its projected service account token for an Entra token. No secret is stored in the cluster and the identity is per workload, not per node. Pod-managed identity (aad-pod-identity) is deprecated; migrate any remaining use to workload identity.
az aks update -g rg-aks -n aks-prod --enable-oidc-issuer --enable-workload-identity
ISSUER=$(az aks show -g rg-aks -n aks-prod --query oidcIssuerProfile.issuerUrl -o tsv)
az identity create -g rg-aks -n id-orders-api
az identity federated-credential create -g rg-aks \
--identity-name id-orders-api --name fc-orders-api \
--issuer "$ISSUER" \
--subject system:serviceaccount:orders:orders-api \
--audiences api://AzureADTokenExchange
apiVersion: v1
kind: ServiceAccount
metadata:
name: orders-api
namespace: orders
annotations:
azure.workload.identity/client-id: "<client-id-of-id-orders-api>"
---
# In the pod template
metadata:
labels:
azure.workload.identity/use: "true"
spec:
serviceAccountName: orders-api
Two related points: the kubelet identity (used to pull images) should hold only AcrPull on the registries it needs, and pods should not be able to reach the node's instance metadata endpoint to borrow it. Network policy (below) can block 169.254.169.254/32 for application namespaces. Enforce with "Azure Kubernetes Service Clusters should enable workload identity" and "Azure Kubernetes Service Clusters should use managed identities". Scoping guidance for managed identities is on the Azure RBAC page.
Azure Policy add-on and pod security
The Azure Policy add-on runs Gatekeeper in the cluster and evaluates Kubernetes objects against built-in definitions, with results visible in Azure Policy compliance. It replaces the removed PodSecurityPolicy and complements the Kubernetes Pod Security Admission labels.
az aks enable-addons -g rg-aks -n aks-prod --addons azure-policy
# Verify the add-on pods
kubectl get pods -n gatekeeper-system
kubectl get pods -n kube-system -l app=azure-policy
Assign one of the two built-in initiatives at the management group, first with the Audit effect, then Deny once workloads are clean:
- "Kubernetes cluster pod security baseline standards for Linux-based workloads": blocks privileged containers, host namespaces, hostPath abuse and dangerous capabilities.
- "Kubernetes cluster pod security restricted standards for Linux-based workloads": adds non-root, no privilege escalation and restricted volume types.
Individual definitions worth adding: "Kubernetes clusters should not allow container privilege escalation", "Kubernetes clusters should ensure that the cluster-admin role is only used where required" and "Kubernetes clusters should minimize wildcard use in role and cluster role". Exclude kube-system and gatekeeper-system through the initiative's namespace exclusion parameter, not by weakening the policy. Use "Deploy Azure Policy Add-on to Azure Kubernetes Service clusters" (DeployIfNotExists) so new clusters get the add-on automatically; org-wide rollout is on the Azure Policy page.
Network policy
Without a network policy engine, Kubernetes allows all pod-to-pod traffic, so one compromised pod can reach every database client, metrics endpoint and internal API in the cluster. Choose the engine at creation time:
az aks create -g rg-aks -n aks-prod \
--network-plugin azure --network-plugin-mode overlay \
--network-dataplane cilium --network-policy cilium \
--vnet-subnet-id "$SUBNET_ID"
Azure CNI Powered by Cilium is the recommended engine for new clusters; Azure Network Policy Manager (--network-policy azure) and Calico (--network-policy calico) remain options. Then apply a default deny in each application namespace and allow only what is needed:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny
namespace: orders
spec:
podSelector: {}
policyTypes: ["Ingress", "Egress"]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-dns-and-api
namespace: orders
spec:
podSelector: {}
policyTypes: ["Egress"]
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
ports:
- { protocol: UDP, port: 53 }
- { protocol: TCP, port: 53 }
- to:
- ipBlock:
cidr: 0.0.0.0/0
except: ["169.254.169.254/32"]
ports:
- { protocol: TCP, port: 443 }
Verify the engine with az aks show -g rg-aks -n aks-prod --query networkProfile.networkPolicy (a value of none means no enforcement). Subnet NSGs still apply to node traffic and are covered on the Virtual Network page.
Node OS and cluster upgrades
Two separate channels keep clusters patched:
- Node OS auto-upgrade channel patches the node image or OS packages.
NodeImagereplaces nodes with the latest weekly image (recommended),SecurityPatchapplies security packages in place,Unmanagedleaves it to the OS,Nonedoes nothing. - Cluster auto-upgrade channel moves the Kubernetes version (
patch,stable,rapid,node-image,none).patchis a sensible default for production.
az aks update -g rg-aks -n aks-prod \
--node-os-upgrade-channel NodeImage \
--auto-upgrade-channel patch
Add a planned maintenance window (az aks maintenanceconfiguration add with the aksManagedNodeOSUpgradeSchedule and aksManagedAutoUpgradeSchedule configurations) so upgrades happen when you expect them, and set pod disruption budgets so drains do not take services down. Prefer Azure Linux or Ubuntu node images over custom images that you then have to patch yourself.
Enforce with "Azure Kubernetes Service Clusters should enable node os auto-upgrade" and "Azure Kubernetes Service Clusters should enable cluster auto-upgrade"; "Configure Node OS Auto upgrade on Azure Kubernetes Cluster" remediates. "Kubernetes Services should be upgraded to a non-vulnerable Kubernetes version" reports clusters on versions with known CVEs.
Defender for Containers
Microsoft Defender for Containers adds runtime threat detection on nodes (through the Defender sensor), Kubernetes audit log analysis, agentless discovery, vulnerability assessment of images in ACR and running in the cluster, and attack path analysis. Enable the plan at subscription level, then make sure the sensor is on each cluster:
az security pricing create -n Containers --tier Standard
az aks update -g rg-aks -n aks-prod --enable-defender
Enforce with "Configure Azure Kubernetes Service clusters to enable Defender profile" (DeployIfNotExists) and audit with "Azure Kubernetes Service clusters should have Defender profile enabled". Plan settings and secure score are on the Defender for Cloud page.
Egress lockdown
By default AKS nodes reach the internet through a public Standard Load Balancer with no filtering, so a compromised pod can download tooling and exfiltrate data freely. Route all egress through Azure Firewall (or another network virtual appliance) with userDefinedRouting:
# Route table on the node subnet: 0.0.0.0/0 to the firewall private IP
az network route-table route create -g rg-aks --route-table-name rt-aks \
-n default-to-fw --address-prefix 0.0.0.0/0 \
--next-hop-type VirtualAppliance --next-hop-ip-address 10.0.1.4
az aks create -g rg-aks -n aks-prod \
--outbound-type userDefinedRouting \
--vnet-subnet-id "$SUBNET_ID" \
--network-plugin azure --enable-private-cluster
On the firewall, allow the AzureKubernetesService FQDN tag plus the specific endpoints your workloads need (your ACR, Key Vault, package mirrors), and deny the rest. The required outbound rules are listed in Microsoft's AKS egress documentation; anything beyond them should be a reviewed exception. NAT Gateway outbound types give stable egress IPs but no filtering, so they do not replace a firewall.
Verify with az aks show -g rg-aks -n aks-prod --query networkProfile.outboundType.
Image provenance and ACR
Pull images only from registries you control, and make the registry itself hard to abuse:
# Kubelet identity gets AcrPull, no imagePullSecrets needed
az aks update -g rg-aks -n aks-prod --attach-acr acrprod
# No shared admin password, no anonymous pull, private access only
az acr update -n acrprod --admin-enabled false \
--anonymous-pull-enabled false --public-network-enabled false
The ACR admin user is a single username and password with push and pull on the whole registry; leaked in a pipeline, it lets an attacker push a backdoored image that your clusters will run. Disable it and use Entra identities (kubelet managed identity for pulls, workload identity or federated pipeline identities for pushes).
In the cluster, restrict images to your registry with "Kubernetes cluster containers should only use allowed images" (a regex such as ^acrprod\.azurecr\.io/.+$) and block mutable tags with "Kubernetes cluster container images should not include latest image tag". On the registry, enforce "Container registries should have local admin account disabled.", "Container registries should have anonymous authentication disabled." and "Container registries should use private link". Turn on the Image Cleaner (--enable-image-cleaner) to remove vulnerable unused images from nodes.
Control plane diagnostic logs
AKS does not store control plane logs in your workspace unless you configure a diagnostic setting. The most useful categories for security:
| Category | Content |
|---|---|
kube-audit-admin | Kubernetes audit events excluding get and list (much lower volume) |
kube-audit | All audit events, including reads of secrets |
guard | Entra ID and Azure RBAC authorization decisions |
kube-apiserver | API server logs |
az monitor diagnostic-settings create --name aks-security \
--resource "$AKS_ID" --workspace "$LAW_ID" \
--export-to-resource-specific true \
--logs '[{"category":"kube-audit-admin","enabled":true},{"category":"guard","enabled":true},{"category":"kube-apiserver","enabled":true}]'
Resource-specific mode writes to the AKSAudit, AKSAuditAdmin and AKSControlPlane tables, which are cheaper and easier to query than AzureDiagnostics. Add kube-audit only if you need reads of secrets for investigations, and consider the Basic table plan for it. Enforce with "Deploy - Configure diagnostic settings for Azure Kubernetes Service to Log Analytics workspace" and audit with "Resource logs in Azure Kubernetes Service should be enabled".
Logging and detection
Log the control plane categories above, the activity log for the cluster resource (credential listing, command invoke, configuration changes) and container logs through Container insights with the Azure Monitor Agent. Defender for Containers raises alerts for privileged container creation, exposed dashboards, crypto mining and suspicious API calls.
Alert on credential retrieval and command invoke from the activity log:
AzureActivity
| where OperationNameValue in~ (
"MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/LISTCLUSTERADMINCREDENTIAL/ACTION",
"MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/LISTCLUSTERUSERCREDENTIAL/ACTION",
"MICROSOFT.CONTAINERSERVICE/MANAGEDCLUSTERS/RUNCOMMAND/ACTION")
| project TimeGenerated, Caller, CallerIpAddress, OperationNameValue, _ResourceId
Alert on new cluster-admin bindings and exec into pods from the audit log:
AKSAuditAdmin
| where (tostring(ObjectRef.resource) in ("clusterrolebindings", "rolebindings") and Verb in ("create", "update", "patch"))
or (tostring(ObjectRef.subresource) == "exec")
| project TimeGenerated, Verb, User = tostring(User.username),
Resource = tostring(ObjectRef.resource), Namespace = tostring(ObjectRef.namespace),
Name = tostring(ObjectRef.name), SourceIps
Workspace design, retention and alert routing are on the Azure Monitor page.
Common mistakes
- Enabling Entra ID integration but leaving local accounts on, so any Contributor can still download a cluster-admin kubeconfig that ignores MFA.
- Creating the cluster with
--network-policy noneand discovering later that adding an engine to a running production cluster needs a maintenance window. - Keeping the ACR admin user enabled for a pipeline, then leaking the password in build logs: anyone can push images your clusters trust.
- Giving the kubelet identity or a workload identity Contributor on the resource group, so a pod compromise turns into control of the node resource group or more.
- Restricting the API server with authorized IP ranges but adding broad ranges (whole cloud regions,
0.0.0.0/0for a CI runner) that make the restriction meaningless. - Applying pod security initiatives in Deny mode on day one without an Audit phase, breaking system add-ons, then disabling the policy entirely.
- Not configuring diagnostic settings, so after an incident there is no record of who created a privileged pod or read secrets.
References
- Azure security baseline for Azure Kubernetes Service (AKS) (Microsoft Learn)
- Secure your Azure Kubernetes Service (Microsoft Learn)
- Create a private Azure Kubernetes Service cluster (Microsoft Learn)
- Use Azure RBAC for Kubernetes authorization (Microsoft Learn)
- Manage local accounts with AKS-managed Microsoft Entra integration (Microsoft Learn)
- Microsoft Entra Workload ID with AKS (Microsoft Learn)
- Control egress traffic for AKS clusters (Microsoft Learn)
- Overview of Microsoft Defender for Containers (Microsoft Learn)
- Threat matrix for Kubernetes (Microsoft Security Blog)
- Escalating privileges to read secrets with Azure Kubernetes Services (Mandiant, Google Cloud)
- CIS Kubernetes Benchmarks (Center for Internet Security)
Filed under aks, kubernetes, containers
Written by
Florian Amette, Cloud Security Engineer & EditorSecurity engineer writing practical hardening pages for Microsoft Azure tenants and subscriptions, aligned with the CIS Microsoft Azure Foundations Benchmark.