race between weave-kube and kube-proxy can allow all traffic through Service VIP #3230
Description
kube-proxy pre-appends the iptables rule "-j KUBE-FORWARD" which ACCEPTs all traffic and prevents it entering the "WEAVE-NPC" chain.
In #3210 we introduced a fix which pre-appends "-j WEAVE-NPC" after kube-proxy has inserted "-j KUBE-FORWARD". The fix relies on a premise that weave-kube is started after kube-proxy which follows from a fact that weave-kube depends on api-server (to get a peer list) and api-server is accessible to weave-kube only after kube-proxy has inserted all nat rules.
However, if the nat rules for api-server are present (e.g. from previous k8s installation which failed to flush them), then weave-kube can start before kube-proxy, and thus the WEAVE-NPC rule will be preceded by the KUBE-FORWARD => all traffic will be enabled to Pods through Service Virtual IP.
(Maybe) possible fixes to the problem:
- Try creating a dummy Service before starting weaver in
weave-kube/launch.sh
to ensure that kube-proxy is running. - Monitor iptables rules and ensure the required order.
- Wait for "KUBE-FORWARD" chain to appear before inserting "WEAVE-NPC" (requires checking k8s vsn and kube-proxy backend).
- Wait for an answer to Kube-proxy adds forward rules to ensure NodePorts work kubernetes/kubernetes#52569 (comment).