Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kola/docker: add selinux test #177

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions kola/tests/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ type simplifiedDockerInfo struct {
}

func init() {
register.Register(&register.Test{
Run: dockerSELinux,
ClusterSize: 1,
Name: "docker.selinux",
Distros: []string{"cl"},
Channels: []string{"alpha", "beta"},
Architectures: []string{"amd64"},
})
register.Register(&register.Test{
Run: dockerNetwork,
ClusterSize: 2,
Expand Down Expand Up @@ -624,3 +632,49 @@ func hasSecurityOptions(opts []string) bool {

return true
}

// dockerSELinux tests SELinux for Docker by running a container
// in enforce mode and in permissive mode with a non-labelled file
// and a labelled file
func dockerSELinux(c cluster.TestCluster) {
m := c.Machines()[0]

var cmd string

cmd = `sudo mkdir /etc/misc && \
docker run -v "/etc/misc:/opt" --rm busybox true`

// assert SELinux is in permissive mode
if err := c.MustSSH(m, "sudo setenforce 0"); err != nil {
c.Fatalf("unable to set permissive mode: %v", err)
}

// create a directory to share and run docker command
if err := c.MustSSH(m, cmd); err != nil {
c.Fatalf("unable to run docker command: %v", err)
}

// switch SELinux to enforcing mode
if err := c.MustSSH(m, "sudo setenforce 1"); err != nil {
c.Fatalf("unable to set enforcing mode: %v", err)
}

// run docker command to assert it fails because of wrong labeling
if _, err := c.SSH(m, `docker run -v "/etc/misc:/opt" --rm busybox sh -c "echo world > /opt/hello"`); err == nil {
c.Fatalf("command should raise a permission error")
}

// run docker command with correct relabel action (z)
if err := c.MustSSH(m, `docker run -v "/etc/misc:/opt:z" --rm busybox sh -c "echo world > /opt/hello"`); err != nil {
c.Fatalf("unable to run docker command: %v", err)
}

out, err := c.SSH(m, "cat /etc/misc/hello")
if err != nil {
c.Fatalf("unable display file content: %v", err)
}

if string(out) != "world" {
c.Fatal("/etc/misc/hello should holds 'world'")
}
}