Skip to content

Add Wireguard support#15383

Merged
brb merged 8 commits intomasterfrom
pr/wg
Mar 27, 2021
Merged

Add Wireguard support#15383
brb merged 8 commits intomasterfrom
pr/wg

Conversation

@brb
Copy link
Member

@brb brb commented Mar 18, 2021

This PR adds a native Wireguard support. Currently, the feature is restricted to Kubernetes and ClusterPool (with single podCIDR per node and IP family) IPAM, and works in the direct routing mode only (the tunneling mode is going to be supported in the future).

The feature consists of two major components - pkg/wireguard/agent (which is run by cilium-agent) and pkg/wireguard/operator (run by a cilium-operator leader).

At the high level, we create a wireguard tunnel device (cilium_wg0) on each node, and set an IP from a dedicated subnet (in the code we call it as a wireguard subnet). Next, we generate a private key, and announce to remote nodes its public key via the CiliumNode object annotation. In addition, we use the same object to announce the wireguard tunnel IP, podCIDR. Finally, when the agent receives a remote CiliumNode object, it sets up the wireguard tunnel to the peer by using the nodeIP as wireguard endpoint address, the wireguard tunnel IP + podCIDR as allowed-ips, and the public key.

Currently, we encrypt the following packets:

  • A local pod to a remote pod.
  • A NodePort BPF request which is going to be forwarded to a remote node.

Both types of packets are marked with MARK_MAGIC_ENCRYPT which is used by the following IP rule and route:

$ ip rule show
1:      from all fwmark 0xe00/0xf00 lookup 201
[...]
$  ip route show table 201
default dev cilium_wg0

Steering the packet to the cilium_wg0 device makes Wireguard to encrypt it. Note that there is no need to specify podCIDR => nodeIP routes, as Wireguard is able to derive a destination node by consulting the allowed-ips list which the agent configures.

The operator is responsible for allocating wireguard tunnel IPs and setting them in CiliumNode objects. While, the agent is responsible for configuring the tunnel device, adding peers and direct routes.

An issue to track the follow-ups: #15462.

Co-developed with @gandro.

Integrate Wireguard for pod2pod encryption

Fix #7519.

@maintainer-s-little-helper
Copy link

Commits dc4b1cc, 5d28779, 7e80a5c, 42dcba9, 4872be5, 3e2fd9c, 66bfb45 do not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@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 Mar 18, 2021
@brb brb added the release-note/major This PR introduces major new functionality to Cilium. label Mar 18, 2021
@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 Mar 18, 2021
@maintainer-s-little-helper
Copy link

Commits dc4b1cc, 5d28779, 7e80a5c, 42dcba9, 4872be5, 3e2fd9c, 66bfb45 do not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

1 similar comment
@maintainer-s-little-helper
Copy link

Commits dc4b1cc, 5d28779, 7e80a5c, 42dcba9, 4872be5, 3e2fd9c, 66bfb45 do not contain "Signed-off-by".

Please follow instructions provided in https://docs.cilium.io/en/stable/contributing/development/contributing_guide/#developer-s-certificate-of-origin

@brb
Copy link
Member Author

brb commented Mar 18, 2021

test-net-next

@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 Mar 18, 2021
@brb
Copy link
Member Author

brb commented Mar 18, 2021

test-me-please

@brb brb marked this pull request as ready for review March 18, 2021 21:00
@brb brb requested review from a team March 18, 2021 21:00
@brb brb requested review from a team as code owners March 18, 2021 21:00
@brb brb requested review from a team March 18, 2021 21:00
@brb brb requested review from a team as code owners March 18, 2021 21:00
@brb brb requested review from kkourt and nathanjsweet March 18, 2021 21:00
@brb brb requested review from errordeveloper and rolinh March 18, 2021 21:00
This extends the cilium-operator to allocate Wireguard IPs for each
Cilium node from a user-defined subnet.

Co-authored-by: Martynas Pumputis <m@lambda.lt>
Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
@brb brb force-pushed the pr/wg branch 2 times, most recently from 6452726 to 13ee10a Compare March 26, 2021 21:40
gandro and others added 3 commits March 26, 2021 22:41
This commit adds support in the cilium-agent for configuring the local
Wireguard device and establishing the tunnel to remote peers. This is
implemented by watching for changes to the local and remote node
objects.

Wiregurad traffic to remote nodes is redirected by the ip route based on
the MARK_MAGIC_ENCRYPT mark.

Co-authored-by: Martynas Pumputis <m@lambda.lt>
Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
In this initial version, Wireguard cannot be configured in a more
fine-grained manner. Follow-up work will likely add more knobs to the
Helm chart to configure additional parameters.

Co-authored-by: Martynas Pumputis <m@lambda.lt>
Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
The test is checking whether KPR is wired up properly when Wireguard is
enabled, i.e. whether a NodePort BPF requests when a backend is on a
remote node are forwarded over the wireguard tunnel.

The log-gatherer image vsn bump is to be able to run tcpdump from it.

Co-authored-by: Martynas Pumputis <m@lambda.lt>
Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
Signed-off-by: Martynas Pumputis <m@lambda.lt>
@brb
Copy link
Member Author

brb commented Mar 26, 2021

test-me-please

@brb
Copy link
Member Author

brb commented Mar 26, 2021

@tklauser @christarazi @kkourt @joestringer @borkmann @rolinh @nathanjsweet Thanks for the reviews! I think all your feedback has been addressed.

@brb
Copy link
Member Author

brb commented Mar 27, 2021

test-4.9

2 similar comments
@brb
Copy link
Member Author

brb commented Mar 27, 2021

test-4.9

@brb
Copy link
Member Author

brb commented Mar 27, 2021

test-4.9

@brb
Copy link
Member Author

brb commented Mar 27, 2021

The 4.9 CI failed with the same failure (unrelated to this PR) as the 4.9 master CI is currently failing (most likely #15487 might resolve the failure).

All comments have been addressed and got ACK from a majority of the reviewers. Marking as ready-to-merge.

@brb brb added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Mar 27, 2021
@brb brb merged commit 0218d37 into master Mar 27, 2021
@brb brb deleted the pr/wg branch March 27, 2021 18:14
youssefazrak added a commit to youssefazrak/cilium that referenced this pull request Apr 9, 2021
This PR is to add the Wireguard support to the Helm charts.

Following comment from PR cilium#15383 some refactoring has been done for the
encryption part: we are now having to subchoices: IPSec or Wireguard for
the encryption.

Fixes: cilium#15483

Signed-off-by: Youssef Azrak <yazrak.tech@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/major This PR introduces major new functionality to Cilium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support WireGuard for encryption