Review Azure Policy configuration for AKS

Configure policy assignments and effects, then verify the required detection and blocking behavior.

Description

To use Azure Policy on AKS, enable the add-on and assign the required policies to the cluster. An audit effect records violations. A deny effect can reject noncompliant requests within the assignment’s scope.

Potential impact

Workloads outside an assignment or covered by an exemption may miss an intended control.

Remediation

In AzureRM 5.6.0, set azure_policy_enabled = true. Check the impact on existing workloads, the assignment scope and its exemptions. Use test deployments to confirm that compliant requests succeed and violations are reported or denied as intended. If using another engine, verify the same requirements there.

Examples

The legacy AzureRM 2.x examples toggle the add-on in addon_profile. Supply the node pool, cluster identity and policy assignments separately.

Before

hcl
resource "azurerm_kubernetes_cluster" "example" {
  name                = "example-aks1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  dns_prefix          = "exampleaks1"

  addon_profile {
    azure_policy {
      enabled = false
    }
  }
}

After

hcl
resource "azurerm_kubernetes_cluster" "example" {
  name                = "example-aks1"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  dns_prefix          = "exampleaks1"

  addon_profile {
    azure_policy {
      enabled = true
    }
  }
}

References