Azure Kubernetes Service Security Deep Dive – Part 3 (Audit Logs)
Published Jan 25 2022 05:54 AM 4,825 Views

Any activity to your Kubernetes cluster is handled as API request. So, when you create a new pod, changes container image of your deployment or read information from a configmap or secret, you basically generate requests to the Kubernetes API. We can ask Kubernetes to record all these requests and related data and metadata in log repository called Audit Logs. Each event at its different stages of execution generates event record and can be stored in audit logs based on some pre-defined policies. Please read this article on auditing carefully to understand the defined stages and defined audit levels. Remember, turning on audit logs means increase in memory consumption as well as storage consumption.


As you can see in the above-mentioned article, for a regular Kubernetes cluster, you can create your custom policy file by defining various stages and audit levels and then edit the kube-apiserver manifest file to include this policy file and the log path. But in case of AKS, as it is a managed Kubernetes service, you cannot access your master nodes and hence you are not allowed to create/implement your custom policy file. But you can configure your AKS cluster to send logs to a Log Analytics workspace or other destinations like a storage account or event hub. Enabling Audit Logs for your AKS cluster is also a recommendation from CIS Benchmark document for AKS. You can get detailed steps in this document. I am repeating those steps here for reader’s benefit. Assuming you are using Azure Portal:


  1. Select the resource group for your AKS cluster, such as myResourceGroup. Don't select the resource group that contains your individual AKS cluster resources, such as MC_myResourceGroup_myAKSCluster_eastus.
  2. On the left-hand side, choose Diagnostic settings.
  3. Select your AKS cluster, such as myAKSCluster, then choose to Add diagnostic setting.
  4. Enter a name, such as myAKSClusterLogs, then select the option to Send to Log Analytics.
  5. Select an existing workspace or create a new one. If you create a workspace, provide a workspace name, a resource group, and a location.
  6. In the list of available logs, select the logs you wish to enable. For this example, enable the kube-audit and kube-audit-admin logs. Common logs include the kube-apiserver, kube-controller-manager, and kube-scheduler. You can return and change the collected logs once Log Analytics workspaces are enabled.
  7. When ready, select Save to enable collection of the selected logs.  

Assuming you did all steps given above, you are now ready to view some logs from control plane from your AKS cluster. Here is one such example of how to do it:



The output will look like this:



Or, you can run Kusto queries as given in this article.


That’s pretty much it. You now know how to configure Audit Logs to your AKS Cluster. We will talk about Network Policy in the next part of this series.


Other parts of these series:  Part1 | Part2 | Part4 | Part5

Version history
Last update:
‎Jan 07 2022 09:18 AM
Updated by: