@@ -31,7 +31,7 @@ import (
31
31
32
32
const runAsUserNameContainerName = "run-as-username-container"
33
33
34
- var _ = SIGDescribe ("[Feature:Windows] SecurityContext RunAsUserName " , func () {
34
+ var _ = SIGDescribe ("[Feature:Windows] SecurityContext" , func () {
35
35
f := framework .NewDefaultFramework ("windows-run-as-username" )
36
36
37
37
ginkgo .It ("should be able create pods and run containers with a given username" , func () {
@@ -71,6 +71,29 @@ var _ = SIGDescribe("[Feature:Windows] SecurityContext RunAsUserName", func() {
71
71
f .TestContainerOutput ("check overridden username" , pod , 0 , []string {"ContainerUser" })
72
72
f .TestContainerOutput ("check pod SecurityContext username" , pod , 1 , []string {"ContainerAdministrator" })
73
73
})
74
+ ginkgo .It ("should ignore Linux Specific SecurityContext if set" , func () {
75
+ ginkgo .By ("Creating a pod with SELinux options" )
76
+ // It is sufficient to show that the pod comes up here. Since we're stripping the SELinux and other linux
77
+ // security contexts in apiserver and not updating the pod object in the apiserver, we cannot validate the
78
+ // the pod object to not have those security contexts. However the pod coming to running state is a sufficient
79
+ // enough condition for us to validate since prior to https://github.com/kubernetes/kubernetes/pull/93475
80
+ // the pod would have failed to come up.
81
+ windowsPodWithSELinux := createTestPod (f , windowsBusyBoximage , windowsOS )
82
+ windowsPodWithSELinux .Spec .Containers [0 ].Args = []string {"test-webserver-with-selinux" }
83
+ windowsPodWithSELinux .Spec .SecurityContext = & v1.PodSecurityContext {}
84
+ containerUserName := "ContainerAdministrator"
85
+ windowsPodWithSELinux .Spec .SecurityContext .SELinuxOptions = & v1.SELinuxOptions {Level : "s0:c24,c9" }
86
+ windowsPodWithSELinux .Spec .Containers [0 ].SecurityContext = & v1.SecurityContext {
87
+ SELinuxOptions : & v1.SELinuxOptions {Level : "s0:c24,c9" },
88
+ WindowsOptions : & v1.WindowsSecurityContextOptions {RunAsUserName : & containerUserName }}
89
+ windowsPodWithSELinux .Spec .Tolerations = []v1.Toleration {{Key : "os" , Value : "Windows" }}
90
+ windowsPodWithSELinux , err := f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Create (context .TODO (),
91
+ windowsPodWithSELinux , metav1.CreateOptions {})
92
+ framework .ExpectNoError (err )
93
+ framework .Logf ("Created pod %v" , windowsPodWithSELinux )
94
+ framework .ExpectNoError (e2epod .WaitForPodNameRunningInNamespace (f .ClientSet , windowsPodWithSELinux .Name ,
95
+ f .Namespace .Name ), "failed to wait for pod %s to be running" , windowsPodWithSELinux .Name )
96
+ })
74
97
})
75
98
76
99
func runAsUserNamePod (username * string ) * v1.Pod {
@@ -80,6 +103,7 @@ func runAsUserNamePod(username *string) *v1.Pod {
80
103
Name : podName ,
81
104
},
82
105
Spec : v1.PodSpec {
106
+ NodeSelector : map [string ]string {"kubernetes.io/os" : "windows" },
83
107
Containers : []v1.Container {
84
108
{
85
109
Name : runAsUserNameContainerName ,
0 commit comments