Skip to content

Commit

Permalink
Change securityContext on operator, so that scc is 'restricted'
Browse files Browse the repository at this point in the history
This change will allow the SCC to be 'restricted',
otherwise it will be 'privileged'

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
  • Loading branch information
akrejcir committed Aug 20, 2021
1 parent 42d6863 commit 0ce711f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/manager/manager.template.yaml
Expand Up @@ -19,7 +19,7 @@ spec:
serviceAccountName: ssp-operator
priorityClassName: system-cluster-critical
securityContext:
runAsUser: 1000
runAsNonRoot: true
containers:
- command:
- /manager
Expand Down
40 changes: 40 additions & 0 deletions tests/misc_test.go
Expand Up @@ -3,6 +3,9 @@ package tests
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
core "k8s.io/api/core/v1"
validator "kubevirt.io/ssp-operator/internal/operands/template-validator"
"sigs.k8s.io/controller-runtime/pkg/client"

lifecycleapi "kubevirt.io/controller-lifecycle-operator-sdk/pkg/sdk/api"

Expand Down Expand Up @@ -73,3 +76,40 @@ var _ = Describe("Observed generation", func() {
Expect(err).ToNot(HaveOccurred())
})
})

var _ = Describe("SCC annotation", func() {
const (
sccAnnotation = "openshift.io/scc"
sccRestricted = "restricted"
)

BeforeEach(func() {
waitUntilDeployed()
})

It("operator pod should have 'restricted' scc annotation", func() {
pods := &core.PodList{}
err := apiClient.List(ctx, pods, client.MatchingLabels{"control-plane": "ssp-operator"})

Expect(err).ToNot(HaveOccurred())
Expect(pods.Items).ToNot(BeEmpty())

for _, pod := range pods.Items {
Expect(pod.Annotations).To(HaveKeyWithValue(sccAnnotation, sccRestricted), "Expected pod %s/%s to have scc 'restricted'", pod.Namespace, pod.Name)
}
})

It("template validator pods should have 'restricted' scc annotation", func() {
pods := &core.PodList{}
err := apiClient.List(ctx, pods,
client.InNamespace(strategy.GetNamespace()),
client.MatchingLabels{validator.KubevirtIo: validator.VirtTemplateValidator})

Expect(err).ToNot(HaveOccurred())
Expect(pods.Items).ToNot(BeEmpty())

for _, pod := range pods.Items {
Expect(pod.Annotations).To(HaveKeyWithValue(sccAnnotation, sccRestricted), "Expected pod %s/%s to have scc 'restricted'", pod.Namespace, pod.Name)
}
})
})

0 comments on commit 0ce711f

Please sign in to comment.