|
| 1 | +--- |
| 2 | +title: IPSec & Offload Authorization E2E Test |
| 3 | +authors: |
| 4 | +- "@xiaojiangao123" # Authors' GitHub accounts here. |
| 5 | +reviewers: |
| 6 | +- "@robot" |
| 7 | +- TBD |
| 8 | +approvers: |
| 9 | +- "@robot" |
| 10 | +- TBD |
| 11 | + |
| 12 | +creation-date: 2025-5-12 |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## IPSec & Offload Authorization E2E Test Proposal |
| 17 | + |
| 18 | +### Overview |
| 19 | + |
| 20 | +This proposal aims to design end-to-end (E2E) test cases for the IPSec feature and Offload Authorization of Kmesh. The IPSec E2E tests focus on basic functionality, security, and reliability, verifying proper execution of IPSec tunnel setup, encryption/decryption, key management, and fault recovery. The Offload Authorization E2E tests include IP authorization, Port authorization, Header authorization, namespace authorization, and hosts authorization. |
| 21 | + |
| 22 | +### Motivation |
| 23 | + |
| 24 | +Kmesh’s IPSec functionality is a key component for secure communication within the service mesh. Its stability and reliability directly affect the security of the entire mesh. The Offload Authorization feature is a unique Kmesh capability that offloads IP and Port authorization to the Linux kernel via XDP. Without comprehensive E2E testing, version upgrades and releases may pose potential risks. |
| 25 | + |
| 26 | +#### Goals |
| 27 | + |
| 28 | +1. Develop complete E2E test cases |
| 29 | +2. Cover all functional scenarios of Kmesh IPSec |
| 30 | +3. Cover all types of Offload Authorization mechanisms |
| 31 | + |
| 32 | +### Proposal |
| 33 | + |
| 34 | +For the IPSec feature, we designed IPSec E2E test cases covering three core scenarios: basic connectivity, key rotation, and fault recovery. |
| 35 | + |
| 36 | +1. The basic connectivity test verifies IPSec tunnel establishment and the correctness of encrypted communication using tcpdump to inspect ESP packets. |
| 37 | + |
| 38 | +2. The key rotation test ensures the reliability of the PSK update mechanism and validates service continuity during key changes. |
| 39 | + |
| 40 | +For the Offload Authorization feature, E2E test cases are designed for IP, Port, Header, Namespace, and Hosts authorization. |
| 41 | + |
| 42 | +The test environment requires at least a 2-nodes Kubernetes cluster using httpbin and sleep or fortio as test applications. |
| 43 | + |
| 44 | +### Design Details |
| 45 | + |
| 46 | +#### 1. Test Environment Preparation |
| 47 | + |
| 48 | +##### Requirements |
| 49 | + |
| 50 | +- At least a 2-nodes Kubernetes cluster with Kmesh installed |
| 51 | +- Tools: tcpdump |
| 52 | +- Applications: httpbin, sleep, fortio |
| 53 | + |
| 54 | +#### 2. IPSec Test Scenarios |
| 55 | + |
| 56 | +##### 2.1 Basic Connectivity E2E Test |
| 57 | + |
| 58 | +###### Test Steps |
| 59 | + |
| 60 | +- Deploy httpbin and sleep applications on different nodes |
| 61 | +- Verify connectivity between applications |
| 62 | +- Check IPSec state and policy rules: |
| 63 | + |
| 64 | + ```bash |
| 65 | + ip xfrm state show |
| 66 | + ``` |
| 67 | + |
| 68 | + **Expected Output:** |
| 69 | + |
| 70 | + ```plaintext |
| 71 | + src {{SRC_IP}} dst {{DST_IP}} |
| 72 | + proto esp spi 0x{{SPI}} reqid 1 mode tunnel |
| 73 | + replay-window 0 |
| 74 | + output-mark 0xd0/0xffffffff |
| 75 | + aead rfc4106(gcm(aes)) {{KEY}} 128 |
| 76 | + anti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000 |
| 77 | + sel src ::/0 dst ::/0 |
| 78 | + ``` |
| 79 | + |
| 80 | + ```bash |
| 81 | + ip xfrm policy show |
| 82 | + ``` |
| 83 | + |
| 84 | + **Expected Output:** |
| 85 | + |
| 86 | + ```plaintext |
| 87 | + src ::/0 dst {{DST_SUBNET}} |
| 88 | + dir out priority 0 |
| 89 | + mark 0xe0/0xffffffff |
| 90 | + tmpl src {{SRC_IP}} dst {{DST_IP}} |
| 91 | + proto esp spi 0x{{SPI}} reqid 1 mode tunnel |
| 92 | + ``` |
| 93 | + |
| 94 | +- Verify encryption using tcpdump; analyze ESP headers and confirm payload is encrypted: |
| 95 | + |
| 96 | + ```bash |
| 97 | + tcpdump -i any esp |
| 98 | + ``` |
| 99 | + |
| 100 | + **Expected Output:** ESP packets should be visible during communication. |
| 101 | + |
| 102 | +##### 2.2 Key Rotation E2E Test |
| 103 | + |
| 104 | +###### Test Steps |
| 105 | + |
| 106 | +- Deploy httpbin and sleep applications on different nodes |
| 107 | +- Record initial SPI and pre-shared key: |
| 108 | + |
| 109 | + ```bash |
| 110 | + ip xfrm state show |
| 111 | + ``` |
| 112 | + |
| 113 | + **Expected Output:** |
| 114 | + |
| 115 | + ```plaintext |
| 116 | + src {{SRC_IP}} dst {{DST_IP}} |
| 117 | + proto esp spi 0x{{INITIAL_SPI}} reqid 1 mode tunnel |
| 118 | + aead rfc4106(gcm(aes)) {{INITIAL_KEY}} 128 |
| 119 | + ``` |
| 120 | + |
| 121 | +- Send continuous traffic between applications |
| 122 | +- Update the pre-shared key |
| 123 | + |
| 124 | + ```bash |
| 125 | + kubectl create secret |
| 126 | + ``` |
| 127 | + |
| 128 | +- Check if SPI and key are updated in xfrm rules: |
| 129 | + |
| 130 | + ```bash |
| 131 | + ip xfrm state show |
| 132 | + ``` |
| 133 | + |
| 134 | + **Expected Output:** |
| 135 | + |
| 136 | + ```plaintext |
| 137 | + src {{SRC_IP}} dst {{DST_IP}} |
| 138 | + proto esp spi 0x{{NEW_SPI}} reqid 1 mode tunnel |
| 139 | + aead rfc4106(gcm(aes)) {{NEW_KEY}} 128 |
| 140 | + ``` |
| 141 | + |
| 142 | +- Verify communication continuity, encryption status |
| 143 | + |
| 144 | +#### 3. Offload Authorization Test Scenarios |
| 145 | + |
| 146 | +Apply the corresponding security policies (ALLOW/DENY) and routing strategies, and verify connectivity, including traffic that matches the rules and will be allowed and traffic that will be denied by the rules. |
| 147 | + |
| 148 | +Here are some AuthorizationPolicy samples. |
| 149 | + |
| 150 | +##### 3.1 IP Authorization Test |
| 151 | + |
| 152 | +- Example security policy YAML: |
| 153 | + |
| 154 | +```yaml |
| 155 | +apiVersion: security.istio.io/v1beta1 |
| 156 | +kind: AuthorizationPolicy |
| 157 | +metadata: |
| 158 | + name: ip-allow-policy |
| 159 | + namespace: test-ns1 |
| 160 | +spec: |
| 161 | + action: ALLOW |
| 162 | + rules: |
| 163 | + - from: |
| 164 | + - source: |
| 165 | + ipBlocks: |
| 166 | + - "{{.Ip}}" |
| 167 | +--- |
| 168 | +apiVersion: security.istio.io/v1beta1 |
| 169 | +kind: AuthorizationPolicy |
| 170 | +metadata: |
| 171 | + name: ip-deny-policy |
| 172 | + namespace: test-ns1 |
| 173 | +spec: |
| 174 | + action: DENY |
| 175 | + rules: |
| 176 | + - from: |
| 177 | + - source: |
| 178 | + ipBlocks: |
| 179 | + - "{{.Ip}}" |
| 180 | +``` |
| 181 | +
|
| 182 | +##### 3.2 Port Authorization Test |
| 183 | +
|
| 184 | +- Example security policy YAML: |
| 185 | +
|
| 186 | +```yaml |
| 187 | +apiVersion: security.istio.io/v1beta1 |
| 188 | +kind: AuthorizationPolicy |
| 189 | +metadata: |
| 190 | + name: port-allow-policy |
| 191 | + namespace: test-ns1 |
| 192 | +spec: |
| 193 | + action: ALLOW |
| 194 | + rules: |
| 195 | + - to: |
| 196 | + - operation: |
| 197 | + ports: {{.Ports}} |
| 198 | +--- |
| 199 | +apiVersion: security.istio.io/v1beta1 |
| 200 | +kind: AuthorizationPolicy |
| 201 | +metadata: |
| 202 | + name: port-deny-policy |
| 203 | + namespace: test-ns1 |
| 204 | +spec: |
| 205 | + action: DENY |
| 206 | + rules: |
| 207 | + - to: |
| 208 | + - operation: |
| 209 | + ports: {{.Ports}} |
| 210 | +``` |
| 211 | +
|
| 212 | +##### 3.3 Namespace Authorization Test |
| 213 | +
|
| 214 | +- Example security policy YAML: |
| 215 | +
|
| 216 | +```yaml |
| 217 | +apiVersion: security.istio.io/v1beta1 |
| 218 | +kind: AuthorizationPolicy |
| 219 | +metadata: |
| 220 | + name: namespace-allow-policy |
| 221 | + namespace: test-ns1 |
| 222 | +spec: |
| 223 | + action: ALLOW |
| 224 | + rules: |
| 225 | + - from: |
| 226 | + - source: |
| 227 | + namespaces: |
| 228 | + - "{{.SourceNamespace}}" |
| 229 | +--- |
| 230 | +apiVersion: security.istio.io/v1beta1 |
| 231 | +kind: AuthorizationPolicy |
| 232 | +metadata: |
| 233 | + name: namespace-deny-policy |
| 234 | + namespace: test-ns1 |
| 235 | +spec: |
| 236 | + action: DENY |
| 237 | + rules: |
| 238 | + - from: |
| 239 | + - source: |
| 240 | + namespaces: |
| 241 | + - "{{.SourceNamespace}}" |
| 242 | +``` |
| 243 | +
|
| 244 | +##### 3.4 Header Authorization Test |
| 245 | +
|
| 246 | +- Example security policy YAML: |
| 247 | +
|
| 248 | +```yaml |
| 249 | +apiVersion: security.istio.io/v1beta1 |
| 250 | +kind: AuthorizationPolicy |
| 251 | +metadata: |
| 252 | + name: header-allow-policy |
| 253 | + namespace: test-ns1 |
| 254 | +spec: |
| 255 | + action: ALLOW |
| 256 | + rules: |
| 257 | + - when: |
| 258 | + - key: request.headers[{{.HeaderName}}] |
| 259 | + values: ["{{.HeaderValue}}"] |
| 260 | +--- |
| 261 | +apiVersion: security.istio.io/v1beta1 |
| 262 | +kind: AuthorizationPolicy |
| 263 | +metadata: |
| 264 | + name: header-deny-policy |
| 265 | + namespace: test-ns1 |
| 266 | +spec: |
| 267 | + action: DENY |
| 268 | + rules: |
| 269 | + - when: |
| 270 | + - key: request.headers[{{.HeaderName}}] |
| 271 | + values: ["{{.HeaderValue}}"] |
| 272 | +``` |
| 273 | +
|
| 274 | +##### 3.5 Hosts Authorization Test |
| 275 | +
|
| 276 | +- Example security policy YAML: |
| 277 | +
|
| 278 | +```yaml |
| 279 | +apiVersion: security.istio.io/v1beta1 |
| 280 | +kind: AuthorizationPolicy |
| 281 | +metadata: |
| 282 | + name: host-allow-policy |
| 283 | + namespace: test-ns1 |
| 284 | +spec: |
| 285 | + action: ALLOW |
| 286 | + rules: |
| 287 | + - to: |
| 288 | + - operation: |
| 289 | + hosts: ["{{.TargetHost}}"] |
| 290 | +--- |
| 291 | +apiVersion: security.istio.io/v1beta1 |
| 292 | +kind: AuthorizationPolicy |
| 293 | +metadata: |
| 294 | + name: host-deny-policy |
| 295 | + namespace: test-ns1 |
| 296 | +spec: |
| 297 | + action: DENY |
| 298 | + rules: |
| 299 | + - to: |
| 300 | + - operation: |
| 301 | + hosts: ["{{.TargetHost}}"] |
| 302 | +``` |
0 commit comments