Skip to content

IPsec VinE Implementation#37723

Merged
ldelossa merged 8 commits intomainfrom
ldelossa/ipsec-vxlan-in-esp
Apr 21, 2025
Merged

IPsec VinE Implementation#37723
ldelossa merged 8 commits intomainfrom
ldelossa/ipsec-vxlan-in-esp

Conversation

@ldelossa
Copy link
Copy Markdown
Contributor

@ldelossa ldelossa commented Feb 18, 2025

Implement IPsec VinE

See commits for details.

Add support for VXLAN in IPsec (VinE)

@maintainer-s-little-helper
Copy link
Copy Markdown

@maintainer-s-little-helper maintainer-s-little-helper bot added dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Feb 18, 2025
@github-actions github-actions bot added the cilium-cli This PR contains changes related with cilium-cli label Feb 18, 2025
@ldelossa ldelossa added release-note/major This PR introduces major new functionality to Cilium. and removed cilium-cli This PR contains changes related with cilium-cli labels Feb 18, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Feb 18, 2025
@ldelossa ldelossa force-pushed the ldelossa/ipsec-vxlan-in-esp branch from 6e08fac to 97e66cf Compare February 18, 2025 18:49
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-sign-off The author needs to add signoff to their commits before merge. label Feb 18, 2025
@ldelossa ldelossa force-pushed the ldelossa/ipsec-vxlan-in-esp branch from 97e66cf to cf4f1d3 Compare February 18, 2025 20:19
Copy link
Copy Markdown
Member

@julianwiedmann julianwiedmann left a comment

Choose a reason for hiding this comment

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

Some comments in-line :)

@jschwinger233 jschwinger233 added the feature/ipsec Relates to Cilium's IPsec feature label Feb 20, 2025
@ldelossa ldelossa added the pinned These issues are not marked stale by our issue bot. label Feb 20, 2025
@ldelossa ldelossa force-pushed the ldelossa/ipsec-vxlan-in-esp branch 3 times, most recently from 4f36d57 to b075675 Compare February 25, 2025 18:16
@ldelossa ldelossa force-pushed the ldelossa/ipsec-vxlan-in-esp branch 6 times, most recently from 4cad2ea to 7c1c9c8 Compare March 4, 2025 00:00
@jschwinger233
Copy link
Copy Markdown
Member

jschwinger233 commented Apr 16, 2025

I still want to draw attention to the facts that ipsec encryption logic has changes:

  1. Overlay encryption. 118 encrypts all overlay packets without inspecting the inner layer, while 117 makes encryption decision based on inner tuple. Egress gateway traffic will be affected.
  2. Spi lookup. 118 always uses spi from node_map_v2[node_ip]->spi, while 117 sets spi from ipcache_map[dst_ip]->key. Ideally pod2pod shouldn't be affected.
  3. Src_sec_id checks. 118 checks src_sec_id (ipsec_redirect_sec_id_ok()) for native routing, while 117 doesn't. Ideally pod2pod shouldn't be affected.

Above changes have been discussed multiple times and agreed upon by the team. The main goal is to consolidate the encryption datapath flow between IPsec and Wireguard for better consistency and maintainability. Let's keep in mind these important changes in case we unfortunately hit any issues.

@ldelossa
Copy link
Copy Markdown
Contributor Author

ldelossa commented Apr 16, 2025

@jschwinger233 thanks for the feedback Gray! ✅ to your comments.

Copy link
Copy Markdown
Contributor

@tommyp1ckles tommyp1ckles left a comment

Choose a reason for hiding this comment

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

cli looks good

pchaigno and others added 8 commits April 21, 2025 14:46
This commit was originally applied in ca9c056
removed in 152867f and is now being
reapplied to support moving IPsec hooks to the egress device.

To support upgrades properly we ensure that `bpf_host` is installed
first when IPsec is enabled.

This ensures the transition to `bpf_lxc` programs which no longer
perform IPsec encryption do not result in leaked traffic. The IPsec
enabled `bpf_host` programs will be in place prior to the IPsec disabled
`bpf_lxc` transition.

Signed-off-by: Paul Chaignon <[email protected]>
To fully support Encrypted Overlay and moving IPsec encrypt hooks to the
egress device we must ensure the `to-netdev` program exists on native
devices.

Update the `DaemonConfig.AreDevicesRequired` function to return `true`
when IPsec is enabled.

This is a more general option which encompasses the `EnableIPSecEncryptedOverlay`
flag.

Moving forward Encrypted Overlay will be the default and this flag will
be removed.

Signed-off-by: Louis DeLosSantos <[email protected]>
Detect if traffic has been encrypted before traversing the overlay
driver via a mark.

This is useful for VinE, where encryption occurs at the ultimate egress
device. If a packet was previously encrypted by the pre-VinE bpf_lxc
programs, we can detect this and avoid performing double encryption.

Likewise, if a packet arrives at the egress device and is unencrypted
tunnel traffic, we can encrypt it to ensure the traffic does not leak.

Implementation of the previous statement will be done in a subsequent
commit.

Signed-off-by: Louis DeLosSantos <[email protected]>
Move IPsec encryption hooks to the native egress device.

Prior to this commit IPsec hooks would occur at pod egress (or at proxy
egress if l7 policy is enforced).

This move accomplish two goals:
1. Consolidate the encryption datapath flow between IPsec and Wireguard
2. Encrypt security IDs when tunnel mode is enabled (VinE/Encrypted
   Overlay)

Thus, when this commit lands IPsec hooks will begin to be applied at
bpf_host and only after the vlxan driver has encapsulated a packet, if
tunnel mode is enabled.

To cleanly migrate to the new IPsec datapath the Cilium cluster MUST be
patched to the latest v1.17 patch release and then upgraded to v1.18.

Signed-off-by: Louis DeLosSantos <[email protected]>
Remove the tests which are no longer valid for IPsec.

This includes the group of tests which focused on bpf_lxc and encrypted
overlay.

IPsec encryption hooks no longer run at bpf_lxc and encrypted overlay is
deprecated.

Add two new tests:
1. Integration test with bpf_host which ensures the IPsec hooks are
   called for traffic about to leave the host
2. Unit tests for the IPsec encryption hook and its hairpin
   functionality.

The latter ensures the `ctx` is prepared correctly for the hairpin and
a call to ctx_redirect is made to recirculate the packet into the stack
for XFRM processing

Signed-off-by: Louis DeLosSantos <[email protected]>
Enable the v2 pod-to-pod encryption tests for IPsec and not just
wireguard, now that VinE is implemented.

Additionally, we can now disable the v1 pod-to-pod encryption tests for
all encryption modes, since IPsec no longer requires it to run.

Signed-off-by: Louis DeLosSantos <[email protected]>
This commit is added to work around an issue with the cluster mesh
testing.

This issue is being tracked and worked on saparately to this PR in
issue: 38113

See issue for full details.

Signed-off-by: gray <[email protected]>
Add documentation outlining the move to VinE in v1.18 forward.

Signed-off-by: Louis DeLosSantos <[email protected]>
@ldelossa
Copy link
Copy Markdown
Contributor Author

/test

@ldelossa
Copy link
Copy Markdown
Contributor Author

IPsec flake is now cleared with merge of #38843 🎉

@julianwiedmann
Copy link
Copy Markdown
Member

@ldelossa I feel this broke conformance-gke (which is no longer part of the default /test set).

In particular https://github.com/cilium/cilium/actions/runs/14585424143 was a scheduled run with this PR as the top-commit, and all the failed configs have tunnel-ipsec. These configs are failing consistently since then.

@ldelossa
Copy link
Copy Markdown
Contributor Author

ldelossa commented May 5, 2025

@julianwiedmann Thanks for the heads up.

Created: #39337

Will be debugging this now.

* The tunnel_endpoint is used in the IPsec hook under test below to
* find the associated NodeID for an egress packet
*/
ipcache_v4_add_entry(DST_IP, 0, 0xAC, DST_IP, TARGET_SPI);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, shouldn't all of this be in a SETUP instead of CHECK?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, I see the comment above 😬 Yeah... we should debug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I often run into strange anomalies when writing BPF unit tests. I tend to follow the path of least resistance once I find something that works.

Can't hurt to debug further tho.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think part of the issue is that we keep calling them BPF unit tests when they're actually integration tests. The SETUP, CHECK, PKTGEN things are for integration tests, but you tried to use them to test just one function (so unit test). It took me a bit to understand that's why you had issues with SETUP.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. Cuz the first example in the BPF testing docs is a unit test which tests one function :-D

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hm, I see. And the docs don't say when to use which.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cilium-cli This PR contains changes related with cilium-cli feature/ipsec Relates to Cilium's IPsec feature pinned These issues are not marked stale by our issue bot. release-note/major This PR introduces major new functionality to Cilium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants