Why Being Inside the Cluster Doesn’t Mean You’re Trusted: 5 Counter-Intuitive Kubernetes Networking Takeaways
Originally published at https://gokairo.dev/blog/why-being-inside-the-cluster-doesnt-mean-youre-trusted-k8s-networking 1. Introduction: The Fallacy of In-Cluster Trust If your database has no public IP and sits insi
Originally published at https://gokairo.dev/blog/why-being-inside-the-cluster-doesnt-mean-youre-trusted-k8s-networking
1. Introduction: The Fallacy of In-Cluster Trust
If your database has no public IP and sits inside your Kubernetes cluster, can an unrelated pod still connect to it?
Many platform teams operate under a dangerous architectural misconception: placing a workload behind a private interface within a cluster automatically secures it. Because the workload isn't exposed directly to the public internet via an Ingress or LoadBalancer service, engineers assume it is safe from unauthorized internal access.
In reality, standard Kubernetes networking models treat all in-cluster traffic as flat and open by default. Establishing true security boundaries requires shifting from implicit, network-wide trust to explicit communication boundaries engineered through networking.k8s.io/v1 (http://networking.k8s.io/v1) NetworkPolicies.
2. Takeaway #1: Cluster Membership Is Not a Security Boundary (Pods Talk by Default)
In a standard Kubernetes cluster, cluster membership does not constitute a security boundary. The default networking specification dictates that any pod can route IP packets to any other pod across any namespace without restriction.
Consider a standard three-tier architecture deployed in the production namespace:
- Frontend Pods: app: frontend
- Backend Pods: app: backend
- Database Pods: app: database
The intended architectural path is strict: Frontend -> Backend -> Database. However, if an unauthorized or compromised rogue workload (for instance, an untested analytics container or a compromised frontend pod) enters the cluster, IP routing allows it to bypass service abstractions entirely and talk directly to the database pod on TCP port 5432. Service abstractions like ClusterIP manage traffic distribution—they do not provide security isolation.
- Assumed Boundary: Cluster Membership (Believing that placing workloads in a private cluster implicitly segregates them from internal peers).
- Actual Boundary: Explicit NetworkPolicies (Enforcing programmatic ingress and egress rules at the pod network interface layer).
3. Takeaway #2: Policies Are Additive, Not "Deny-Overrides-Allow"
A common trap for platform engineers migrating from traditional enterprise firewalls is expecting a "deny-overrides-allow" evaluation model. In Kubernetes NetworkPolicies, rule evaluation is strictly additive.
When a pod is selected by a NetworkPolicy, it transitions from an unisolated state to an isolated state for the specified policyTypes (Ingress, Egress, or both). An empty rule array (such as ingress: []) establishes a default-deny posture for that traffic direction. Crucially, applying a secondary policy that matches the same target pod and includes an explicit permit rule does not "override" or delete the deny policy. Instead, isolation creates the baseline default-deny state, and matching rules addively open explicit, white-listed paths through that isolated state.
To illustrate additive mechanics, consider locking down the database pod in the production namespace. First, we apply a baseline isolation manifest:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: database-default-deny-ingress
namespace: production
spec:
podSelector:
matchLabels:
app: database
policyTypes:
- Ingress
ingress: []
This manifest selects app: database and sets an empty ingress: [] list, isolating the database from all incoming traffic across the cluster. Next, to allow only our trusted backend to communicate with the database, we declare a second policy:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-backend-to-database
namespace: production
spec:
podSelector:
matchLabels:
app: database
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
app: backend
ports:
- protocol: TCP
port: 5432
Because Kubernetes policies are additive, app: database remains isolated from the rest of the cluster, but traffic matching app: backend on TCP port 5432 is granted access.
Critical Selector Nuance: Combined vs. Separate Peer Entries
When writing ingress or egress rules, pay meticulous attention to YAML list structures under the from or to blocks. The interaction between podSelector and namespaceSelector changes dramatically based on syntax:
Combined Peer Entry (AND condition):
ingress:
- from:
- namespaceSelector:
matchLabels:
environment: production
podSelector:
matchLabels:
app: backend
Traffic is allowed ONLY if it originates from a pod labeled app: backend located inside a namespace labeled environment: production.
Separate Peer Entries (OR condition):
ingress:
- from:
- namespaceSelector:
matchLabels:
environment: production
- podSelector:
matchLabels:
app: backend
Traffic is allowed from ANY pod in a namespace labeled environment: production OR from any pod in the current namespace labeled app: backend.
Key Analytical Takeaway: Kubernetes policy evaluation creates a default-deny state upon pod selection and addively opens paths. Combining podSelector and namespaceSelector into a single peer element enforces an AND evaluation, whereas splitting them into distinct array items creates an OR evaluation.
4. Takeaway #3: Ingress Isolation Leaves Egress Wide Open (And Vice Versa)
Securing incoming connections to a workload does not protect its outgoing connections. The networking.k8s.io/v1 API enforces complete directional separation between Ingress (inbound) and Egress (outbound) controls.
Applying database-default-deny-ingress isolates incoming traffic to the database pod, ensuring an unauthorized frontend pod cannot connect directly to port 5432. However, because Egress was not listed under policyTypes, the database pod's outbound network capabilities remain 100% unrestricted.
If an attacker achieves remote code execution on an ingress-isolated database pod, that pod can still initiate outbound TCP connections to external command-and-control servers or exfiltrate data to arbitrary internal IP addresses.
Crucial Rule: Ingress and egress isolation are completely independent. A policy that isolates incoming traffic leaves outbound egress traffic wide open until an explicit egress isolation policy is declared.
5. Takeaway #4: Your YAML Means Nothing Without CNI Support
You can author syntactically perfect NetworkPolicy manifests, apply them via your CI/CD pipeline, and receive success responses from the Kubernetes API server—yet remain completely unprotected.
NetworkPolicy resources are pure API declarations. The actual enforcement of these rules falls entirely on the cluster’s underlying Container Network Interface (CNI) plugin (such as Calico, Cilium, or enterprise cloud CNIs configured with policy engines). If your cluster runs a basic CNI plugin that lacks NetworkPolicy enforcement capabilities, the API server will accept your YAML without throwing errors, but the network plane will completely ignore the rules. Pod-to-pod traffic will continue to pass unrestricted.
Operational Verification & Diagnostic Framing
Never assume a policy is working simply because kubectl apply succeeded. Platform engineers must operationalize inspection and audit commands:
# Verify active policies in the target namespace
kubectl get networkpolicies -n production
# Inspect detailed selector matches and rule configurations
kubectl describe networkpolicy database-default-deny-ingress -n production
kubectl describe networkpolicy allow-backend-to-database -n production
When validating network paths with temporary test pods, engineers must properly differentiate between network policy packet drops, DNS resolution failures, and Layer 7 application errors:
- Network Policy Drop (L3/L4 Block): The connection attempt times out at the TCP handshake layer (SYN packets dropped silently by the CNI kernel module or ebpf program).
- DNS Resolution Failure: The test pod returns NXDOMAIN or Could not resolve host. This indicates a ClusterDNS or CoreDNS issue, not a NetworkPolicy packet block on the target database IP.
- Application Layer Failure: The connection receives an explicit ECONNREFUSED or an HTTP 403/500 error. The network packet successfully reached the container, but the application service rejected the connection or crashed.
Policy Enforcement Audit Checklist:
- CNI Plugin Support: Confirm that the underlying cluster CNI plugin actively supports and enforces networking.k8s.io/v1 NetworkPolicies.
- Selector Exactness: Audit podSelector and namespaceSelector key-value pairs against running pod and namespace labels.
- Port & Protocol Matching: Confirm target application container ports match the numeric protocol and port specified in the YAML.
Operational Verification: Execute kubectl describe networkpolicy and test connection paths, ensuring TCP connection timeouts occur on blocked paths while authorized paths establish cleanly.
6. Takeaway #5: Network Controls Are Not Application Authorization
Kubernetes NetworkPolicies operate at Layer 3 (IP addresses, ipBlock, namespaceSelector) and Layer 4 (TCP/UDP ports, podSelector). They dictate whether network packets can physically travel across the virtual fabric from point A to point B.
NetworkPolicies cannot inspect application protocol payloads, validate HTTP headers, inspect TLS certificates, or verify JSON Web Tokens (JWTs). Allowing TCP traffic on port 5432 from app: backend to app: database simply opens the wire—it does not authenticate the backend application user, authorize database queries, or encrypt packet payloads in transit.
Architectural Boundary Callout: Layer 3/Layer 4 network controls establish transport safety by controlling packet routing between endpoints. They complement—but never replace—Layer 7 application security mechanisms such as mutual TLS (mTLS), user authentication, application-level Role-Based Access Control (RBAC), and payload sanity validation.
7. Conclusion: Move from Implicit to Explicit Trust
Relying on private IPs or cluster boundaries for workload security creates a fragile defense posture. Sharing a Kubernetes cluster must never be mistaken for sharing implicit trust. Platform and security engineers must define explicit communication boundaries, audit their CNI implementations, and verify enforcement across every workload direction.
Your workloads may share a Kubernetes cluster. They should not automatically share trust. Define the communication boundaries, verify enforcement, and protect each service according to what it actually needs.
A Final Question for Platform Engineers: Have you verified that your cluster's CNI is actively dropping blocked packets, or are your workloads operating under the dangerous illusion of implicit cluster trust?
Read the full article on KAIRO.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.