Repository navigation
NetworkPolicy tests for blocking north/south traffic #114369
Description
The NP docs point out that NP's semantics for north/south traffic are not very clearly defined:
Cluster ingress and egress mechanisms often require rewriting the source or destination IP of packets. In cases where this happens, it is not defined whether this happens before or after NetworkPolicy processing, and the behavior may be different for different combinations of network plugin, cloud provider,
Serviceimplementation, etc.In the case of ingress, this means that in some cases you may be able to filter incoming packets based on the actual original source IP, while in other cases, the "source IP" that the NetworkPolicy acts on may be the IP of a
LoadBalanceror of the Pod's node, etc.For egress, this means that connections from pods to
ServiceIPs that get rewritten to cluster-external IPs may or may not be subject toipBlock-based policies.
However, what's not ambiguous is that a pod which is fully isolated for ingress should not accept E/W or N/S traffic. Regardless of how the ingress/LB/cloud handles the traffic, it should end up getting blocked. (Well, unless it gets masqueraded to the pod's node IP, because then it hits that exception to the rules.)
Unfortunately we can't say the same for egress; I think we assume that a pod-to-service-IP connection will be allowed to reach kube-proxy even if the pod is fully isolated-for-egress, but we explicitly don't require that ipBlock policies get applied after service proxying.
Anyway, we should be able to add a test to test/e2e/network/netpol/network_policy.go that confirms that cluster-ingress traffic to a fully isolated-for-ingress pod is not allowed. In particular, if we create a LoadBalancer Service with externalTrafficPolicy: Local, and a NetworkPolicy blocking all ingress to that Service's Pods, then we should not be able to connect to the service via either the LoadBalancer IP/name or via its NodePort (on one of the correct nodes).
/sig network
/area network-policy
/priority backlog
/help
/good-first-issue
Activity
k8s-ci-robot commentedon Dec 8, 2022
@danwinship:
This request has been marked as suitable for new contributors.
Guidelines
Please ensure that the issue body includes answers to the following questions:
For more details on the requirements of such an issue, please see here and ensure that they are met.
If this request no longer meets these requirements, the label can be removed
by commenting with the
/remove-good-first-issuecommand.Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
MohnishMishra commentedon Dec 28, 2022
Hello, I am Mohnish Mishra. I am a 2nd year student in BTech in Computer Science and Engineering.
I am new to open-source coding and trying understand the same.
I am interested in contributing to this project.
If you could please guide me on what is to be done and what are the pre-requisites for the same, it will be of great help.
sftim commentedon Dec 29, 2022
@danwinship this feels to me like an issue that (right now) justifies the help label, but maybe not good-first-issue. WDYT?
astoycos commentedon Jan 2, 2023
This has been on my TODO list, and I'm hoping to either get to it early in the new year or have a member of the network policy api subgroup tackle this. @MohnishMishra Feel free to come to that meeting to learn more :) [Note we are changing the time this year see this pr and slack conversation for more information]
But yeah @sftim I'd say this is slightly above good first issue :)
farahInTheZone commentedon Jan 3, 2023
Hey. If this is not being actively worked on, I would like to pick this up.
MohnishMishra commentedon Jan 4, 2023
Thank you @astoycos.
I have joined the mailing group and hope to join the meetings and learn.
Thank you for the opportunity.
47 remaining items
kunalworldwide commentedon May 26, 2026
@danwinship before I open a new PR — @aroradaman raised whether this should go in
network-policy-apiinstead oftest/e2e/network/netpol/network_policy.go. This is a v1 NetworkPolicy test so my assumption is it stays innetpol/, but wanted to check before putting work into the wrong place.Also want to confirm I'm reading your latest comments right: the test should create a pod with deny-all-ingress, expose it via NodePort with
externalTrafficPolicy: Local, connect from the e2e host (not from inside a pod), and just fail if the connection succeeds. No SNAT detection needed. Should I include a LoadBalancer variant too or keep it narrow for now?danwinship commentedon May 26, 2026
@kunalworldwide there is already a PR open adding a test for this. It just hasn't merged yet.
kunalworldwide commentedon Jun 29, 2026
@danwinship good to know — is the open PR #137390, or a different one? I saw #137390 was closed earlier; if there is a replacement PR it would be useful to link it here so others do not duplicate the work. Happy to help review or test if it is stuck on something.
danwinship commentedon Jun 29, 2026
There have been multiple PRs opened at various points; you can see them all in the sidebar on the right. One of them is currently open.
kunalworldwide commentedon Jul 15, 2026
@danwinship thanks — I see the open PR now. Is it stuck on anything specific (review bandwidth, rebase, or a design question)? Happy to help review or run the e2e tests if that unblocks it.
Add e2e test for NetworkPolicy with LoadBalancer Local externalTraffi…
Add e2e test for NetworkPolicy with LoadBalancer Local externalTraffi…
test: add e2e test for NetworkPolicy blocking LoadBalancer Local ingress
test: add e2e test for NetworkPolicy blocking LoadBalancer Local ingress
test: add e2e test for netpol LB externalTrafficPolicy
test: add e2e test for netpol with LB Local
test: add e2e test for netpol with LB Local
test: add e2e test for NetworkPolicy blocking LoadBalancer Local ingress
test: add e2e test for netpol with LB Local
test: add e2e test for netpol with LB Local