Skip to content

Commit

Permalink
Merge pull request #539 from flatcar/krnowak/openbsd-netcat
Browse files Browse the repository at this point in the history
kola/tests: Replace nmap's ncat with openbsd ncat
  • Loading branch information
krnowak authored Aug 9, 2024
2 parents b94c871 + a602f87 commit a0b4473
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand=
- using `--qemu-vnc 0`, it's possible to setup a VNC server. Similar to SSH you need to identify the PID of the `qemu` instance to setup a proxy:
```
mkfifo reply
ncat -kl 12800 < reply | sudo nsenter -t "${QEMUPID}" -n ncat localhost 5900 > reply
nc -kl 12800 < reply | sudo nsenter -t "${QEMUPID}" -n nc localhost 5900 > reply
rm reply
```
Now, you can access the VNC session on localhost:12800 using a VNC client.
Expand Down
12 changes: 6 additions & 6 deletions kola/tests/crio/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,16 @@ func crioNetwork(c cluster.TestCluster) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Log("creating netcat containers")

// Since genContainer also generates crio pod/container configs,
// there will be a duplicate config file on each machine.
// Thus we only save one set for later use.
crioConfigPod, crioConfigContainer, err := genContainer(c, src, "ncat", "ncat", []string{"ncat", "echo"}, []string{"ncat"})
crioConfigPod, crioConfigContainer, err := genContainer(c, src, "netcat", "netcat", []string{"nc", "echo", "timeout"}, []string{"nc"})
if err != nil {
c.Fatal(err)
}
_, _, err = genContainer(c, dest, "ncat", "ncat", []string{"ncat", "echo"}, []string{"ncat"})
_, _, err = genContainer(c, dest, "netcat", "netcat", []string{"nc", "echo", "timeout"}, []string{"nc"})
if err != nil {
c.Fatal(err)
}
Expand All @@ -285,8 +285,8 @@ func crioNetwork(c cluster.TestCluster) {
return err
}

// This command will block until a message is recieved
output, err := c.SSH(dest, fmt.Sprintf("sudo timeout 30 crictl exec %s echo 'HELLO FROM SERVER' | timeout 20 ncat --listen 0.0.0.0 9988 || echo 'LISTENER TIMEOUT'", containerID))
// This command will block until a message is received
output, err := c.SSH(dest, fmt.Sprintf("sudo timeout 30 crictl exec %s echo 'HELLO FROM SERVER' | timeout 20 nc -l -N 0.0.0.0 9988 || echo 'LISTENER TIMEOUT'", containerID))
if err != nil {
return err
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func crioNetwork(c cluster.TestCluster) {
return err
}

output, err := c.SSH(src, fmt.Sprintf("sudo crictl exec %s echo 'HELLO FROM CLIENT' | ncat %s 9988",
output, err := c.SSH(src, fmt.Sprintf("sudo crictl exec %s echo 'HELLO FROM CLIENT' | nc %s 9988",
containerID, dest.PrivateIP()))
if err != nil {
return err
Expand Down
59 changes: 48 additions & 11 deletions kola/tests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,21 @@ func init() {
Platforms: []string{"qemu", "qemu-unpriv"},
})
register.Register(&register.Test{
Run: dockerNetwork,
Run: dockerNetworkNmapNcat,
ClusterSize: 2,
Name: "docker.network",
Name: "docker.network-nmap-ncat",
Distros: []string{"cl"},
EndVersion: semver.Version{Major: 4057},
// No idea why Docker containers cannot reach each the other VM
ExcludePlatforms: []string{"qemu-unpriv"},
// Should run on all cloud environments to check against network conflicts
})
register.Register(&register.Test{
Run: dockerNetworkOpenBsdNc,
ClusterSize: 2,
Name: "docker.network-openbsd-nc",
Distros: []string{"cl"},
MinVersion: semver.Version{Major: 4057},
// No idea why Docker containers cannot reach each the other VM
ExcludePlatforms: []string{"qemu-unpriv"},
// Should run on all cloud environments to check against network conflicts
Expand Down Expand Up @@ -362,21 +373,47 @@ func dockerResources(c cluster.TestCluster) {
}
}

type ncSetup struct {
imageName string
binaries []string
clientCommand string
serverCommand string
}

func dockerNetworkNmapNcat(c cluster.TestCluster) {
nc := ncSetup{
imageName: "ncat",
binaries: []string{"ncat"},
clientCommand: "ncat",
serverCommand: "ncat --idle-timeout 20 --listen",
}
dockerNetwork(c, nc)
}

func dockerNetworkOpenBsdNc(c cluster.TestCluster) {
nc := ncSetup{
imageName: "netcat",
binaries: []string{"nc", "timeout"},
clientCommand: "nc",
serverCommand: "timeout 20 nc -N -l",
}
dockerNetwork(c, nc)
}

// Ensure that docker containers can make network connections outside of the host
func dockerNetwork(c cluster.TestCluster) {
func dockerNetwork(c cluster.TestCluster, nc ncSetup) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Logf("creating %s containers\n", nc.imageName)

GenDockerImage(c, src, "ncat", []string{"ncat"})
GenDockerImage(c, dest, "ncat", []string{"ncat"})
GenDockerImage(c, src, nc.imageName, nc.binaries)
GenDockerImage(c, dest, nc.imageName, nc.binaries)

listener := func(ctx context.Context) error {
// Will block until a message is recieved
out, err := c.SSH(dest,
`echo "HELLO FROM SERVER" | docker run -i -p 9988:9988 ncat ncat --idle-timeout 20 --listen 0.0.0.0 9988`,
)
// Will block until a message is received
destCmd := fmt.Sprintf(`echo "HELLO FROM SERVER" | docker run -i -p 9988:9988 %s %s 0.0.0.0 9988`, nc.imageName, nc.serverCommand)
out, err := c.SSH(dest, destCmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -409,7 +446,7 @@ func dockerNetwork(c cluster.TestCluster) {
}
}

srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | docker run -i ncat ncat %s 9988`, dest.PrivateIP())
srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | docker run -i %s %s %s 9988`, nc.imageName, nc.clientCommand, dest.PrivateIP())
out, err := c.SSH(src, srcCmd)
if err != nil {
return err
Expand Down
10 changes: 5 additions & 5 deletions kola/tests/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ func podmanNetworkTest(c cluster.TestCluster) {
machines := c.Machines()
src, dest := machines[0], machines[1]

c.Log("creating ncat containers")
c.Log("creating netcat containers")

tutil.GenPodmanScratchContainer(c, src, "ncat", []string{"ncat"})
tutil.GenPodmanScratchContainer(c, dest, "ncat", []string{"ncat"})
tutil.GenPodmanScratchContainer(c, src, "netcat", []string{"timeout", "nc"})
tutil.GenPodmanScratchContainer(c, dest, "netcat", []string{"timeout", "nc"})

listener := func(ctx context.Context) error {
// Will block until a message is recieved
out, err := c.SSH(dest,
`echo "HELLO FROM SERVER" | sudo podman run -i -p 9988:9988 ncat ncat --idle-timeout 20 --listen 0.0.0.0 9988`,
`echo "HELLO FROM SERVER" | sudo podman run -i -p 9988:9988 netcat timeout 20 nc -l -N 0.0.0.0 9988`,
)
if err != nil {
return err
Expand Down Expand Up @@ -317,7 +317,7 @@ func podmanNetworkTest(c cluster.TestCluster) {
}
}

srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | sudo podman run -i ncat ncat %s 9988`, dest.PrivateIP())
srcCmd := fmt.Sprintf(`echo "HELLO FROM CLIENT" | sudo podman run -i netcat nc %s 9988`, dest.PrivateIP())
out, err := c.SSH(src, srcCmd)
if err != nil {
return err
Expand Down

0 comments on commit a0b4473

Please sign in to comment.