Skip to content

Conversation

aditighag
Copy link
Member

@aditighag aditighag commented Mar 11, 2021

bpf: Skip policy enforcements for service loopback case

When an endpoint connects to itself via service clusterIP, we hairpin the
flow using a loopback IP address (configured using --ipv4-service-loopback-address).
The destination clusterIP (on egress) and loopback IP (on ingress) map to incorrect identities.
As a result, the subsequent egress and ingress policy enforcements lead to packet drops.

This is evident from the monitor output -

<- endpoint 1844 flow 0x96c8d52 identity 55108->unknown state new ifindex 0 orig-ip 0.0.0.0: 10.12.0.123:58242 -> 172.20.0.130:80 tcp SYN Policy verdict log: flow 0x96c8d52 local EP ID 1844, remote ID world, proto 6, egress, action deny, match none, 169.254.42.1:58242 -> 10.12.0.123:80 tcp SYN

Skip policy enforcements (ingress and egress) in such cases since we
should allow a pod to connect to itself.

Release note

Fix an issue where packets are dropped when a pod connects to itself via a service clusterIP.

Signed-off-by: Aditi Ghag aditi@cilium.io
Co-authored-by: Paul Chaignon paul@cilium.io
Fixes: #11593

@aditighag aditighag added release-note/bug This PR fixes an issue in a previous release of Cilium. needs-backport/1.7 labels Mar 11, 2021
@aditighag aditighag requested review from a team and jibi March 11, 2021 21:35
@aditighag aditighag marked this pull request as draft March 11, 2021 21:38
@pchaigno pchaigno self-requested a review March 11, 2021 21:40
@pchaigno pchaigno added area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. labels Mar 11, 2021
@aditighag aditighag force-pushed the pr/aditighag/svc-policy-loopback-fix branch from 91ba240 to c759535 Compare March 11, 2021 22:02
@aditighag
Copy link
Member Author

test-me-please

@aditighag aditighag force-pushed the pr/aditighag/svc-policy-loopback-fix branch 3 times, most recently from 3749b7f to 0bae7f5 Compare March 12, 2021 07:40
@aditighag aditighag requested a review from joestringer March 12, 2021 07:55
Copy link
Member

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

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

Just posting to keep the context on changes, but I have a new version locally. I added the same for the IPv6 path and removed policy verdict notifications, but I'm still testing changes to address my second comment (ingress path). It's a bit more tortuous than I thought.

@pchaigno pchaigno force-pushed the pr/aditighag/svc-policy-loopback-fix branch 2 times, most recently from 078659e to 58fb824 Compare March 12, 2021 18:21
Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

Fix itself LGTM, one minor nit for better code consistency. Would also be good to see an integration test to guard against regressions and run against different datapath modes.

@pchaigno
Copy link
Member

pchaigno commented Mar 12, 2021

The single failure is https://jenkins.cilium.io/job/Cilium-PR-K8s-1.20-kernel-4.9/953/testReport/junit/Suite-k8s-1/20/K8sDatapathConfig_AutoDirectNodeRoutes_Check_direct_connectivity_with_per_endpoint_routes/.
Let's see if it's a flake:
test-only --k8s_version=1.20 --kernel_version=4.9 --focus="K8sDatapathConfig AutoDirectNodeRoutes Check direct connectivity with per endpoint routes"

@pchaigno
Copy link
Member

We've hit a complexity issue on 4.9:

2021-03-12T20:24:59.215993300Z level=error msg="Command execution failed" cmd="[tc filter replace dev lxc065036eb6f09 egress prio 1 handle 1 bpf da obj 878_next/bpf_lxc.o sec to-container]" error="exit status 1" subsys=datapath-loader
2021-03-12T20:24:59.216059006Z level=warning subsys=datapath-loader
2021-03-12T20:24:59.216099499Z level=warning msg="Prog section 'to-container' rejected: Argument list too long (7)!" subsys=datapath-loader
2021-03-12T20:24:59.216136474Z level=warning msg=" - Type:         3" subsys=datapath-loader
2021-03-12T20:24:59.216172463Z level=warning msg=" - Attach Type:  0" subsys=datapath-loader
2021-03-12T20:24:59.216223310Z level=warning msg=" - Instructions: 1737 (0 over limit)" subsys=datapath-loader
2021-03-12T20:24:59.216260150Z level=warning msg=" - License:      GPL" subsys=datapath-loader
2021-03-12T20:24:59.216295383Z level=warning subsys=datapath-loader
2021-03-12T20:24:59.216331021Z level=warning msg="Verifier analysis:" subsys=datapath-loader
2021-03-12T20:24:59.216366262Z level=warning subsys=datapath-loader
2021-03-12T20:24:59.216402404Z level=warning msg="Skipped 4596416 bytes, use 'verb' option for the full verbose log." subsys=datapath-loader
2021-03-12T20:24:59.221033201Z level=warning msg="1332: (71) r2 = *(u8 *)(r10 -84)" subsys=datapath-loader
2021-03-12T20:24:59.221035300Z level=warning msg="BPF program is too large. Proccessed 98305 insn" subsys=datapath-loader

@pchaigno
Copy link
Member

pchaigno commented Apr 1, 2021

I've removed the v1.9 backport label until we address the complexity issue.

@brb
Copy link
Member

brb commented Apr 1, 2021

I've removed the v1.9 backport label until we address the complexity issue.

It's a very corner case for the policy enforcement. Shall we just say - this won't work on v1.9, so just use v1.10 instead if you want this?

@pchaigno
Copy link
Member

pchaigno commented Apr 1, 2021

It already works in v1.8, we can't break it in v1.9.

@brb
Copy link
Member

brb commented Apr 1, 2021

Then we can list it as undefined behavior on < v1.10. If users are hit by this, then they 1) can switch to the socket-LB or 2) modify a netpol to accept packets from the svc loopback IP addr.

aditighag added a commit to aditighag/cilium that referenced this pull request Apr 29, 2021
Test for PR cilium#15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
aditighag added a commit that referenced this pull request Apr 29, 2021
[ upstream commit 799bc1 ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
rolinh pushed a commit that referenced this pull request Apr 30, 2021
Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
christarazi pushed a commit that referenced this pull request May 3, 2021
[ upstream commit 69f10ed ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
glibsm pushed a commit to glibsm/cilium that referenced this pull request May 4, 2021
[ upstream commit 69f10ed ]

Test for PR cilium#15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

backport-1.8: Resolved conflicts in test change and variable
aligning

Signed-off-by: Aditi Ghag <aditi@cilium.io>
Signed-off-by: Glib Smaga <code@gsmaga.com>
ti-mo pushed a commit that referenced this pull request May 5, 2021
[ upstream commit 69f10ed ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
joestringer pushed a commit that referenced this pull request May 6, 2021
[ upstream commit 69f10ed ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

backport-1.8: Resolved conflicts in test change and variable
aligning

Signed-off-by: Aditi Ghag <aditi@cilium.io>
Signed-off-by: Glib Smaga <code@gsmaga.com>
brb pushed a commit that referenced this pull request May 7, 2021
[ upstream commit 69f10ed ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
aanm pushed a commit that referenced this pull request May 11, 2021
[ upstream commit 69f10ed ]

Test for PR #15321 - tests the case where a pod
connects to itself via service clusterIP when selected
by a policy.

Signed-off-by: Aditi Ghag <aditi@cilium.io>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Endpoint unable to connect itself to via service IP with policy enabled
9 participants