Description
To see who performed a Kubernetes API operation, select an audit category in the AKS diagnostic setting. kube-audit includes API audit events. kube-audit-admin omits get and list.
Potential impact
Gaps in this record can leave you unable to establish who changed a permission or when someone read a resource.
Remediation
In the cluster’s azurerm_monitor_diagnostic_setting, set category inside the enabled_log block. For Log Analytics, set log_analytics_workspace_id on the diagnostic setting itself. Perform an operation in the selected category and find the caller and time at the destination. Set retention and read access, and configure alerts if you need notifications.
Examples
The excerpts omit the node pools, cluster identity configuration and Log Analytics workspace definition.
Before
resource "azurerm_kubernetes_cluster" "example" {
name = "example-aks"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "exampleaks"
}
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "aks-diagnostics"
target_resource_id = azurerm_kubernetes_cluster.example.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
enabled_log {
category = "kube-apiserver"
}
}
After
resource "azurerm_kubernetes_cluster" "example" {
name = "example-aks"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "exampleaks"
}
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "aks-diagnostics"
target_resource_id = azurerm_kubernetes_cluster.example.id
log_analytics_workspace_id = azurerm_log_analytics_workspace.example.id
enabled_log {
category = "kube-audit"
}
}
The first setting selects kube-apiserver operational logs. Check whether another diagnostic setting covers the audit events you need. The second sends kube-audit to the same workspace.