projectcalico / calico

Cloud native networking and network security
https://docs.tigera.io/calico/latest/about/
Apache License 2.0
5.91k stars 1.32k forks source link

Provide mechanism to modify established connections #6399

Open 0m1xa opened 2 years ago

0m1xa commented 2 years ago

I faced the situation when deletion (and maybe creation) of the policy doesn't affect the pod(s). I guess the main problem is that calico doesn't modify established connections. And if the pod has a persistent connection then changes will not affect it.

Expected Behavior

Modify the established connections as well.

Current Behavior

The state of the established connections doesn't change.

Context

It is a great example to use reloader.

Your Environment

caseydavenport commented 2 years ago

I think it's worth pointing out here that the Kubernetes NetworkPolicy API is intended to operate on connections and not packets: https://kubernetes.io/docs/concepts/services-networking/network-policies/

So, the current behavior is the "correct" one in terms of the Kubernetes API. However, I can imagine it might be desirable to have a way to invalidate existing allowed connections as a separate feature.

0m1xa commented 2 years ago

@caseydavenport Exactly! I'd like to see an additional feature to invalidate connections.

sanmai-NL commented 1 year ago

@caseydavenport Can you cite where is says that unequivocally?

caseydavenport commented 12 months ago

@sanmai-NL just searching for "connection" in that linked document in my previous comment brings up several examples, but these say it best:

NetworkPolicies apply to a connection with a pod on one or both ends

and

There are two sorts of isolation for a pod: isolation for egress, and isolation for ingress. They concern what connections may be established.

sanmai-NL commented 12 months ago

I think that indeed suggests but certainly doesn't assert exclusive applicability to connections. Indeed, that would be inconsistent since NetworkPolicys can cover UDP, which is not connection-oriented.

caseydavenport commented 12 months ago

Yes, UDP as a protocol isn't connection oriented, but there are still distinct UDP connections and UDP flows identified by the kernel and tracked via connection tracking (conntrack on Linux) much like TCP. NetworkPolicy applies to them similarly - e.g., you don't need to allow return traffic explicitly, it is identified as part of that UDP "connection" and allowed implicitly.

I think the discussion you're having in https://github.com/kubernetes/kubernetes/issues/120525 covers this pretty well.

It seems the stance from SIG network is now "the behavior is undefined", in which case the answer here remains that Calico's implementation does not impact any existing connections, and that it's a reasonable enhancement request to have an opt-in way to invalidate connections instead.

zoglam commented 7 months ago

Did you found another way to solve the problem? @0m1xa Maybe without using calico

0m1xa commented 7 months ago

Did you found another way to solve the problem? @0m1xa Maybe without using calico

@zoglam Yes, I did. Cilium :satisfied: