Skip to content

Commit 8bed088

Browse files
committed
kubelet: block non-forwarded packets from crossing the localhost boundary
We set route_localnet so that host-network processes can connect to <127.0.0.1:NodePort> and it still works. This, however, is too permissive. So, block martians that are not already in conntrack. See: kubernetes#90259 Signed-off-by: Casey Callendrello <[email protected]>
1 parent 83f3430 commit 8bed088

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/kubelet/kubelet_network_linux.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ func (kl *Kubelet) syncNetworkUtil() {
7777
klog.Errorf("Failed to ensure rule to drop packet marked by %v in %v chain %v: %v", KubeMarkDropChain, utiliptables.TableFilter, KubeFirewallChain, err)
7878
return
7979
}
80+
81+
// drop all non-local packets to localhost if they're not part of an existing
82+
// forwarded connection. See #90259
83+
if !kl.iptClient.IsIPv6() { // ipv6 doesn't have this issue
84+
if _, err := kl.iptClient.EnsureRule(utiliptables.Append, utiliptables.TableFilter, KubeFirewallChain,
85+
"-m", "comment", "--comment", "block incoming localnet connections",
86+
"--dst", "127.0.0.0/8",
87+
"!", "--src", "127.0.0.0/8",
88+
"-m", "conntrack",
89+
"!", "--ctstate", "RELATED,ESTABLISHED,DNAT",
90+
"-j", "DROP"); err != nil {
91+
klog.Errorf("Failed to ensure rule to drop invalid localhost packets in %v chain %v: %v", utiliptables.TableFilter, KubeFirewallChain, err)
92+
return
93+
}
94+
}
95+
8096
if _, err := kl.iptClient.EnsureRule(utiliptables.Prepend, utiliptables.TableFilter, utiliptables.ChainOutput, "-j", string(KubeFirewallChain)); err != nil {
8197
klog.Errorf("Failed to ensure that %s chain %s jumps to %s: %v", utiliptables.TableFilter, utiliptables.ChainOutput, KubeFirewallChain, err)
8298
return

0 commit comments

Comments
 (0)