Skip to content

Commit

Permalink
Merge pull request #344 from flatcar/tormath1/selinux
Browse files Browse the repository at this point in the history
test/selinux: update boolean name and added back enforced Selinux Cilium tests
  • Loading branch information
tormath1 authored Sep 22, 2023
2 parents 2998fe8 + 6598471 commit 7d8aac2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
10 changes: 3 additions & 7 deletions kola/tests/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ var (
_ = c.MustSSH(controller, "/opt/bin/cilium uninstall")
version := params["CiliumVersion"].(string)
cidr := params["PodSubnet"].(string)
cmd := fmt.Sprintf("/opt/bin/cilium install --config enable-endpoint-routes=true --config cluster-pool-ipv4-cidr=%s --version=%s --encryption=ipsec --wait=false --restart-unmanaged-pods=false --rollback=false", cidr, version)
_, _ = c.SSH(controller, cmd)
patch := `/opt/bin/kubectl --namespace kube-system patch daemonset/cilium -p '{"spec":{"template":{"spec":{"containers":[{"name":"cilium-agent","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}],"initContainers":[{"name":"mount-cgroup","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"apply-sysctl-overwrites","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"clean-cilium-state","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}]}}}}'`
_ = c.MustSSH(controller, patch)
status := "/opt/bin/cilium status --wait --wait-duration 1m"
_ = c.MustSSH(controller, status)
cmd := fmt.Sprintf("/opt/bin/cilium install --config enable-endpoint-routes=true --config cluster-pool-ipv4-cidr=%s --version=%s --encryption=ipsec --wait --wait-duration 1m", cidr, version)
_ = c.MustSSH(controller, cmd)
},
},
},
Expand Down Expand Up @@ -239,7 +235,7 @@ func init() {
major = 3140
}

if CNI == "flannel" || CNI == "cilium" {
if CNI == "flannel" {
flags = append(flags, register.NoEnableSelinux)
}

Expand Down
1 change: 0 additions & 1 deletion kola/tests/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ EOF
--config enable-endpoint-routes=true \
--config cluster-pool-ipv4-cidr={{ .PodSubnet }} \
--version={{ .CiliumVersion }} 2>&1 | iconv --from-code utf-8 --to-code ascii//TRANSLIT
kubectl --namespace kube-system patch daemonset/cilium -p '{"spec":{"template":{"spec":{"containers":[{"name":"cilium-agent","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}],"initContainers":[{"name":"mount-cgroup","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"apply-sysctl-overwrites","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"clean-cilium-state","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}]}}}}'
# --wait will wait for status to report success
/opt/bin/cilium status --wait 2>&1 | iconv --from-code utf-8 --to-code ascii//TRANSLIT
{{ end }}
Expand Down
1 change: 0 additions & 1 deletion kola/tests/kubeadm/testdata/master-cilium-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ EOF
--config enable-endpoint-routes=true \
--config cluster-pool-ipv4-cidr=192.168.0.0/17 \
--version=v0.11.1 2>&1 | iconv --from-code utf-8 --to-code ascii//TRANSLIT
kubectl --namespace kube-system patch daemonset/cilium -p '{"spec":{"template":{"spec":{"containers":[{"name":"cilium-agent","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}],"initContainers":[{"name":"mount-cgroup","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"apply-sysctl-overwrites","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}},{"name":"clean-cilium-state","securityContext":{"seLinuxOptions":{"level":"s0","type":"unconfined_t"}}}]}}}}'
# --wait will wait for status to report success
/opt/bin/cilium status --wait 2>&1 | iconv --from-code utf-8 --to-code ascii//TRANSLIT

Expand Down
25 changes: 21 additions & 4 deletions kola/tests/misc/selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import (
"regexp"
"strings"

"github.com/coreos/go-semver/semver"
"github.com/flatcar/mantle/kola/cluster"
"github.com/flatcar/mantle/kola/register"
"github.com/flatcar/mantle/platform"
)

var seBoolean = "container_use_nfs"

func init() {
register.Register(&register.Test{
Run: SelinuxEnforce,
Expand All @@ -40,6 +43,15 @@ func init() {
Distros: []string{"cl", "fcos", "rhcos"},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
SkipFunc: func(version semver.Version, channel, arch, platform string) bool {
// Workaround to set the SELinux boolean name based of the Flatcar version.
// Note: it works only if we test '*'
if version.LessThan(semver.Version{Major: 3733}) {
seBoolean = "virt_use_nfs"
}

return false
},
})
register.Register(&register.Test{
Run: SelinuxBooleanPersist,
Expand All @@ -48,6 +60,15 @@ func init() {
Distros: []string{"fcos", "rhcos"},
// This test is normally not related to the cloud environment
Platforms: []string{"qemu", "qemu-unpriv"},
SkipFunc: func(version semver.Version, channel, arch, platform string) bool {
// Workaround to set the SELinux boolean name based of the Flatcar version.
// Note: it works only if we test '*'
if version.LessThan(semver.Version{Major: 3733}) {
seBoolean = "virt_use_nfs"
}

return false
},
})
register.Register(&register.Test{
Run: SelinuxManage,
Expand Down Expand Up @@ -155,8 +176,6 @@ func SelinuxEnforce(c cluster.TestCluster) {

// SelinuxBoolean checks that you can tweak a boolean in the current session
func SelinuxBoolean(c cluster.TestCluster) {
seBoolean := "virt_use_nfs"

m := c.Machines()[0]

tempBoolState, err := getSelinuxBooleanState(c, m, seBoolean)
Expand Down Expand Up @@ -186,8 +205,6 @@ func SelinuxBoolean(c cluster.TestCluster) {
// SelinuxBooleanPersist checks that you can tweak a boolean and have it
// persist across reboots
func SelinuxBooleanPersist(c cluster.TestCluster) {
seBoolean := "virt_use_nfs"

m := c.Machines()[0]

persistBoolState, err := getSelinuxBooleanState(c, m, seBoolean)
Expand Down

0 comments on commit 7d8aac2

Please sign in to comment.