This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connectivity.go
763 lines (645 loc) · 27.6 KB
/
connectivity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
package RuntimeTest
import (
"fmt"
"os"
"path/filepath"
"time"
. "github.com/cilium/cilium/test/ginkgo-ext"
"github.com/cilium/cilium/test/helpers"
"github.com/cilium/cilium/test/helpers/constants"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/types"
)
func runOnNetNextOnly(f func()) func() {
if helpers.RunsOnNetNext() {
return f
}
return func() {}
}
var _ = Describe("RuntimeConnectivityInVethModeTest", runtimeConnectivityTest("veth"))
var _ = Describe("RuntimeConnectivityInIpvlanModeTest", runOnNetNextOnly(runtimeConnectivityTest("ipvlan")))
// TODO(brb) Either create a dummy netdev or determine the master device at runtime
const ipvlanMasterDevice = "enp0s8"
var runtimeConnectivityTest = func(datapathMode string) func() {
return func() {
var (
vm *helpers.SSHMeta
monitorStop = func() error { return nil }
)
BeforeAll(func() {
vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)
if datapathMode == "ipvlan" {
vm.SetUpCiliumInIpvlanMode(ipvlanMasterDevice)
// cilium-docker has to be restarted because the datapath mode
// has changed
vm.Exec("sudo systemctl restart cilium-docker")
}
ExpectCiliumReady(vm)
})
JustBeforeEach(func() {
monitorStop = vm.MonitorStart()
})
AfterAll(func() {
// Restore the datapath mode and cilium-docker
if datapathMode == "ipvlan" {
vm.SetUpCilium()
vm.Exec("sudo systemctl restart cilium-docker")
}
vm.CloseSSHClient()
})
removeContainer := func(containerName string) {
By("removing container %s", containerName)
res := vm.ContainerRm(containerName)
ExpectWithOffset(1, res).To(helpers.CMDSuccess(), "cannot delete container")
}
AfterEach(func() {
vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
})
JustAfterEach(func() {
vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
Expect(monitorStop()).To(BeNil(), "cannot stop monitor command")
})
AfterFailed(func() {
vm.ReportFailed()
})
Context("Basic Connectivity test", func() {
BeforeEach(func() {
vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
vm.ContainerCreate(helpers.Server, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.server")
vm.PolicyDelAll()
vm.WaitEndpointsReady()
err := helpers.WithTimeout(func() bool {
if data, _ := vm.GetEndpointsNames(); len(data) < 2 {
logger.Info("Waiting for endpoints to be ready")
return false
}
return true
}, "Endpoints are not ready", &helpers.TimeoutConfig{Timeout: 150 * time.Second})
Expect(err).Should(BeNil())
}, 150)
AfterEach(func() {
removeContainer(helpers.Client)
removeContainer(helpers.Server)
return
})
It("Test connectivity between containers without policies imported", func() {
// TODO: this code is duplicated in the next "It" in this file. refactor it into a function.
// See if we can make the "Filter" strings for getting IPv4 and IPv6 addresses into constants.
By("inspecting container %s", helpers.Server)
serverData := vm.ContainerInspect(helpers.Server)
serverIP, err := serverData.Filter(fmt.Sprintf("{[0].NetworkSettings.Networks.%s.IPAddress}", helpers.CiliumDockerNetwork))
Expect(err).Should(BeNil())
By("serverIP: %q", serverIP)
serverIPv6, err := serverData.Filter(fmt.Sprintf("{[0].NetworkSettings.Networks.%s.GlobalIPv6Address}", helpers.CiliumDockerNetwork))
By("serverIPv6: %q", serverIPv6)
Expect(err).Should(BeNil())
By("checking %q can ping to %q IPv6", helpers.Client, helpers.Server)
res := vm.ContainerExec(helpers.Client, helpers.Ping6(serverIPv6.String()))
res.ExpectSuccess()
By("checking %q can ping to %q IPv4", helpers.Client, helpers.Server)
res = vm.ContainerExec(helpers.Client, helpers.Ping(serverIP.String()))
res.ExpectSuccess()
// TODO: remove this hardcoding ; it is not clean. Have command wrappers that take maps of strings.
By("netperf to %q from %q IPv6", helpers.Server, helpers.Client)
cmd := fmt.Sprintf(
"netperf -c -C -t TCP_SENDFILE -H %s", serverIPv6)
res = vm.ContainerExec(helpers.Client, cmd)
res.ExpectSuccess()
}, 300)
It("Test connectivity between containers with policy imported", func() {
policyID, err := vm.PolicyImportAndWait(
fmt.Sprintf("%s/test.policy", vm.ManifestsPath()), 150*time.Second)
Expect(err).Should(BeNil())
logger.Debugf("New policy created with id '%d'", policyID)
serverData := vm.ContainerInspect(helpers.Server)
serverIP, err := serverData.Filter(fmt.Sprintf("{[0].NetworkSettings.Networks.%s.IPAddress}", helpers.CiliumDockerNetwork))
Expect(err).Should(BeNil())
By("serverIP: %q", serverIP)
serverIPv6, err := serverData.Filter(fmt.Sprintf("{[0].NetworkSettings.Networks.%s.GlobalIPv6Address}", helpers.CiliumDockerNetwork))
By("serverIPv6: %q", serverIPv6)
Expect(err).Should(BeNil())
By("%q can ping to %q IPV6", helpers.Client, helpers.Server)
res := vm.ContainerExec(helpers.Client, helpers.Ping6(serverIPv6.String()))
res.ExpectSuccess()
By("%s can ping to %s IPv4", helpers.Client, helpers.Server)
res = vm.ContainerExec(helpers.Client, helpers.Ping(serverIP.String()))
res.ExpectSuccess()
By("netperf to %q from %q (should succeed)", helpers.Server, helpers.Client)
cmd := fmt.Sprintf("netperf -c -C -H %s", serverIP)
res = vm.ContainerExec(helpers.Client, cmd)
// TODO: remove this hardcoding ; it is not clean. Have command wrappers that take maps of strings.
By("netperf to %q from %q IPv6 with -t TCP_SENDFILE", helpers.Server, helpers.Client)
cmd = fmt.Sprintf(
"netperf -c -C -t TCP_SENDFILE -H %s", serverIPv6)
res = vm.ContainerExec(helpers.Client, cmd)
res.ExpectSuccess()
By("super_netperf to %q from %q (should succeed)", helpers.Server, helpers.Client)
cmd = fmt.Sprintf("super_netperf 10 -c -C -t TCP_SENDFILE -H %s", serverIP)
res = vm.ContainerExec(helpers.Client, cmd)
res.ExpectSuccess()
By("ping from %q to %q", helpers.Host, helpers.Server)
res = vm.Exec(helpers.Ping(serverIP.String()))
res.ExpectSuccess()
}, 300)
It("Test NAT46 connectivity between containers", func() {
if datapathMode == "ipvlan" {
Skip("NAT64 is not implemented in the ipvlan mode")
}
endpoints, err := vm.GetEndpointsIds()
Expect(err).Should(BeNil(), "could not get endpoint IDs")
server, err := vm.ContainerInspectNet(helpers.Server)
Expect(err).Should(BeNil())
By("server: %q", server)
client, err := vm.ContainerInspectNet(helpers.Client)
Expect(err).Should(BeNil())
By("client: %q", client)
status := vm.EndpointSetConfig(endpoints[helpers.Client], "NAT46", helpers.OptionEnabled)
Expect(status).Should(BeTrue())
areEndpointsReady := vm.WaitEndpointsReady()
Expect(areEndpointsReady).Should(BeTrue(), "Endpoints not ready after timeout")
res := vm.ContainerExec(helpers.Client, helpers.Ping6(fmt.Sprintf(
"::FFFF:%s", server[helpers.IPv4])))
res.ExpectSuccess()
res = vm.ContainerExec(helpers.Server,
helpers.Ping6(fmt.Sprintf("::FFFF:%s", client[helpers.IPv4])))
res.ExpectFail(fmt.Sprintf("unexpectedly succeeded pinging IPv6 %s from %s",
client[helpers.IPv4], helpers.Server))
})
})
Context("With CNI", func() {
var (
cniPlugin = "/opt/cni/bin/cilium-cni"
cniServer = "cni-server"
cniClient = "cni-client"
netDPath = "/etc/cni/net.d/"
tmpDir *helpers.CmdRes
)
BeforeAll(func() {
// Remove any CNI plugin installed in the provision server. This
// helps to avoid issues on installing the new CNI
_ = vm.ExecWithSudo(fmt.Sprintf("rm -rf %[1]s/*.conf", netDPath)).ExpectSuccess(
"CNI config cannot be deleted")
tmpDir = vm.Exec("mktemp -d")
tmpDir.ExpectSuccess("TMP folder cannot be created %s", tmpDir.Output())
})
AfterAll(func() {
vm.Exec(fmt.Sprintf("rm -rf %s", tmpDir.Output()))
})
BeforeEach(func() {
vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
})
AfterEach(func() {
vm.ContainerRm(cniServer)
vm.ContainerRm(cniClient)
vm.Exec(fmt.Sprintf("docker rm -f $(docker ps --filter ancestor=%s --format '{{.ID}}')", constants.BusyboxImage))
})
runCNIContainer := func(name string, label string) {
res := vm.Exec(fmt.Sprintf("docker run -t -d --net=none -l %s %s", label, constants.BusyboxImage))
res.ExpectSuccess()
containerID := res.SingleOut()
pid := vm.Exec(fmt.Sprintf("docker inspect -f '{{ .State.Pid }}' %s", containerID))
pid.ExpectSuccess()
netnspath := fmt.Sprintf("/proc/%s/ns/net", pid.SingleOut())
res = vm.Exec(fmt.Sprintf(
"sudo -E PATH=$PATH:/opt/cni/bin -E CNI_PATH=%[1]s/bin %[1]s/cni/scripts/exec-plugins.sh add %s %s",
tmpDir.SingleOut(), containerID, netnspath))
res.ExpectSuccess("CNI exec-plugins did not work correctly")
res = vm.ContainerCreate(
name, constants.NetperfImage,
fmt.Sprintf("container:%s", containerID), fmt.Sprintf("-l %s", label))
res.ExpectSuccess("Container %s cannot be created", name)
}
It("Basic connectivity test", func() {
filename := "05-cilium-cni.conf"
cniConf := `{"name": "cilium",
"type": "cilium-cni"}`
err := helpers.RenderTemplateToFile(filename, cniConf, os.ModePerm)
Expect(err).To(BeNil())
cmd := vm.ExecWithSudo(fmt.Sprintf("mv %s %s",
helpers.GetFilePath(filename),
filepath.Join(netDPath, filename)))
cmd.ExpectSuccess("cannot install cilium cni plugin conf")
script := fmt.Sprintf(`
cd %s && \
git clone https://github.com/containernetworking/cni -b v0.5.2 --single-branch && \
cd cni && \
./build.sh
`, tmpDir.SingleOut())
vm.Exec(script).ExpectSuccess("Cannot install cni")
vm.Exec(fmt.Sprintf("cp %s %s", cniPlugin, filepath.Join(tmpDir.SingleOut(), "bin")))
By("Importing policy")
policyFileName := "CNI-policy.json"
policy := `
[{
"endpointSelector": {"matchLabels":{"id.server":""}},
"ingress": [{
"fromEndpoints": [
{"matchLabels":{"reserved:host":""}},
{"matchLabels":{"id.client":""}}
]
}]
}]`
err = helpers.RenderTemplateToFile(policyFileName, policy, os.ModePerm)
Expect(err).Should(BeNil())
_, err = vm.PolicyImportAndWait(helpers.GetFilePath(policyFileName), helpers.HelperTimeout)
Expect(err).Should(BeNil(), fmt.Sprintf("Cannot import policy %s", policyFileName))
By("Adding containers")
runCNIContainer(cniServer, "id.server")
runCNIContainer(cniClient, "id.client")
areEndpointsReady := vm.WaitEndpointsReady()
Expect(areEndpointsReady).Should(BeTrue())
serverIPv4 := vm.ContainerExec(
cniServer,
`ip -4 a show dev eth0 scope global | grep inet | sed -e 's%.*inet \(.*\)\/.*%\1%'`)
serverIPv6 := vm.ContainerExec(
cniServer,
`ip -6 a show dev eth0 scope global | grep inet6 | sed -e 's%.*inet6 \(.*\)\/.*%\1%'`)
vm.ContainerExec(cniClient, helpers.Ping(serverIPv4.SingleOut())).ExpectSuccess(
"cannot ping from client to server %q", serverIPv4.SingleOut())
vm.ContainerExec(cniClient, helpers.Ping6(serverIPv6.SingleOut())).ExpectSuccess(
"cannot ping6 from client to server %q", serverIPv6.SingleOut())
})
})
}
}
var _ = Describe("RuntimeConntrackInVethModeTest", runtimeConntrackTest("veth"))
var _ = Describe("RuntimeConntrackInIpvlanModeTest", runOnNetNextOnly(runtimeConntrackTest("ipvlan")))
var runtimeConntrackTest = func(datapathMode string) func() {
return func() {
var (
vm *helpers.SSHMeta
monitorStop = func() error { return nil }
curl1ContainerName = "curl"
curl2ContainerName = "curl2"
CTPolicyConntrackLocalDisabled = "ct-test-policy-conntrack-local-disabled.json"
)
type conntestCases struct {
from string
to string
destination string
assert func() types.GomegaMatcher
}
BeforeAll(func() {
vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)
if datapathMode == "ipvlan" {
vm.SetUpCiliumInIpvlanMode(ipvlanMasterDevice)
// cilium-docker has to be restarted because the datapath mode
// has changed
vm.Exec("sudo systemctl restart cilium-docker")
}
ExpectCiliumReady(vm)
ExpectPolicyEnforcementUpdated(vm, helpers.PolicyEnforcementAlways)
})
AfterAll(func() {
// Restore the datapath mode and cilium-docker
if datapathMode == "ipvlan" {
vm.SetUpCilium()
vm.Exec("sudo systemctl restart cilium-docker")
}
vm.CloseSSHClient()
})
clientServerConnectivity := func() {
By("============= Starting Connectivity Test ============= ")
By("Getting IPs of each spawned container")
clientDockerNetworking, err := vm.ContainerInspectNet(helpers.Client)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Client)
By("client container Docker networking: %q", clientDockerNetworking)
serverDockerNetworking, err := vm.ContainerInspectNet(helpers.Server)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Server)
By("server container Docker networking: %q", serverDockerNetworking)
httpdDockerNetworking, err := vm.ContainerInspectNet(helpers.Httpd1)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Httpd1)
By("httpd1 container Docker networking: %q", httpdDockerNetworking)
httpd2DockerNetworking, err := vm.ContainerInspectNet(helpers.Httpd2)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Httpd2)
By("httpd2 container Docker networking: %q", httpd2DockerNetworking)
curl1DockerNetworking, err := vm.ContainerInspectNet(curl1ContainerName)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", curl1ContainerName)
By("curl1 container Docker networking: %q", curl1DockerNetworking)
curl2DockerNetworking, err := vm.ContainerInspectNet(curl2ContainerName)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", curl2ContainerName)
By("httpd1 container Docker networking: %q", curl2DockerNetworking)
By("Showing policies imported to Cilium")
res := vm.PolicyGetAll()
GinkgoPrint(res.CombineOutput().String())
testCases := []conntestCases{
{
from: curl1ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpdDockerNetworking[helpers.IPv6]),
destination: helpers.Httpd1,
assert: BeTrue,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://%s:80", httpdDockerNetworking[helpers.IPv4]),
destination: helpers.Httpd1,
assert: BeTrue,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpdDockerNetworking[helpers.IPv6]),
destination: helpers.Httpd1,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://%s:80", httpdDockerNetworking[helpers.IPv4]),
destination: helpers.Httpd1,
assert: BeFalse,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpd2DockerNetworking[helpers.IPv6]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://%s:80", httpd2DockerNetworking[helpers.IPv4]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpdDockerNetworking[helpers.IPv6]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://%s:80", httpdDockerNetworking[helpers.IPv4]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: helpers.Client,
to: helpers.Ping6(serverDockerNetworking[helpers.IPv6]),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Ping(serverDockerNetworking[helpers.IPv4]),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netcat("%s 777", serverDockerNetworking[helpers.IPv6]),
destination: helpers.Server,
assert: BeFalse,
},
{
from: helpers.Client,
to: helpers.Netcat("%s 777", serverDockerNetworking[helpers.IPv4]),
destination: helpers.Server,
assert: BeFalse,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv6], helpers.TCP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv4], helpers.TCP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv6], helpers.UDP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv4], helpers.UDP_RR),
destination: helpers.Server,
assert: BeTrue,
},
}
for _, test := range testCases {
By("Container %q test connectivity to %q", test.from, test.destination)
res = vm.ContainerExec(test.from, test.to)
ExpectWithOffset(1, res.WasSuccessful()).To(test.assert(),
"The result of %q from container %q to %s does not match", test.to, test.from, test.destination)
}
By("Testing bidirectional connectivity from client to server")
By("container %s pinging %s IPv6 (should NOT work)", helpers.Server, helpers.Client)
res = vm.ContainerExec(helpers.Server, helpers.Ping6(clientDockerNetworking[helpers.IPv6]))
ExpectWithOffset(1, res).ShouldNot(helpers.CMDSuccess(),
"container %q unexpectedly was able to ping to %q IP:%q", helpers.Server, helpers.Client, clientDockerNetworking[helpers.IPv6])
By("container %s pinging %s IPv4 (should NOT work)", helpers.Server, helpers.Client)
res = vm.ContainerExec(helpers.Server, helpers.Ping(clientDockerNetworking[helpers.IPv4]))
ExpectWithOffset(1, res).ShouldNot(helpers.CMDSuccess(),
"%q was unexpectedly able to ping to %q IP:%q", helpers.Server, helpers.Client, clientDockerNetworking[helpers.IPv4])
By("============= Finished Connectivity Test ============= ")
}
clientServerL3Connectivity := func() {
By("============= Starting Connectivity Test ============= ")
By("Getting IPs of each spawned container")
clientDockerNetworking, err := vm.ContainerInspectNet(helpers.Client)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Client)
By("client container Docker networking: %s", clientDockerNetworking)
serverDockerNetworking, err := vm.ContainerInspectNet(helpers.Server)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Server)
By("server container Docker networking: %s", serverDockerNetworking)
httpdDockerNetworking, err := vm.ContainerInspectNet(helpers.Httpd1)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Httpd1)
By("httpd1 container Docker networking: %s", httpdDockerNetworking)
httpd2DockerNetworking, err := vm.ContainerInspectNet(helpers.Httpd2)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", helpers.Httpd2)
By("httpd2 container Docker networking: %s", httpd2DockerNetworking)
curl1DockerNetworking, err := vm.ContainerInspectNet(curl1ContainerName)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", curl1ContainerName)
By("curl1 container Docker networking: %s", curl1DockerNetworking)
curl2DockerNetworking, err := vm.ContainerInspectNet(curl2ContainerName)
ExpectWithOffset(1, err).Should(BeNil(),
"could not get metadata for container %q", curl2ContainerName)
By("httpd1 container Docker networking: %s", curl2DockerNetworking)
By("Showing policies imported to Cilium")
res := vm.PolicyGetAll()
GinkgoPrint(res.CombineOutput().String())
testCases := []conntestCases{
{
from: curl1ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpdDockerNetworking[helpers.IPv6]),
destination: helpers.Httpd1,
assert: BeTrue,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://%s:80", httpdDockerNetworking[helpers.IPv4]),
destination: helpers.Httpd1,
assert: BeTrue,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpdDockerNetworking[helpers.IPv6]),
destination: helpers.Httpd1,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://%s:80", httpdDockerNetworking[helpers.IPv4]),
destination: helpers.Httpd1,
assert: BeFalse,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpd2DockerNetworking[helpers.IPv6]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl1ContainerName,
to: helpers.CurlFail("http://%s:80", httpd2DockerNetworking[helpers.IPv4]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://[%s]:80", httpd2DockerNetworking[helpers.IPv6]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: curl2ContainerName,
to: helpers.CurlFail("http://%s:80", httpd2DockerNetworking[helpers.IPv4]),
destination: helpers.Httpd2,
assert: BeFalse,
},
{
from: helpers.Client,
to: helpers.Ping6(serverDockerNetworking[helpers.IPv6]),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Ping(serverDockerNetworking[helpers.IPv4]),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv6], helpers.TCP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv4], helpers.TCP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv6], helpers.UDP_RR),
destination: helpers.Server,
assert: BeTrue,
},
{
from: helpers.Client,
to: helpers.Netperf(serverDockerNetworking[helpers.IPv4], helpers.UDP_RR),
destination: helpers.Server,
assert: BeTrue,
},
}
for _, test := range testCases {
By("Container %q test connectivity to %q", test.from, test.destination)
res = vm.ContainerExec(test.from, test.to)
ExpectWithOffset(1, res.WasSuccessful()).To(test.assert(),
"The result of %q from container %q to %s does not match", test.to, test.from, test.destination)
}
By("============= Finished Connectivity Test ============= ")
}
BeforeEach(func() {
// TODO: provide map[string]string instead of one string representing KV pair.
vm.ContainerCreate(helpers.Client, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.client")
vm.ContainerCreate(helpers.Server, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.server")
vm.ContainerCreate(helpers.Httpd1, constants.HttpdImage, helpers.CiliumDockerNetwork, "-l id.httpd")
vm.ContainerCreate(helpers.Httpd2, constants.HttpdImage, helpers.CiliumDockerNetwork, "-l id.httpd_deny")
vm.ContainerCreate(curl1ContainerName, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.curl")
vm.ContainerCreate(curl2ContainerName, constants.NetperfImage, helpers.CiliumDockerNetwork, "-l id.curl2")
vm.PolicyDelAll().ExpectSuccess("cannot delete all policies")
_, err := vm.PolicyImportAndWait(vm.GetFullPath("ct-test-policy.json"), helpers.HelperTimeout)
Expect(err).Should(BeNil())
})
JustBeforeEach(func() {
monitorStop = vm.MonitorStart()
})
AfterEach(func() {
containersToRm := []string{helpers.Client, helpers.Server, helpers.Httpd1, helpers.Httpd2, curl1ContainerName, curl2ContainerName}
for _, containerToRm := range containersToRm {
vm.ContainerRm(containerToRm)
}
vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
ExpectPolicyEnforcementUpdated(vm, helpers.PolicyEnforcementDefault)
})
JustAfterEach(func() {
vm.ValidateNoErrorsInLogs(CurrentGinkgoTestDescription().Duration)
Expect(monitorStop()).To(BeNil(), "cannot stop monitor command")
})
AfterFailed(func() {
vm.ReportFailed("cilium policy get")
})
It("Conntrack-related configuration options for endpoints", func() {
By("Getting Endpoint IDs")
endpoints, err := vm.GetEndpointsIds()
Expect(err).Should(BeNil(), "could not get endpoint IDs")
// Check that endpoint IDs exist in map.
for _, endpointName := range []string{helpers.Server, helpers.Client} {
_, exists := endpoints[endpointName]
Expect(exists).To(BeTrue(), "unable to retrieve endpoint ID for endpoint %s", endpointName)
By("Endpoint ID for %q = %q", endpointName, endpoints[endpointName])
}
endpointsToConfigure := []string{endpoints[helpers.Server], endpoints[helpers.Client]}
// Iterate through possible values to configure ConntrackLocal option,
// apply to both endpoints, verify the option configuration change matches
// what was performed, and then run connectivity test with endpoints.
conntrackLocalOptionModes := []string{helpers.OptionDisabled, helpers.OptionEnabled}
for _, conntrackLocalOptionMode := range conntrackLocalOptionModes {
By("Testing with endpoint configuration option: ConntrackLocal=%s", conntrackLocalOptionMode)
for _, endpointToConfigure := range endpointsToConfigure {
err := vm.SetAndWaitForEndpointConfiguration(
endpointToConfigure, helpers.OptionConntrackLocal, conntrackLocalOptionMode)
Expect(err).To(BeNil(), "Cannot set ConnTrackLocal=%q for endpoint %q",
conntrackLocalOptionMode, endpointToConfigure)
}
areEndpointsReady := vm.WaitEndpointsReady()
Expect(areEndpointsReady).Should(BeTrue(), "Endpoints are not ready after timeout")
clientServerConnectivity()
}
By("Testing Conntrack endpoint configuration option disabled")
// Delete all L4 policy so we can disable connection tracking
vm.PolicyDelAll().ExpectSuccess("Policies cannot be deleted")
for _, endpointToConfigure := range endpointsToConfigure {
// ConntrackLocal must be disabled as it depends on Conntrack
err := vm.SetAndWaitForEndpointConfiguration(endpointToConfigure, helpers.OptionConntrackLocal, helpers.OptionDisabled)
Expect(err).To(BeNil(), "Cannot disable ConntrackLocal for the endpoint %q", endpointToConfigure)
err = vm.SetAndWaitForEndpointConfiguration(endpointToConfigure, helpers.OptionConntrack, helpers.OptionDisabled)
Expect(err).To(BeNil(), "Cannot disable ConnTrack for the endpoint %q", endpointToConfigure)
}
// Need to add policy that allows communication in both directions.
_, err = vm.PolicyImportAndWait(
vm.GetFullPath(CTPolicyConntrackLocalDisabled),
helpers.HelperTimeout)
Expect(err).Should(BeNil(), "cannot import %s", CTPolicyConntrackLocalDisabled)
clientServerL3Connectivity()
})
}
}