Skip to content

Commit 57c0b77

Browse files
Amarthya-vAmarthya Valija
andauthored
Update test case to enforce security context settings (#346)
* Update test case to enforce security context settings * Fix test case for security context enforcement * Fix test case for Security context enforcement * Fix test case for Security Context enforcement --------- Co-authored-by: Amarthya Valija <[email protected]>
1 parent 5803bd9 commit 57c0b77

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

osde2e/managed_cluster_validating_webhooks_test.go

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/util/intstr"
2828
"k8s.io/client-go/dynamic"
2929
"k8s.io/client-go/kubernetes/scheme"
30+
"k8s.io/utils/pointer"
3031
"sigs.k8s.io/controller-runtime/pkg/client/config"
3132
"sigs.k8s.io/controller-runtime/pkg/log"
3233
"sigs.k8s.io/e2e-framework/klient/k8s"
@@ -105,6 +106,35 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
105106
Expect(err).ToNot(HaveOccurred())
106107
})
107108

109+
It("should create a pod with the correct security context", func() {
110+
pod := &v1.Pod{
111+
ObjectMeta: metav1.ObjectMeta{
112+
Name: "testpod",
113+
},
114+
Spec: v1.PodSpec{
115+
Containers: []v1.Container{
116+
{
117+
Name: "test",
118+
Image: "quay.io/jitesoft/nginx:mainline",
119+
SecurityContext: &v1.SecurityContext{
120+
AllowPrivilegeEscalation: pointer.BoolPtr(false),
121+
Capabilities: &v1.Capabilities{
122+
Drop: []v1.Capability{"ALL"},
123+
},
124+
RunAsNonRoot: pointer.BoolPtr(true),
125+
SeccompProfile: &v1.SeccompProfile{
126+
Type: v1.SeccompProfileTypeRuntimeDefault,
127+
},
128+
},
129+
},
130+
},
131+
},
132+
}
133+
134+
err := client.Create(context.TODO(), pod)
135+
Expect(err).NotTo(HaveOccurred())
136+
})
137+
108138
Describe("sre-pod-validation", Ordered, func() {
109139
const (
110140
privilegedNamespace = "openshift-backplane"
@@ -125,16 +155,41 @@ var _ = Describe("Managed Cluster Validating Webhooks", Ordered, func() {
125155
Spec: v1.PodSpec{
126156
Containers: []v1.Container{
127157
{
128-
Name: "test",
158+
Name: "test-ubi",
129159
Image: "registry.access.redhat.com/ubi8/ubi-minimal",
160+
SecurityContext: &v1.SecurityContext{
161+
AllowPrivilegeEscalation: pointer.BoolPtr(false),
162+
Capabilities: &v1.Capabilities{
163+
Drop: []v1.Capability{"ALL"},
164+
},
165+
RunAsNonRoot: pointer.BoolPtr(true),
166+
SeccompProfile: &v1.SeccompProfile{
167+
Type: v1.SeccompProfileTypeRuntimeDefault,
168+
},
169+
},
170+
},
171+
{
172+
Name: "test-nginx",
173+
Image: "quay.io/jitesoft/nginx:mainline",
174+
SecurityContext: &v1.SecurityContext{
175+
AllowPrivilegeEscalation: pointer.BoolPtr(false),
176+
Capabilities: &v1.Capabilities{
177+
Drop: []v1.Capability{"ALL"},
178+
},
179+
RunAsNonRoot: pointer.BoolPtr(true),
180+
SeccompProfile: &v1.SeccompProfile{
181+
Type: v1.SeccompProfileTypeRuntimeDefault,
182+
},
183+
},
130184
},
131185
},
132186
Tolerations: []v1.Toleration{
133187
{
134188
Key: "node-role.kubernetes.io/master",
135189
Value: "toleration-key-value",
136190
Effect: v1.TaintEffectNoSchedule,
137-
}, {
191+
},
192+
{
138193
Key: "node-role.kubernetes.io/infra",
139194
Value: "toleration-key-value2",
140195
Effect: v1.TaintEffectNoSchedule,

0 commit comments

Comments
 (0)