Skip to content

resolve implementation-defined behavior around hairpin packets in CNP #343

@danwinship

Description

@danwinship

There is some unspecified/implementation-defined behavior involving hairpin packets in NetworkPolicy, which is currently also implementation-defined in ClusterNetworkPolicy... We should try to make them well-defined.

Consider a Service X with endpoint Pods A and B, which are both fully isolated.

  1. Simple hairpinning: If pod A connects to its own podIP, does this succeed despite NetworkPolicy? ("Yes"?)
  2. Service hairpinning: If pod A connects to Service X and the service proxy redirects the packet back to pod A, does this succeed despite NetworkPolicy? ("Yes"?) (EDIT: or "No"?)
  3. Service hairpinning miss: If pod A connects to Service X and the service proxy redirects the packet to pod B, does this succeed despite NetworkPolicy? ("No"?)
  4. Service masquerading: If, due to hairpinning or other reasons, the service proxy decides to masquerade a packet, should that packet then be matched against rules for its original source IP or the masqueraded IP? ("Uh....")

I think everyone agrees the answer to the first question is "yes" and the third one is "no". This means the answer to the second question must be inconsistent with one of them. I think these days, everyone says that the answer to the second question is "yes" (obeying the general rule that "NetworkPolicy doesn't see Services", and thus the exception for hairpinned packets from the first case applies). It's possible I'm wrong and Cilium does things differently though? (From some quick searches, it looks like Cilium used to do things differently, but now does things the same way everyone else does.)

The fourth case seems unrelated, but I believe that Calico and kube-network-policies don't specifically handle the second case, and they only get it "right" because kube-proxy is masquerading the packet to the node IP, and so then it hits the magic "all packets from the local node are allowed" rule for kubelet probes. So it's worth thinking about whether this is a bug or a feature...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions