Skip to main content

A Namespace Without a Default-Deny NetworkPolicy Leaves Pods Open to All Traffic

High severityKubernetes About 20 minutes to fix

Overview

A namespace with one allow-specific Kubernetes NetworkPolicy is not the same as a namespace with default-deny; unselected pods remain fully open until an explicit deny-all policy is added.

At a glance

Symptom
A namespace that engineers believed was isolated by NetworkPolicy continues to accept traffic from pods and namespaces that were never explicitly granted access.
Likely cause
The observed exposure traces to a namespace that contains one NetworkPolicy scoped with a narrow podSelector (for example, matching only pods labelled app: payments-api)…
Impact
Newly deployed or unlabelled workloads in the namespace inherit no network restriction whatsoever, so lateral movement between pods, direct pod-to-pod access bypassing intended service boundaries, and unintended cross-namespace…
Verification signal
Validation succeeds only when explicitly unselected traffic is provably blocked and explicitly allowed traffic still succeeds after the default-deny policy is in place.
Safe correction
The fix is to add an explicit default-deny NetworkPolicy that selects all pods in the namespace with an empty podSelector and no ingress or egress rules, then layer…
Rollback or recovery
Rollback removes the newly applied default-deny policy and returns the namespace to its prior state within one command, since no existing workload configuration is altered by this change.

Symptom

A namespace that engineers believed was isolated by NetworkPolicy continues to accept traffic from pods and namespaces that were never explicitly granted access. Traffic that the team assumed was blocked reaches workloads without error, warning or denial event of any kind, and nothing in kubectl get networkpolicy output indicates a problem because the applied policy looks correct in isolation.

False Assumption

The team assumed that creating any NetworkPolicy object in a namespace switches that namespace into a default-deny posture, so that only explicitly allowed traffic can reach the selected pods. This is not how Kubernetes NetworkPolicy semantics work. A NetworkPolicy only affects the specific pods matched by its podSelector and only restricts the traffic types it names in policyTypes.

Pods not selected by any policy remain fully open to all ingress and egress, exactly as if no NetworkPolicy resource existed in the namespace at all.

Root Cause

The observed exposure traces to a namespace that contains one NetworkPolicy scoped with a narrow podSelector (for example, matching only pods labelled app: payments-api) and an ingress rule allowing traffic from a specific frontend label. No separate policy exists with an empty podSelector: {} that would apply default-deny to every other pod in the namespace.

Kubernetes NetworkPolicy is additive and selector-scoped, not namespace-wide by default; the presence of one policy does not imply a baseline deny for unselected workloads. Any pod in the namespace outside that selector, including newly deployed services, remains unrestricted.

Impact

Newly deployed or unlabelled workloads in the namespace inherit no network restriction whatsoever, so lateral movement between pods, direct pod-to-pod access bypassing intended service boundaries, and unintended cross-namespace ingress are all possible without triggering any policy violation.

Because the running policy is valid and the field team can see it applied, the gap is easy to miss during a change review; the failure is silent rather than erroring, and it typically surfaces only during a security assessment, a network trace, or an incident investigation.

Diagnosis

Confirm the gap using read-only commands before making any change. First list every NetworkPolicy in the namespace and inspect each selector and policy type.

Diagnostic Commands

Run the following read-only checks in the affected namespace.

kubectl get networkpolicy -n <namespace> -o yaml
kubectl get pods -n <namespace> --show-labels

Any pod whose labels match no policy’s podSelector is unrestricted.

Correction

The fix is to add an explicit default-deny NetworkPolicy that selects all pods in the namespace with an empty podSelector, policyTypes listing Ingress (and Egress if outbound traffic should also be denied, in which case allow DNS explicitly) and no ingress or egress rules, then layer the existing allow-specific policy on top. Apply the default-deny policy first in a non-production namespace, confirm baseline behaviour, then apply it to the target namespace with a defined rollback path.

Validation

Validation succeeds only when explicitly unselected traffic is provably blocked and explicitly allowed traffic still succeeds after the default-deny policy is in place. Test both the negative case (traffic that should now be denied) and the positive case (traffic that must remain permitted) from a temporary test pod, and capture the observed connection results as evidence.

Rollback

Rollback removes the newly applied default-deny policy and returns the namespace to its prior state within one command, since no existing workload configuration is altered by this change.

Prevention

Treat default-deny as the required first policy object in every namespace that uses NetworkPolicy, applied before any allow-specific rule, and enforce this via a namespace admission check or a cluster policy engine (for example, an OPA Gatekeeper or Kyverno constraint) that flags namespaces containing allow-only policies with no matching default-deny object.

Include a NetworkPolicy review step in namespace-provisioning checklists, and re-verify policy coverage whenever new workloads are labelled or relabelled, since label changes can silently move a pod out of an existing selector’s scope.

3

Apply the safer control

Before you change production

Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.

Fix commands and configuration

kubectl get networkpolicy
podSelector
policyTypes
4

When to escalate

Validation and rollback are covered in the sections above.

Escalate

Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.

The KBY Brief

Fixed? Get the next one before it hits you: The KBY Brief

Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.

About this page

Credited to

Dates

Published

Last updated

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Found this useful? Follow KBY for more like it.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources