Skip to content

All posts

Kubernetes

How to show Kubernetes network segmentation to auditors

Ritesh Patel

Kubernetes: How to show Kubernetes network segmentation to auditors

Show segmentation with three records: the NetworkPolicy manifests in each namespace, the namespace labels those policies select on, and a default-deny baseline that isolates pods no other policy selects. Then state the limit. The NetworkPolicy API does not log blocked or accepted connections, so the policies are evidence of configuration, not of traffic.

Checked against the Kubernetes Network Policies page as of 2026-11-30. The page was last modified 2026-04-14 and describes its limits as of Kubernetes 1.37. The manifests below are the page’s own examples.

What a NetworkPolicy isolates by default

A pod is non-isolated until a policy selects it. The Kubernetes page says that by default a pod is non-isolated for egress and for ingress, so all connections are allowed. A pod becomes isolated for a direction only when a NetworkPolicy both selects the pod and lists that direction in policyTypes.

Policies then add up. If several policies apply to a pod in one direction, the allowed connections are the union of what they allow, and their order does not matter. A connection between two pods needs both sides to agree: the egress policy on the source pod and the ingress policy on the destination pod must each allow it. The page also says that if a namespace has no policies, all ingress and egress traffic to and from its pods is allowed.

For an auditor, the question is therefore not whether a policy exists. It is whether every pod in scope is selected for each direction you claim to isolate. The steps below build that evidence in the order it is needed. The continuous compliance pillar page covers the wider compliance work this sits in.

Label namespaces so policies can select them

A namespaceSelector matches labels, not names. The page says a NetworkPolicy cannot target a namespace by its name directly. Instead, the control plane sets an immutable kubernetes.io/metadata.name label on every namespace, with the namespace name as its value. You can use that label, or a label of your own, to select a namespace.

Label each namespace in scope:

kubectl label namespace frontend namespace=frontend
kubectl label namespace backend namespace=backend

Then select on the labels in an egress rule. This example from the page allows egress from pods labelled app: myapp to pods in either labelled namespace:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: egress-namespaces
spec:
  podSelector:
    matchLabels:
      app: myapp
  policyTypes:
  - Egress
  egress:
  - to:
    - namespaceSelector:
        matchExpressions:
        - key: namespace
          operator: In
          values: ["frontend", "backend"]

To select a single namespace by name, the page points to the standardized label rather than a name field:

namespaceSelector:
  matchLabels:
    kubernetes.io/metadata.name: frontend

Add a default-deny baseline to each namespace

A default-deny policy selects every pod in a namespace and allows nothing in one or both directions. It is the baseline an auditor can check first, because it covers pods that no other policy selects. The page gives three variants, and they differ in what they isolate:

Baseline policyTypes What it isolates Page caveat
default-deny-ingress Ingress Inbound traffic to every pod in the namespace Does not change egress
default-deny-egress Egress Outbound traffic from every pod in the namespace Also blocks DNS; add a separate DNS allow
default-deny-all Ingress, Egress Both directions Carries both caveats above

The three manifests, as the page gives them:

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
spec:
  podSelector: {}
  policyTypes:
  - Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-egress
spec:
  podSelector: {}
  policyTypes:
  - Egress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

The page’s caution on the egress baseline matters for evidence. A namespace that passes its egress test because DNS is broken has not shown segmentation. Record the DNS allow policy alongside the baseline, and name the DNS service it targets.

Set policyTypes explicitly on every policy

policyTypes decides what a policy isolates, and the page sets defaults when it is left out. If no policyTypes is given, Ingress is always set, and Egress is set only if the policy has egress rules. A policy written as an egress allow-list can therefore also isolate ingress for the pods it selects.

Write policyTypes on every manifest, even where the default would give the same result. An auditor reading the file then sees the isolation directions without working out the defaults. Check the list against the direction you claim in your control mapping. A policy that claims egress control but lists only Ingress does not show egress isolation.

Read the selectors as Kubernetes interprets them

The from and to sections of a policy are easy to misread, because a single list element and two list elements mean different things. The page gives both forms:

# One element: pods labelled role=client, in namespaces labelled user=alice
ingress:
- from:
  - namespaceSelector:
      matchLabels:
        user: alice
    podSelector:
      matchLabels:
        role: client
# Two elements: pods labelled role=client in the policy's own namespace,
# or any pod in a namespace labelled user=alice
ingress:
- from:
  - namespaceSelector:
      matchLabels:
        user: alice
  - podSelector:
      matchLabels:
        role: client

The page says that when in doubt, kubectl describe shows how Kubernetes has interpreted the policy. Put that output next to the manifest in the evidence set. It is the reader’s check that the manifest says what the author meant.

What the page does not let you prove

Several limits decide what a policy object can support in an audit. The page states each one, and this post does not go past them.

Auditor question What the page says Out of scope here
Is the policy in force? A policy has no effect unless the network plugin supports NetworkPolicy. Creating one without a controller that implements it does nothing. The page gives no way to test enforcement, so this post gives none.
When did it take effect? Pods can start before isolation is applied. The API gives no way to tell when a policy has been handled. Plugin-specific timing.
Does a change affect open connections? Implementation-defined. The page advises not to change policies in ways that might affect existing connections. Which plugins close connections.
Does deny-all cover ICMP? Only TCP, UDP and SCTP are guaranteed. Other protocols are undefined. Plugin behaviour for ICMP.
Were blocked connections logged? Logging blocked or accepted connections is listed as not possible in the API. Any substitute logging source.
Does a port range apply everywhere? endPort needs a plugin that supports it. Without support, only the single port applies. Which plugins support endPort.

The last row is a gotcha for evidence. A range that looks correct in the manifest may cover only one port on a cluster whose plugin ignores endPort.

Evidence set: what the page supports

The table below lists the evidence an engineer can build from the page alone, and the items the page cannot support. Use it as the checklist for the evidence folder. It is not a control mapping. Map it to your own standard.

Evidence Supported by the page Notes
NetworkPolicy manifests for each namespace in scope Yes Keep them in version control with a commit history.
Namespace labels that the selectors use Yes Include kubernetes.io/metadata.name where a selector uses it.
Default-deny baseline per namespace Yes Use the variant that matches your claim.
DNS allow policy paired with an egress baseline Yes, as a requirement The page does not give the manifest.
Explicit policyTypes on each policy Yes Defaults are stated on the page.
kubectl describe output for each policy Named on the page The page does not say what the output contains.
Proof that a policy is enforced No Out of scope; see the table above.
Log of blocked or accepted connections No The API does not log these.
Audit trail of who changed a policy Not covered The evidence collection post covers the audit log.

For the egress side of agent pods, the egress post works through the same baseline with an AI agent workload.

Enforcing this with Kyverno

This post does not say that Kyverno enforces the baseline above, or that Kyverno gives an auditor this evidence. The one dependency the Kubernetes page does establish is the network plugin. A NetworkPolicy takes effect only where the plugin implements it, so record the plugin and its version in the evidence set before anything else. For the open-source project behind the policy engine, see Kyverno OSS.

Frequently asked questions

Does a NetworkPolicy show that traffic was blocked?

No. The Kubernetes Network Policies page lists the ability to log network security events, such as connections that are blocked or accepted, among the things the NetworkPolicy API cannot do. A policy object records configuration: which pods are isolated and which connections are allowed. Present it as evidence of design. If an auditor needs proof of traffic, that proof has to come from a source outside the NetworkPolicy API.

Why does a default deny egress policy break name resolution?

The page says a default deny-all egress policy also blocks DNS traffic. Workloads that need name resolution then fail until a separate NetworkPolicy allows egress to your cluster's DNS service. The page does not give that DNS policy or say how to find the DNS labels, so write it against your own cluster. Add it before you judge the baseline, or a DNS failure will look like a segmentation failure.

Can a policy with only egress rules also isolate ingress?

Yes, if policyTypes is not set. The page says that when no policyTypes are given, Ingress is always set, and Egress is set only when the policy has egress rules. A policy you meant as egress-only can therefore isolate ingress too. Set policyTypes explicitly on every policy so the manifest states what it isolates.

Does a deny-all policy block ICMP?

Not guaranteed. The page says a deny-all policy is only guaranteed to deny TCP, UDP and SCTP connections. For other protocols, such as ARP or ICMP, the behaviour is undefined and can differ between network plugins. Do not describe a deny-all policy as blocking all traffic in audit evidence.

Ritesh Patel, Founder & VP Product, Nirmata

Ritesh Patel is a founder of Nirmata and leads its products. He writes about governing AI coding agents, MCP security and Kubernetes policy as code.

LinkedIn

Nirmata Control HubOne control plane for Kyverno policies.
Share

Stay up-to-date with the latest in AI, governance, and infrastructure

Subscribe to our free monthly newsletter to get industry news, DevOps tips, and articles right to your inbox on Kyverno, containerization, Kubernetes deployment & management and more.