@@ -26,7 +26,7 @@ import (
26
26
"context"
27
27
"fmt"
28
28
29
- "k8s.io/api/core/v1"
29
+ v1 "k8s.io/api/core/v1"
30
30
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31
31
"k8s.io/apimachinery/pkg/util/uuid"
32
32
"k8s.io/kubernetes/test/e2e/framework"
@@ -252,10 +252,11 @@ func testPodSELinuxLabeling(f *framework.Framework, hostIPC bool, hostPID bool)
252
252
pod .Spec .SecurityContext .SELinuxOptions = & v1.SELinuxOptions {
253
253
Level : "s0:c0,c1" ,
254
254
}
255
-
256
255
f .TestContainerOutput ("Pod with same MCS label reading test file" , pod , 0 , []string {testContent })
256
+
257
257
// Confirm that the same pod with a different MCS
258
258
// label cannot access the volume
259
+ ginkgo .By ("confirming a container with a different MCS label is unable to read the file" )
259
260
pod = scTestPod (hostIPC , hostPID )
260
261
pod .Spec .Volumes = volumes
261
262
pod .Spec .Containers [0 ].VolumeMounts = volumeMounts
@@ -269,7 +270,10 @@ func testPodSELinuxLabeling(f *framework.Framework, hostIPC bool, hostPID bool)
269
270
err = f .WaitForPodRunning (pod .Name )
270
271
framework .ExpectNoError (err , "Error waiting for pod to run %v" , pod )
271
272
272
- content , err = tk .ReadFileViaContainer (pod .Name , "test-container" , testFilePath )
273
- framework .ExpectNoError (err , "Error reading file via container" )
274
- gomega .Expect (content ).NotTo (gomega .ContainSubstring (testContent ))
273
+ // for this to work, SELinux should be in enforcing mode, so let's check that
274
+ isEnforced , err := tk .ReadFileViaContainer (pod .Name , "test-container" , "/sys/fs/selinux/enforce" )
275
+ if err == nil && isEnforced == "1" {
276
+ _ , err = tk .ReadFileViaContainer (pod .Name , "test-container" , testFilePath )
277
+ framework .ExpectError (err , "expecting SELinux to not let the container with different MCS label to read the file" )
278
+ }
275
279
}
0 commit comments