Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only drop invalid cstate packets if non liberal #120412

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

aojea
Copy link
Member

@aojea aojea commented Sep 4, 2023

Conntrack invalid packets may cause unexpected and subtle bugs on esblished connections, because of that we install by default an iptables rules that drops the packets with this conntrack state.

However, there are network scenarios, specially those that use multihoming nodes, that may have legit traffic that is detected by conntrack as invalid, hence these iptables rules are causing problems dropping this traffic.

An alternative to solve the spurious problems caused by the invalid connectrack packets is to set the sysctl nf_conntrack_tcp_be_liberal option, but this is a system wide setting and we don't want kube-proxy to be opinionated about the whole node networking configuration.

Kube-proxy will only install the DROP rules for invalid conntrack states if the nf_conntrack_tcp_be_liberal is not set.

/kind bug
/kind cleanup
/kind feature

Fixes #117924, #94861

Kube-proxy will only install the DROP rules for invalid conntrack states if the nf_conntrack_tcp_be_liberal is not set.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 4, 2023
@k8s-ci-robot
Copy link
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.

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.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Sep 4, 2023
@aojea
Copy link
Member Author

aojea commented Sep 4, 2023

/assign @danwinship @thockin
/cc @cyclinder

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kube-proxy sig/network Categorizes an issue or PR as relevant to SIG Network. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 4, 2023
@aojea aojea force-pushed the proxy_invalid branch 3 times, most recently from c775dfc to c68f8dd Compare September 4, 2023 22:00
Copy link
Contributor

@danwinship danwinship left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

pkg/proxy/iptables/proxier.go Outdated Show resolved Hide resolved
pkg/proxy/iptables/proxier.go Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aojea, danwinship

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

The pull request process is described here

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

Conntrack invalid packets may cause unexpected and subtle bugs
on esblished connections, because of that we install by default an
iptables rules that drops the packets with this conntrack state.

However, there are network scenarios, specially those that use multihoming
nodes, that may have legit traffic that is detected by conntrack as
invalid, hence these iptables rules are causing problems dropping this
traffic.

An alternative to solve the spurious problems caused by the invalid
connectrack packets is to set the sysctl nf_conntrack_tcp_be_liberal
option, but this is a system wide setting and we don't want kube-proxy
to be opinionated about the whole node networking configuration.

Kube-proxy will only install the DROP rules for invalid conntrack states
if the nf_conntrack_tcp_be_liberal is not set.

Change-Id: I5eb326931ed915f5ae74d210f0a375842b6a790e
@cyclinder
Copy link
Contributor

/test pull-kubernetes-node-e2e-containerd

@cyclinder
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 6, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 67ba42e16f3a2560d37df2948285d7ebdc5fa232

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

@aroradaman The problem should be the same for proxy-mode=ipvs. No issues, but some comments #74839 (comment).

Should we add this in the ipvs proxier as well?

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

Um, perhaps not. That would be an incompatible update, and likely break functionality for those who have switched to ipvs to support asymmetric routing. They may suddenly get the DROP unless they have set tcp_be_liberal

@aroradaman
Copy link
Member

@uablrek @aojea @danwinship
(I might be wrong here)

Here, If nf_conntrack_tcp_be_liberal is set we don't install DROP rules for packets marked INVALID but by enabling liberal we are telling conntrack not to mark packets as INVALID.

So this change is a no-op in terms of packet filtering, this is more like an optimization by reducing the number of rules and improving parsing speed?

@cyclinder
Copy link
Contributor

That would be an incompatible update, and likely break functionality for those who have switched to ipvs to support asymmetric routing. They may suddenly get the DROP unless they have set tcp_be_liberal

ipvs don't need the DROP rule, the admin can set nf_conntrack_tcp_be_liberal by themself, and if #120354 is merged, We can also set it thought kube-proxy.

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

ipvs don't need the DROP rule

I try to understand why. Am I right that ipvs does the NAT (in masq mode) (figure), and ipvs will do that regardless of any out-of-window problems? In other words, ipvs is always "liberal".

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

(I might be wrong here)

I think so. There are 2 problems:

  1. In unusual situations an out-of-window TCP packet can arrive. It is benign, and not really an error. But since conntrack is considering it INVALID (may be considered a kernel bug), no SNAT is done. See the figure
  2. Some K8s deployments setup asymmetric routing, or uses globally unique addresses (GUA) for IPv6 POD addresses, and don't NAT those on outgoing connects

The first problem can be solved either by setting nf_conntrack_tcp_be_liberal (the packet is not considered INVALID), or you can insert a DROP rule for packets marked INVALID.

But inserting a DROP rule, disables asymmetric routing, or using IPv6 GUA addresses for outgoing connects!

Without Antonio's PR, asymmetric routing is simply not possible in proxy-mode=iptables, but with it users can set nf_conntrack_tcp_be_liberal to suspress the DROP rule. Elegant and backward compatible.

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

IMO this is a very good description (from 2018!)

@uablrek
Copy link
Contributor

uablrek commented Sep 6, 2023

This is a limitation of conntrack which does not differentiate perfectly legal packets causing TCP window overflow from actually malformed packets (all get treated as INVALID).

@danwinship This may be an argument for upgrading the "limitation" to a kernel bug?

@cyclinder
Copy link
Contributor

cyclinder commented Sep 6, 2023

As far as I know, ipvs handles SNAT/DNAT in a separate kernel module(INPUT Chain), but it also relies on conntrack, I'm not sure if there is the same problem. I think yes.

ipvs don't need the DROP rule

I want to say that this PR is for iptables mode to handle the issue of asymmetric routing and keep backward compatibility, while ipvs mode does not require this PR, support for setting the sysctl is enough.

@danwinship
Copy link
Contributor

danwinship commented Sep 6, 2023

@danwinship This may be an argument for upgrading the "limitation" to a kernel bug?

copying from #117924 (comment):

the bug (at least in the form that we are causing it in our regression test) is fixed in kernel 6.2 6.1 ("netfilter: conntrack: ignore overly delayed tcp packet").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kube-proxy cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. 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.

"Connection reset by peer" due to invalid conntrack packets
7 participants