Review AKS network policy settings

Use a supported policy engine and actual NetworkPolicy rules to allow only required pod traffic.

Description

To restrict traffic between AKS Pods, select a policy engine for the cluster and deploy a NetworkPolicy that selects the target Pods.

Potential impact

Pods outside the policy’s scope can retain unnecessary network access.

Remediation

Choose azure, calico or cilium to match the network plugin and data plane. Define ingress and egress rules that allow required traffic such as DNS. Test ingress by connecting to a selected Pod and egress by connecting from it. Check that each rule allows and blocks the intended traffic.

Examples

Both examples use Azure CNI. The second selects Azure NPM with network_policy = "azure". Check the AzureRM 5.6.0 plan and prepare for cluster replacement when making this change on an existing cluster. For a new Linux cluster, also consider Azure CNI Powered by Cilium.

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"

  default_node_pool {
    name       = "default"
    node_count = 1
    vm_size    = "Standard_D2_v2"
  }

  identity {
    type = "SystemAssigned"
  }

  network_profile {
    network_plugin = "azure"
  }
}

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"

  default_node_pool {
    name       = "default"
    node_count = 1
    vm_size    = "Standard_D2_v2"
  }

  identity {
    type = "SystemAssigned"
  }

  network_profile {
    network_plugin = "azure"
    network_policy = "azure"
  }
}

References