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

bpf: Fix host firewall in presence of kube-proxy masquerading #13049

Merged
merged 4 commits into from Sep 14, 2020

Conversation

pchaigno
Copy link
Member

@pchaigno pchaigno commented Sep 2, 2020

If kube-proxy is in use (no BPF-based masquerading), packets from pods may be SNATed. The response packet will therefore have a host IP as the destination IP. For example, if a pod connects to 1.1.1.1:

# Pod sends a SYN.
from-lxc: 10.8.0.1 -> 1.1.1.1
# Src IP gets masqueraded to 192.168.33.11. We skip the host firewall because
# the packet mark tells us this is not coming from hostns.
to-netdev: 192.168.33.11 -> 1.1.1.1
...
# SYN+ACK is sent to 192.168.33.11. This IP belongs to the host endpoints, so
# we incorrectly enforce host policy on this packet.
from-netdev: 1.1.1.1 -> 192.168.33.11

To avoid enforcing host policies for response packets to pods, we need to create a CT entry for the forward, SNATed packet from the pod. Response packets will thus match this CT entry and bypass host policies.

I tested this change by deploying the connectivity checks in the dev. VM with kube-proxy and the lock-down-dev-vms.yaml host policy. The second commit also updates the CIDR+toPorts host policy test to run it when kube-proxy is used. Finally, the pull request has label ci/host-firewall to run all e2e CI tests on Jenkins with the host firewall enabled by default.

RFC. I've marked this pull request as RFC because of the performance concern. With this PR, when the host firewall and kube-proxy are enabled, we will perform a CT lookup (+ some CT updates) for each packet ingressing or egressing on the native devices. The only alternative I found so far is to restrict the host firewall to kube-proxy-free mode ☹️

Fixes: #11507

@pchaigno pchaigno added sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/minor This PR changes functionality that users may find relevant to operating Cilium. area/host-firewall Impacts the host firewall or the host endpoint. ci/host-firewall This label enables the host firewall by default in all CI tests. labels Sep 2, 2020
@pchaigno pchaigno force-pushed the pr/pchaigno/fix-hostfw-kube-proxy-masq branch 2 times, most recently from d6c5ac4 to 41e66f1 Compare September 2, 2020 19:56
@pchaigno pchaigno added release-note/bug This PR fixes an issue in a previous release of Cilium. and removed release-note/minor This PR changes functionality that users may find relevant to operating Cilium. labels Sep 2, 2020
@pchaigno pchaigno changed the title Fix host firewall in presence of kube-proxy masquerading [RFC] Fix host firewall in presence of kube-proxy masquerading Sep 7, 2020
If kube-proxy is in use (no BPF-based masquerading), packets from pods may
be SNATed. The response packet will therefore have a host IP as the
destination IP. For example, if a pod connects to 1.1.1.1:

  # Pod sends a SYN.
  from-lxc: 10.8.0.1 -> 1.1.1.1
  # Src IP gets masqueraded to 192.168.33.11. We skip the host firewall
  # because the packet mark tells us this is not coming from hostns.
  to-netdev: 192.168.33.11 -> 1.1.1.1
  ...
  # SYN+ACK is sent to 192.168.33.11. This IP belongs to the host
  # endpoints, so we incorrectly enforce host policy on this packet.
  from-netdev: 1.1.1.1 -> 192.168.33.11

To avoid enforcing host policies for response packets to pods, we need to
create a CT entry for the forward, SNATed packet from the pod. Response
packets will thus match this CT entry and bypass host policies.

I tested this change by deploying the connectivity checks in the dev. VM
with kube-proxy and the lock-down-dev-vms.yaml host policy. A subsequent
commit also updates the CIDR+toPorts host policy test to run it when
kube-proxy is used. Finally, the pull request has label ci/host-firewall
to run all e2e CI tests on Jenkins with the host firewall enabled by
default.

Fixes: 88bf291 ("bpf: Enforce host policies for IPv4")
Signed-off-by: Paul Chaignon <paul@cilium.io>
Previous commit fixed the host firewall to work with kube-proxy. Thus,
we can now run the CIDR+toPorts test for the host firewall when
kube-proxy is enabled.

Signed-off-by: Paul Chaignon <paul@cilium.io>
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.8.3 Sep 7, 2020
This includes allowing some services that were not present on the
release-channel=rapid GKE clusters.

Signed-off-by: Paul Chaignon <paul@cilium.io>
Signed-off-by: Paul Chaignon <paul@cilium.io>
@pchaigno pchaigno force-pushed the pr/pchaigno/fix-hostfw-kube-proxy-masq branch from 41e66f1 to a14ea2d Compare September 7, 2020 14:48
@pchaigno pchaigno marked this pull request as ready for review September 7, 2020 14:49
@pchaigno pchaigno requested a review from a team September 7, 2020 14:49
@pchaigno pchaigno requested review from a team as code owners September 7, 2020 14:49
@pchaigno
Copy link
Member Author

pchaigno commented Sep 7, 2020

test-me-please

Copy link
Member

@nebril nebril left a comment

Choose a reason for hiding this comment

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

CI bit looks good (yay for not skipping tests!).

@pchaigno pchaigno changed the title [RFC] Fix host firewall in presence of kube-proxy masquerading Fix host firewall in presence of kube-proxy masquerading Sep 14, 2020
@pchaigno pchaigno changed the title Fix host firewall in presence of kube-proxy masquerading bpf: Fix host firewall in presence of kube-proxy masquerading Sep 14, 2020
@joestringer joestringer removed this from Needs backport from master in 1.8.3 Sep 14, 2020
@joestringer joestringer added this to Needs backport from master in 1.8.4 Sep 14, 2020
@vadorovsky vadorovsky merged commit 4028da9 into master Sep 14, 2020
@vadorovsky vadorovsky deleted the pr/pchaigno/fix-hostfw-kube-proxy-masq branch September 14, 2020 19:45
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.8 in 1.8.4 Sep 16, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Needs backport from master to Backport pending to v1.8 in 1.8.4 Sep 16, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot moved this from Backport pending to v1.8 to Backport done to v1.8 in 1.8.4 Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/host-firewall Impacts the host firewall or the host endpoint. ci/host-firewall This label enables the host firewall by default in all CI tests. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
No open projects
1.8.4
Backport done to v1.8
Development

Successfully merging this pull request may close these issues.

None yet

5 participants