Skip to content

Commit bf43a2a

Browse files
committed
ipsec: add ipsec user guide
Signed-off-by: bitcoffee <[email protected]>
1 parent c111dd0 commit bf43a2a

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
draft: true
3+
linktitle: use IPsec in Kmesh cluster
4+
menu:
5+
docs:
6+
parent: user guide
7+
weight: 19
8+
title: use IPsec in Kmesh cluster
9+
toc: true
10+
type: docs
11+
12+
---
13+
14+
### Use IPsec in Kmesh cluster
15+
16+
IPsec is a mature and widely used encryption method for inter node communication. This document explains how to enable IPsec for two Kmesh managed nodes in a Kmesh cluster to encrypt communication data between both parties.
17+
18+
### How to enable IPsec in Kmesh
19+
20+
**Step 1: Generate an IPsec pre shared key for Kmesh before starting the Kmesh by kmeshctl. Currently, only the rfc4106 (gcm (AES)) algorithm is supported. key need 36 characters(32 character as algo key, 4 character as salt)**
21+
22+
root@master:~/kmesh# ./kmeshctl secret --key=<aead key>
23+
24+
or
25+
26+
root@master:~/kmesh# ./kmeshctl secret --k=<aead key>
27+
28+
If you want to randomly generate a key, you can use the following command
29+
30+
root@master:~/kmesh# ./kmeshctl secret --key=$(dd if=/dev/urandom count=36 bs=1 2>/dev/null | xxd -p -c 64)
31+
32+
If you want use custom key, you can use the following command
33+
34+
root@master:~/kmesh# ./kmeshctl secret --key=$(echo -n "{36-character user-defined key here}" | xxd -p -c 64)
35+
36+
**Step 2: Install the specified CRD type**
37+
38+
root@master:~/kmesh# kubectl apply -f deploy/yaml/crd/kmesh.net_kmeshnodeinfos.yaml
39+
40+
**Step 3: Add the parameter --enable-ipsec=true to the Kmesh yaml**
41+
42+
kmesh.yaml
43+
...
44+
args:
45+
[
46+
"./start_kmesh.sh --mode=dual-engine --enable-bypass=false --enable-ipsec=true",
47+
]
48+
...
49+
50+
**Step 4: Place pods or namespace under the management of Kmesh.**
51+
52+
Only when both communicating pods are managed by Kmesh, will they enter the encryption process.
53+
54+
root@master:~/kmesh# kubectl label namespace default istio.io/dataplane-mode=Kmesh
55+
56+
**Step 5: Test whether the data packet has been encrypted**
57+
58+
Use tcpdump on nodes to capture packets and check if IPsec has been used during data communication between nodes (determined by ESP packets)
59+
60+
root@master:~/kmesh# tcpdump -i any |grep ESP
61+
...
62+
14:19:24.143654 ? Out IP master > node1: ESP(spi=0x00000001,seq=0x3da88), length 80
63+
14:19:24.143690 ? Out IP master > node1: ESP(spi=0x00000001,seq=0x3da89), length 80
64+
14:19:24.143707 ? In IP node1 > master: ESP(spi=0x00000001,seq=0x3c037), length 80
65+
14:19:24.143738 ? In IP node1 > master: ESP(spi=0x00000001,seq=0x3c038), length 172
66+
...
67+
68+
**Step 6: Replace pre shared key**
69+
70+
After a period of time, the pre shared key of the cluster can be changed. After changing the pre shared key, the ESP SPI number of the IPsec used for communication between nodes will be increased by 1 compared to the previous version. You can be observed again through tcpdump. The initial IPSec SPI version number is 1
71+
72+
root@master:~/kmesh# tcpdump -i any |grep ESP
73+
...
74+
14:26:33.782665 ? Out IP master > node1: ESP(spi=0x00000002,seq=0x1aaa1), length 80
75+
14:26:33.782666 ? Out IP master > node1: ESP(spi=0x00000002,seq=0x1aaa2), length 80
76+
14:26:33.782667 ? In IP node1 > master: ESP(spi=0x00000002,seq=0x183d2), length 80
77+
14:26:33.782667 ? In IP node1 > master: ESP(spi=0x00000002,seq=0x183d3), length 80
78+
...
79+
80+
### Note
81+
82+
1、 IPsec encryption uses mark `0xe0` and `0xd0` as markers for IPsec encryption and decryption. Please ensure that no conflicting Makr is used on the host network, otherwise unknown behavior may occur
83+
84+
2、Please ensure that `address MASQ` is not used on packets encrypted with IPsec. After address MASQ, IPsec cannot accurately match encryption and decryption rules, which can result in packet loss

0 commit comments

Comments
 (0)