Securing Azure Kubernetes Service
This lesson covers the API server, identity, workload policy and secrets in AKS.
Learning outcomes
After completing this lesson, you will be able to:
- Compare authorized IP ranges with private clusters.
- Explain why local accounts should be disabled.
- Describe workload identity.
- Explain the Azure Policy add-on and the Secrets Store CSI Driver.
Protecting the API server
By default, the AKS API server has a public IP address and FQDN. Two main options restrict it, and they are alternatives.
Authorized IP ranges use --api-server-authorized-ip-ranges, with a Standard load balancer, and changes can take up to two minutes. A private cluster uses --enable-private-cluster, and a private DNS zone such as privatelink.REGION.azmk8s.io. Unless --disable-public-fqdn is set, a public FQDN that resolves to the private address remains. Do not delete or change the private endpoint, because the cluster then stops working. Microsoft-hosted Azure DevOps agents cannot reach a private cluster. API Server VNet Integration is a further option, and it allows up to 2,000 authorized ranges.
Authorized ranges or private cluster?
Authentication and authorization
Microsoft Entra integration makes people sign in with their directory accounts, which brings MFA and Conditional Access. It uses the flags --enable-aad and --aad-admin-group-object-ids, and it cannot be disabled once it is enabled on a cluster.
Authorization can use Kubernetes RBAC, with roles and bindings inside the cluster, or Azure RBAC for Kubernetes authorization, with Azure roles such as Azure Kubernetes Service RBAC Reader. Azure RBAC gives a single place to manage access.
Local accounts are the trap. They are enabled by default, and Microsoft describes --admin access as a non-auditable backdoor, even with RBAC or Entra integration in place. Disable them with --disable-local-accounts, and rotate the cluster certificates on an existing cluster. Emergency access then uses a member of the Entra administrator group.
az aks update --resource-group RG --name CLUSTER --enable-aad --enable-azure-rbac \
--aad-admin-group-object-ids GROUP_ID --disable-local-accountsAKS access
Workload identity
A pod often needs to reach Azure resources such as Key Vault. Microsoft Entra Workload ID gives it an identity with no secret. It uses a Kubernetes service account, the cluster's OIDC issuer, and a federated identity credential on a managed identity. The pod presents a Kubernetes token, and Microsoft Entra ID exchanges it for an access token.
-
Enable
Turn on the OIDC issuer and workload identity on the cluster.
-
Create
Create a managed identity, and give it roles on the target.
-
Federate
Add a federated credential that trusts the service account.
-
Annotate
Add the annotation azure.workload.identity/client-id to the service account.
-
Label
Add the label azure.workload.identity/use: "true" to the pods.
A managed identity is limited to 20 federated identity credentials. The virtual nodes add-on is not supported. The older pod-managed identity feature is superseded, and clusters should migrate to workload identity.
The following diagram shows the token exchange behind workload identity.

Workload policy and secrets
The Azure Policy add-on for AKS applies policy to what runs in a cluster, using Gatekeeper. A built-in initiative such as Kubernetes cluster pod security baseline standards for Linux-based workloads can stop privileged containers, host path mounts and similar settings. Change the effect from audit to deny to enforce it. Policies can take up to 20 minutes to sync, and a denial comes from validation.gatekeeper.sh, naming a constraint that begins with k8sazure.
Kubernetes Secrets are stored in etcd, and they are not a strong store on their own. The Secrets Store CSI Driver, with the azure-keyvault-secrets-provider add-on, mounts secrets from Key Vault into pods through a SecretProviderClass, and supports autorotation. Grant Key Vault Secrets User to the identity that it uses. Encryption of etcd with customer-managed keys is also available.
Pods, policies and secrets
Network and node controls
Network policies restrict traffic between pods, which is otherwise open within a cluster. Azure CNI with Cilium is a common engine for them. Nodes have no public IP addresses by default. Image Cleaner removes stale images from nodes, including those with known vulnerabilities, and it does not work on Windows node pools. Upgrades keep Kubernetes and node images current, and the automatic upgrade channels reduce the effort. Stay on supported operating systems: Azure Linux 2.0 node images are being removed, and affected pools should move to Azure Linux 3.
AKS Automatic preconfigures many of these controls, including Azure RBAC, workload identity, baseline Pod Security Standards, Image Cleaner and API Server VNet Integration.
Hardening access
An AKS cluster uses Microsoft Entra integration. A review finds that an administrator signed in with az aks get-credentials --admin, and the action could not be tied to a person. Pods read a database password from a Kubernetes Secret. You must remove both weaknesses. What should you do?
Run az aks update --disable-local-accounts, and rotate the cluster's certificates, so that the --admin route closes and all access is through Entra identities. Then enable workload identity, so that pods authenticate as a managed identity, and use a Microsoft Entra login to the database, or use the Secrets Store CSI Driver if a secret must remain.
Disabling Entra integration is not possible, and it would make matters worse. Kubernetes RBAC alone leaves the local account in place. Encrypting etcd would protect the secret at rest, but it would not remove the need for it.
A pod needs to read from Key Vault with no secret. Which feature should it use?
Show answer
Microsoft Entra Workload ID, which federates its service account with a managed identity.
Exam Tips
Remember for the exam
- Local accounts are enabled by default and should be disabled.
- Entra integration cannot be disabled once enabled.
- Workload identity needs the OIDC issuer and a federated credential.
- Policy denials come from Gatekeeper; sync takes up to 20 minutes.