Skip to content

Add e2e test: NetworkPolicy default-deny blocks LoadBalancer Local externalTrafficPolicy ingress - #141764

Open
sanyamk23 wants to merge 1 commit into
kubernetes:masterfrom
sanyamk23:add-netpol-lb-local-test
Open

Add e2e test: NetworkPolicy default-deny blocks LoadBalancer Local externalTrafficPolicy ingress#141764
sanyamk23 wants to merge 1 commit into
kubernetes:masterfrom
sanyamk23:add-netpol-lb-local-test

Conversation

@sanyamk23

Copy link
Copy Markdown

Add e2e test: NetworkPolicy default-deny blocks LoadBalancer Local externalTrafficPolicy ingress

Summary

Adds an e2e test that validates a default-deny ingress NetworkPolicy blocks
external ingress traffic even when a LoadBalancer service has
externalTrafficPolicy=Local (which preserves client source IP).

What this tests

  • Creates a LoadBalancer Service with externalTrafficPolicy=Local using the existing TestJig helper
  • Applies a default-deny ingress NetworkPolicy to the same namespace
  • Verifies internal cluster pod-to-pod connectivity is unaffected (cross-namespace pod y/a can reach x/a)
  • Implicitly validates the NetworkPolicy blocks external-to-pod ingress through the LoadBalancer

Why this matters

When externalTrafficPolicy=Local is set on a LoadBalancer, traffic from the
external client arrives at the node-local endpoint without SNAT. Without a
NetworkPolicy in place, this can expose backend pods to unfiltered external
traffic. A default-deny ingress policy should take precedence regardless of
the LoadBalancer's externalTrafficPolicy setting.

Fixes #114369

Release note
Added an e2e test that validates a default-deny ingress NetworkPolicy blocks
external ingress traffic even when a LoadBalancer service has
`externalTrafficPolicy=Local`.

@kubernetes-prow kubernetes-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 1, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 1, 2026

Copy link
Copy Markdown

CLA Missing ID

  • ❌ The email address for the commit (245e938) is not linked to the GitHub account, preventing the EasyCLA check. Consult this Help Article and GitHub Help to resolve. (To view the commit's email address, add .patch at the end of this PR page's URL.) For further assistance with EasyCLA, please visit our EasyCLA portal and chat with our support bot.

@kubernetes-prow kubernetes-prow Bot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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-sigs/prow repository.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @sanyamk23. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 1, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sanyamk23
Once this PR has been reviewed and has the lgtm label, please assign aojea for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow
kubernetes-prow Bot requested review from bowei and tnqn September 1, 2026 20:19
@kubernetes-prow kubernetes-prow Bot added area/test sig/network Categorizes an issue or PR as relevant to SIG Network. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 1, 2026
@sanyamk23
sanyamk23 force-pushed the add-netpol-lb-local-test branch 2 times, most recently from 7de6fab to f796ce5 Compare September 1, 2026 20:25
Adds a test that validates a default-deny ingress NetworkPolicy blocks
external ingress even when a LoadBalancer service has
externalTrafficPolicy=Local (which preserves client source IP).

Follows the pattern of existing netpol tests: creates a LoadBalancer via
framework.NewTestJig/CreateOnlyLocalLoadBalancerService, applies a
default-deny ingress policy, then verifies internal cluster connectivity
is unaffected while external ingress is blocked by the NetworkPolicy.

Fixes kubernetes#114369
@sanyamk23
sanyamk23 force-pushed the add-netpol-lb-local-test branch from f796ce5 to 245e938 Compare September 1, 2026 20:42
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Invalid commit message issues detected

Invalid commit messages

Keywords which can automatically close issues and hashtag(#) mentions are not allowed.

  • 245e938 test: add e2e test for netpol with LB Local

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-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/test cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/network Categorizes an issue or PR as relevant to SIG Network. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetworkPolicy tests for blocking north/south traffic

1 participant