Review NetworkPolicy enforcement configuration

Verify that NetworkPolicy is actually enforced by the deployed network configuration.

Description

NetworkPolicy needs a network component that enforces it. If you use Flannel for connectivity, check whether a separate policy controller such as Calico is running.

Potential impact

Without enforcement, Pods in other namespaces may still reach an internal service.

Remediation

Plan for connectivity loss and recovery. Enable enforcement using the installation guide for your network component. Allow required ingress and egress, including DNS. From a Pod, test one connection that should succeed and one that should be blocked.

Examples

The ConfigMaps illustrate plugin selection. To migrate the network, follow the plugin’s installation and migration procedure.

Before

yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-system
  labels:
    app: flannel
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "plugins": [
        {
          "type": "flannel"
        }
      ]
    }

After

yaml
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-system
  labels:
    app: calico
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "plugins": [
        {
          "type": "calico"
        }
      ]
    }

References