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

iptables: Remove NOTRACK Netfilter target #17751

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Documentation/operations/system_requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ configuration must include the following modules:
::

CONFIG_NETFILTER_XT_TARGET_TPROXY=m
CONFIG_NETFILTER_XT_TARGET_CT=m
CONFIG_NETFILTER_XT_MATCH_MARK=m
CONFIG_NETFILTER_XT_MATCH_SOCKET=m

Expand Down
24 changes: 12 additions & 12 deletions pkg/datapath/iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func getFeedRule(name, args string) []string {
}

// skipPodTrafficConntrack returns true if it's possible to install iptables
// `-j NOTRACK` rules to skip tracking pod traffic.
// `-j CT --notrack` rules to skip tracking pod traffic.
func skipPodTrafficConntrack(ipv6 bool) bool {
return !ipv6 && option.Config.InstallNoConntrackIptRules
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func (m *IptablesManager) installStaticProxyRules() error {
"-A", ciliumPreRawChain,
"-m", "mark", "--mark", matchToProxy,
"-m", "comment", "--comment", "cilium: NOTRACK for proxy traffic",
"-j", "NOTRACK"}, false)
"-j", "CT", "--notrack"}, false)
if err == nil {
// Explicit ACCEPT for the proxy traffic. Needed when the INPUT defaults to DROP.
// Matching needs to be the same as for the NOTRACK rule above.
Expand All @@ -621,7 +621,7 @@ func (m *IptablesManager) installStaticProxyRules() error {
"-o", "lxc+",
"-m", "mark", "--mark", matchProxyReply,
"-m", "comment", "--comment", "cilium: NOTRACK for proxy return traffic",
"-j", "NOTRACK"}, false)
"-j", "CT", "--notrack"}, false)
}
if err == nil {
// No conntrack for proxy return traffic that is heading to cilium_host
Expand All @@ -631,7 +631,7 @@ func (m *IptablesManager) installStaticProxyRules() error {
"-o", "cilium_host",
"-m", "mark", "--mark", matchProxyReply,
"-m", "comment", "--comment", "cilium: NOTRACK for proxy return traffic",
"-j", "NOTRACK"}, false)
"-j", "CT", "--notrack"}, false)
}
if err == nil {
// Explicit ACCEPT for the proxy return traffic. Needed when the OUTPUT defaults to DROP.
Expand All @@ -655,7 +655,7 @@ func (m *IptablesManager) installStaticProxyRules() error {
"-A", ciliumPreRawChain,
"-m", "mark", "--mark", matchToProxy,
"-m", "comment", "--comment", "cilium: NOTRACK for proxy traffic",
"-j", "NOTRACK"}, false)
"-j", "CT", "--notrack"}, false)
if err == nil {
// Explicit ACCEPT for the proxy traffic. Needed when the INPUT defaults to DROP.
// Matching needs to be the same as for the NOTRACK rule above.
Expand All @@ -673,7 +673,7 @@ func (m *IptablesManager) installStaticProxyRules() error {
"-A", ciliumOutputRawChain,
"-m", "mark", "--mark", matchProxyReply,
"-m", "comment", "--comment", "cilium: NOTRACK for proxy return traffic",
"-j", "NOTRACK"}, false)
"-j", "CT", "--notrack"}, false)
}
if err == nil {
// Explicit ACCEPT for the proxy return traffic. Needed when the OUTPUT defaults to DROP.
Expand Down Expand Up @@ -804,17 +804,17 @@ func (m *IptablesManager) endpointNoTrackRules(prog iptablesInterface, cmd strin
protocol := strings.ToLower(port.Protocol)
p := strconv.FormatUint(uint64(port.Port), 10)
if ingress {
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumPreRawChain, "-p", protocol, "-d", IP, "--dport", p, "-j", "NOTRACK"}, false); err != nil {
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumPreRawChain, "-p", protocol, "-d", IP, "--dport", p, "-j", "CT", "--notrack"}, false); err != nil {
return err
}
if _, err := prog.runProgCombinedOutput([]string{"-t", "filter", cmd, ciliumInputChain, "-p", protocol, "-d", IP, "--dport", p, "-j", "ACCEPT"}, false); err != nil {
return err
}
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumOutputRawChain, "-p", protocol, "-d", IP, "--dport", p, "-j", "NOTRACK"}, false); err != nil {
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumOutputRawChain, "-p", protocol, "-d", IP, "--dport", p, "-j", "CT", "--notrack"}, false); err != nil {
return err
}
} else {
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumOutputRawChain, "-p", protocol, "-s", IP, "--sport", p, "-j", "NOTRACK"}, false); err != nil {
if _, err := prog.runProgCombinedOutput([]string{"-t", "raw", cmd, ciliumOutputRawChain, "-p", protocol, "-s", IP, "--sport", p, "-j", "CT", "--notrack"}, false); err != nil {
return err
}
if _, err := prog.runProgCombinedOutput([]string{"-t", "filter", cmd, ciliumOutputChain, "-p", protocol, "-s", IP, "--sport", p, "-j", "ACCEPT"}, false); err != nil {
Expand Down Expand Up @@ -1418,7 +1418,7 @@ func (m *IptablesManager) ciliumNoTrackXfrmRules(prog iptablesInterface, input s
"-t", "raw", input, ciliumPreRawChain,
"-m", "mark", "--mark", match,
"-m", "comment", "--comment", xfrmDescription,
"-j", "NOTRACK"}, false); err != nil {
"-j", "CT", "--notrack"}, false); err != nil {
return err
}
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ func (m *IptablesManager) addNoTrackPodTrafficRules(prog iptablesInterface, pods
"-I", chain,
"-s", podsCIDR,
"-m", "comment", "--comment", "cilium: NOTRACK for pod traffic",
"-j", "NOTRACK"},
"-j", "CT", "--notrack"},
false); err != nil {
return err
}
Expand All @@ -1500,7 +1500,7 @@ func (m *IptablesManager) addNoTrackPodTrafficRules(prog iptablesInterface, pods
"-I", chain,
"-d", podsCIDR,
"-m", "comment", "--comment", "cilium: NOTRACK for pod traffic",
"-j", "NOTRACK"},
"-j", "CT", "--notrack"},
false); err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions test/k8sT/DatapathConfiguration.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,21 +859,21 @@ var _ = Describe("K8sDatapathConfig", func() {

Expect(testPodConnectivityAcrossNodes(kubectl)).Should(BeTrue(), "Connectivity test between nodes failed")

cmd := fmt.Sprintf("iptables -t raw -C CILIUM_PRE_raw -s %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j NOTRACK", helpers.NativeRoutingCIDR)
cmd := fmt.Sprintf("iptables -t raw -C CILIUM_PRE_raw -s %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j CT --notrack", helpers.NativeRoutingCIDR)
res = kubectl.ExecPodCmd(helpers.CiliumNamespace, ciliumPod, cmd)
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing -j NOTRACK iptables rule")
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing '-j CT --notrack' iptables rule")

cmd = fmt.Sprintf("iptables -t raw -C CILIUM_PRE_raw -d %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j NOTRACK", helpers.NativeRoutingCIDR)
cmd = fmt.Sprintf("iptables -t raw -C CILIUM_PRE_raw -d %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j CT --notrack", helpers.NativeRoutingCIDR)
res = kubectl.ExecPodCmd(helpers.CiliumNamespace, ciliumPod, cmd)
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing -j NOTRACK iptables rule")
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing '-j CT --notrack' iptables rule")

cmd = fmt.Sprintf("iptables -t raw -C CILIUM_OUTPUT_raw -s %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j NOTRACK", helpers.NativeRoutingCIDR)
cmd = fmt.Sprintf("iptables -t raw -C CILIUM_OUTPUT_raw -s %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j CT --notrack", helpers.NativeRoutingCIDR)
res = kubectl.ExecPodCmd(helpers.CiliumNamespace, ciliumPod, cmd)
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing -j NOTRACK iptables rule")
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing '-j CT --notrack' iptables rule")

cmd = fmt.Sprintf("iptables -t raw -C CILIUM_OUTPUT_raw -d %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j NOTRACK", helpers.NativeRoutingCIDR)
cmd = fmt.Sprintf("iptables -t raw -C CILIUM_OUTPUT_raw -d %s -m comment --comment 'cilium: NOTRACK for pod traffic' -j CT --notrack", helpers.NativeRoutingCIDR)
res = kubectl.ExecPodCmd(helpers.CiliumNamespace, ciliumPod, cmd)
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing -j NOTRACK iptables rule")
Expect(res.WasSuccessful()).Should(BeTrue(), "Missing '-j CT --notrack' iptables rule")

cmd = fmt.Sprintf("conntrack -L -s %s -d %s | wc -l", helpers.NativeRoutingCIDR, helpers.NativeRoutingCIDR)
res = kubectl.ExecPodCmd(helpers.CiliumNamespace, ciliumPod, cmd)
Expand Down