Commit 84edf7e
authored
mcp: allow configuring the session encryption iterations (#1598)
**Description**
Allow configuring the number of iterations to be executed for the MCP
session encryption.
MCP sessions are encrypted using PBKDF2 for key derivation and AES-GCM
for encryption. This provides some flexibility to allow users to balance
between security and performance.
The default implementation defaults to 100.000 iterations, which should
be a reasonable tradeoff between security and speed. This PR introduces
a new Helm value to allow users change this value to make the MCP proxy
faster if needed.
The following benchmarks show the behaviour for different values:
```
Running tool: /opt/homebrew/opt/[email protected]/bin/go test -benchmem -run=^$ -bench ^BenchmarkPBKDF2AesGcmSessionCrypto$ github.com/envoyproxy/ai-gateway/internal/mcpproxy
goos: darwin
goarch: arm64
pkg: github.com/envoyproxy/ai-gateway/internal/mcpproxy
cpu: Apple M1
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_100-8 85375 14220 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_100-8 87002 14356 ns/op 2260 B/op 16 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_1000-8 8824 126737 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_1000-8 9558 116771 ns/op 2260 B/op 16 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_10000-8 1056 1512627 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_10000-8 799 1350919 ns/op 2260 B/op 16 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_50000-8 211 5655061 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_50000-8 208 5703031 ns/op 2260 B/op 16 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_100000-8 100 11378411 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_100000-8 100 11343512 ns/op 2260 B/op 16 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/encrypt_200000-8 52 23629280 ns/op 2560 B/op 20 allocs/op
BenchmarkPBKDF2AesGcmSessionCrypto/decrypt_200000-8 50 26281746 ns/op 2260 B/op 16 allocs/op
PASS
ok github.com/envoyproxy/ai-gateway/internal/mcpproxy 15.551s
```
**Related Issues/PRs (if applicable)**
N/A
**Special notes for reviewers (if applicable)**
N/A
---------
Signed-off-by: Ignasi Barrera <[email protected]>1 parent 5f56187 commit 84edf7e
File tree
12 files changed
+402
-215
lines changed- cmd
- controller
- extproc/mainlib
- internal
- controller
- mcpproxy
- manifests/charts/ai-gateway-helm
- templates
12 files changed
+402
-215
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
199 | 203 | | |
200 | 204 | | |
201 | 205 | | |
| |||
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
261 | 272 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
283 | 297 | | |
284 | 298 | | |
285 | 299 | | |
| |||
352 | 366 | | |
353 | 367 | | |
354 | 368 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
368 | 385 | | |
369 | 386 | | |
370 | 387 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| |||
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
129 | 157 | | |
130 | 158 | | |
131 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| |||
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
| |||
269 | 273 | | |
270 | 274 | | |
271 | 275 | | |
272 | | - | |
273 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
274 | 287 | | |
275 | 288 | | |
276 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
90 | 96 | | |
91 | 97 | | |
92 | 98 | | |
| |||
228 | 234 | | |
229 | 235 | | |
230 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
231 | 240 | | |
232 | 241 | | |
233 | 242 | | |
| |||
0 commit comments