recalculate network policies for established connections#253
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aojea The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
71ae57a to
4f32f27
Compare
e39599d to
dda56ff
Compare
f1f3f84 to
6e69983
Compare
danwinship
left a comment
There was a problem hiding this comment.
So I was imagining something more like: "when policies/namespaces/pods change, figure out what IPs are no longer allowed, and then drop conntrack entries for those IPs". But I guess k-n-p doesn't work like that at all so that wouldn't make sense.
I don't remember all the details of how k-n-p currently works, but one thing to note is that some events that require updating NetworkPolicy enforcement are guaranteed not to require deleting conntrack entries. In particular, adding or deleting a Pod or Namespace does not require deleting conntrack entries.
|
it does not work flushing the conntrack entry, the connection is not sent through the queue, subsequent packets are treated as established |
6e69983 to
dbb232f
Compare
| chain forward-established { | ||
| type filter hook forward priority filter - 5; policy accept; | ||
| ct state established ip saddr . th sport . ip daddr . th dport . meta l4proto @block-tuple-v4 reject with icmp port-unreachable | ||
| ct state established ip6 saddr . th sport . ip6 daddr . th dport . meta l4proto @block-tuple-v6 reject with icmpv6 addr-unreachable | ||
| } |
There was a problem hiding this comment.
we need to do something like this , is the only way I find out we can "break" existing connections https://lore.kernel.org/netfilter-devel/20250313231341.3040002-1-aojea@google.com/T/#m44c410cd56bdc62cc717798a0e28ee4dcaaab9ad
135c13a to
54eeaef
Compare
|
Ok, I have a better understanding now of the problem, assume TCP and UDP only by now For UDP just clean up the conntrack entry, next one will be sent to userspace with the nfqueu
https://lwn.net/Articles/1037388/ It seems cilium folks went through this already and have pretty good description of the problem and are adding the necessary tooling to the stack cilium/cilium#25169 |
EDIT: oh, wait, that doesn't matter for NetworkPolicy purposes; you can postpone evaluation until the destination node |
yeah, since we want to break existing connections, and it seems we need to be "invasive" we need to make local decisions only ... current code can optimize making decisions for the flow in both directions in the originating node ... By the way, talked with one team mate working on the ebpf socket destroy problem internally, and he told me that there is no better solution than iterating through namespaces to find the sockets ... I need to check if we can get the information from the conntrack entry or we can store the relation Pod/IP to network namespace and use it, then the good news is that we can just use netlink, is what |
5c73879 to
49fcf83
Compare
ae73d94 to
487a91a
Compare
487a91a to
1eccd32
Compare
e6dc0bf to
125a9d0
Compare
is it possible for a network policy or namespace or pod labels to change during the lifetime of this objects. Since these changes can impact the policy over the connectons already established we need to reevaluate them, in order to do that, we just check the existing conntrack entries and we clean them to force the subsequent packets to go over the nfqueue process for non TCP connections. For TCP connections we try to find the socket and kill it.
125a9d0 to
1ddc43a
Compare
|
@danwinship it took me more than I expected, found also some bugs on the libraries, but now is working as expected, as we can see in the logs of the e2e test added please let me know if you want to review |
89c1d8d to
94ef330
Compare
94ef330 to
0ca0559
Compare
|
talked offline, explained current algorithm and implementation and we are good on merging and iterating |
Fixes: #246