Skip to content

removal logic in v1.17 for handling the from-wireguard program on Cilium downgrade from v1.18#38187

Merged
julianwiedmann merged 1 commit intocilium:v1.17from
smagnani96:pr/cil-from-wireguard-removal-logic-v1.17
Mar 20, 2025
Merged

removal logic in v1.17 for handling the from-wireguard program on Cilium downgrade from v1.18#38187
julianwiedmann merged 1 commit intocilium:v1.17from
smagnani96:pr/cil-from-wireguard-removal-logic-v1.17

Conversation

@smagnani96
Copy link
Copy Markdown
Contributor

@smagnani96 smagnani96 commented Mar 13, 2025

This is the minimum logic required to be present in v1.17 for handling Cilium downgrade from v1.18.
In v1.18 we transition to a dedicated cil_from_wireguard program, which replaces the previous cil_from_netdev.
Upon downgrading Cilium, we therefore need the logic to always detach the cil_from_wireguard in favor of cil_from_netdev to preserve connectivity.

from-wireguard feature in v1.18 that requires this commit in v1.17 #38077 (Issue #33676)

Removal logic for the new cil_from_wireguard program to handle Cilium Downgrades from v1.18.

@smagnani96 smagnani96 added kind/enhancement This would improve or streamline existing functionality. area/encryption Impacts encryption support such as IPSec, WireGuard, or kTLS. release-note/misc This PR makes changes that have no direct user impact. feature/wireguard Relates to Cilium's Wireguard feature labels Mar 13, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added backport/1.17 This PR represents a backport for Cilium 1.17.x of a PR that was merged to main. kind/backports This PR provides functionality previously merged into master. labels Mar 13, 2025
@smagnani96 smagnani96 changed the title Pr/cil from wireguard removal logic v1.17 [v1.17] removal logic for v1.18 cil from wireguard for downgrades Mar 13, 2025
@smagnani96 smagnani96 changed the title [v1.17] removal logic for v1.18 cil from wireguard for downgrades [v1.17] removal logic for the v1.18 from-wireguard program on Cilium downgrade Mar 13, 2025
@smagnani96 smagnani96 force-pushed the pr/cil-from-wireguard-removal-logic-v1.17 branch 2 times, most recently from 8b70c6a to c17886f Compare March 13, 2025 22:47
@smagnani96 smagnani96 force-pushed the pr/cil-from-wireguard-removal-logic-v1.17 branch from c17886f to 4a9aac6 Compare March 14, 2025 00:25
@rgo3 rgo3 self-requested a review March 14, 2025 09:45
@smagnani96 smagnani96 force-pushed the pr/cil-from-wireguard-removal-logic-v1.17 branch from 4a9aac6 to 322e835 Compare March 14, 2025 14:22
This commit adds the needed logic to handle removal of the new program
cil_from_wireguard introduced in v1.18 and attached to the ingress of
cilium_wg0, replacing our previous cil_from_netdev.
These are the possible scenarios while downgrading Cilium:

* WireGuard is not enabled anymore => interface will be deleted, don't
  need to manually handle program detach;
* ingress hook is still needed => attachNetworkDevices() will attach the
  previous cil_from_netdev to the hook and will immediately detach the
  cil_from_wireguard to prevent disruptions;
* ingress hook is not needed anymore => replaceWireguardDatapath() will
  remove the program if present.

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
@smagnani96 smagnani96 force-pushed the pr/cil-from-wireguard-removal-logic-v1.17 branch from 322e835 to 0ccc0fb Compare March 18, 2025 11:45
@smagnani96
Copy link
Copy Markdown
Contributor Author

/test

@smagnani96 smagnani96 marked this pull request as ready for review March 18, 2025 14:34
@smagnani96 smagnani96 requested a review from a team as a code owner March 18, 2025 14:34
@smagnani96 smagnani96 changed the title [v1.17] removal logic for the v1.18 from-wireguard program on Cilium downgrade removal logic in v1.17 for handling the from-wireguard program on Cilium downgrade from v1.18 Mar 18, 2025
@smagnani96 smagnani96 added dont-merge/discussion A discussion is ongoing and should be resolved before merging, regardless of reviews & tests status. and removed kind/backports This PR provides functionality previously merged into master. backport/1.17 This PR represents a backport for Cilium 1.17.x of a PR that was merged to main. labels Mar 18, 2025
Copy link
Copy Markdown
Contributor

@rgo3 rgo3 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@smagnani96 smagnani96 removed the dont-merge/discussion A discussion is ongoing and should be resolved before merging, regardless of reviews & tests status. label Mar 20, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Mar 20, 2025
@julianwiedmann julianwiedmann added this pull request to the merge queue Mar 20, 2025
Merged via the queue into cilium:v1.17 with commit f77b43f Mar 20, 2025
60 checks passed
smagnani96 added a commit that referenced this pull request Mar 25, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Mar 25, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Mar 25, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Mar 31, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 1, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 1, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 1, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 2, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 2, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 3, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 7, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 22, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

Upgrades/Downgrades are correctly handles also due to changin the cilium
tailcall map used in the wireguard code path in v1.18: if we preserved the
same name cilium_calls_wireguard_2 than v1.17, when downgrading we could
experiment MissingTailCall erorr, given that the new from-wireguard program
would be still in place while the calls map is completely overwritten from
replaceWireguard. The from-wireguard program is later detached upon
re-inserting the old from-netdev, but for that time window it would not
be able to handle packets, leaving them for the stack (in most of the
cases they'd be still reaching their endpoints).

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 23, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

Upgrades/Downgrades are correctly handles also due to changin the cilium
tailcall map used in the wireguard code path in v1.18: if we preserved the
same name cilium_calls_wireguard_2 than v1.17, when downgrading we could
experiment MissingTailCall erorr, given that the new from-wireguard program
would be still in place while the calls map is completely overwritten from
replaceWireguard. The from-wireguard program is later detached upon
re-inserting the old from-netdev, but for that time window it would not
be able to handle packets, leaving them for the stack (in most of the
cases they'd be still reaching their endpoints).

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
smagnani96 added a commit that referenced this pull request Apr 24, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

Upgrades/Downgrades are correctly handles also due to changin the cilium
tailcall map used in the wireguard code path in v1.18: if we preserved the
same name cilium_calls_wireguard_2 than v1.17, when downgrading we could
experiment MissingTailCall erorr, given that the new from-wireguard program
would be still in place while the calls map is completely overwritten from
replaceWireguard. The from-wireguard program is later detached upon
re-inserting the old from-netdev, but for that time window it would not
be able to handle packets, leaving them for the stack (in most of the
cases they'd be still reaching their endpoints).

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
github-merge-queue bot pushed a commit that referenced this pull request Apr 24, 2025
We currently need to attach `cil_from_netdev` to the ingress hook of the
Wireguard `cilium_wg0` device to enable encryption of KPR traffic in native
routing. In that case, a reply packet would be otherwise dropped due
to lacking of rev-SNAT/DNAT (for further info, please refer to the Issue/PR
#19401).

However, we don't need the whole logic, which might be problematic as described
in #19401 (comment):
in case of host firewall enabled, policy enforcement would not only
(erroneously) happen, but they would also be applied ONLY to the ingress
hook of the wireguard device.

Let's switch to a dedicated program with the minimal set of needed
features. The new `cil_from_wireguard` must look as much as possible to
the previous `cil_from_netdev`, while additionally dropping not needed
features. For this reason, here's the list of codepaths that have been
either dropped or preserved:

* Codepaths dropped:
    * ENABLE_NODEPORT_ACCELERATION
    * ctx->vlan_present
    * ENABLE_HOST_FIREWALL
    * ENABLE_IPSEC
    * ENABLE_ARP_PASSTHROUGH || ENABLE_ARP_RESPONDER || ENABLE_L2_ANNOUNCEMENTS
* Codepaths preserved:
    * ENABLE_IPV4_FRAGMENTS
    * ENABLE_NODEPORT
    * ENABLE_HOST_ROUTING

This means that the new wireguard program, as well as the previously
attached from_netdev, is able to locally deliver packets to endpoints.
However, differently than `cil_from_overlay`, if an endpoint is not
identified, the packet is left for the stack.

This patch supports Cilium version upgrades with the removal of
the previously used cil_from_netdev. Having both the old from-netdev and
the new from-wireguard programs attached causes connectivity problems,
therefore here we make sure to always detach the old program.
For downgrades, we previously landed in v1.17 (i) the removal logic for
the newly introduced calls_map, and (ii) the removal logic for the new
from-wireguard program #38187: this
means that, upon downgrading Cilium, we are able to:

* TCX: (1) re-attach from-netdev then (2) remove from-wireguard
* TC: replace existing filter with the previous from-netdev

Upgrades/Downgrades are correctly handles also due to changin the cilium
tailcall map used in the wireguard code path in v1.18: if we preserved the
same name cilium_calls_wireguard_2 than v1.17, when downgrading we could
experiment MissingTailCall erorr, given that the new from-wireguard program
would be still in place while the calls map is completely overwritten from
replaceWireguard. The from-wireguard program is later detached upon
re-inserting the old from-netdev, but for that time window it would not
be able to handle packets, leaving them for the stack (in most of the
cases they'd be still reaching their endpoints).

An additional thing to note, is that with the cil_from_wireguard program
inserted we preserve the same packets' path as before when we used to
attach from_netdev rather than from_wg:

* Request pod-to-pod: to_pod->to_ndetdev->to_wg->to_ndetdev
* Reply pod-to-pod:   from_netdev->from_wg->from_pod

Signed-off-by: Simone Magnani <simone.magnani@isovalent.com>
@smagnani96 smagnani96 deleted the pr/cil-from-wireguard-removal-logic-v1.17 branch May 21, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/encryption Impacts encryption support such as IPSec, WireGuard, or kTLS. feature/wireguard Relates to Cilium's Wireguard feature kind/enhancement This would improve or streamline existing functionality. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants