@@ -8,29 +8,33 @@ import (
8
8
g "github.com/onsi/ginkgo"
9
9
o "github.com/onsi/gomega"
10
10
11
+ exutil "github.com/openshift/origin/test/extended/util"
11
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
13
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
13
14
e2e "k8s.io/kubernetes/test/e2e/framework"
15
+ )
14
16
15
- testutil "github.com/openshift/origin/test/util"
17
+ const (
18
+ supplementalGroupsPod = "supplemental-groups"
16
19
)
17
20
18
21
var _ = g .Describe ("[security] supplemental groups" , func () {
19
22
defer g .GinkgoRecover ()
20
23
21
24
var (
22
- f = e2e .NewDefaultFramework ("security-supgroups" )
25
+ oc = exutil .NewCLI ("sup-groups" , exutil .KubeConfigPath ())
26
+ f = oc .KubeFramework ()
23
27
)
24
28
25
29
g .Describe ("[Conformance]Ensure supplemental groups propagate to docker" , func () {
26
- g .It ("should propagate requested groups to the docker host config [local]" , func () {
27
- g .By ("getting the docker client" )
28
- dockerCli , err := testutil .NewDockerClient ()
29
- o .Expect (err ).NotTo (o .HaveOccurred ())
30
+ g .It ("should propagate requested groups to the container [local]" , func () {
30
31
31
32
fsGroup := int64 (1111 )
32
33
supGroup := int64 (2222 )
33
34
35
+ _ , err := oc .AsAdmin ().Run ("adm" ).Args ("policy" , "add-scc-to-user" , "anyuid" , oc .Username ()).Output ()
36
+ o .Expect (err ).NotTo (o .HaveOccurred ())
37
+
34
38
// create a pod that is requesting supplemental groups. We request specific sup groups
35
39
// so that we can check for the exact values later and not rely on SCC allocation.
36
40
g .By ("creating a pod that requests supplemental groups" )
@@ -52,50 +56,29 @@ var _ = g.Describe("[security] supplemental groups", func() {
52
56
err = f .WaitForPodRunning (submittedPod .Name )
53
57
o .Expect (err ).NotTo (o .HaveOccurred ())
54
58
55
- // find the docker id of our running container.
56
- g .By ("finding the docker container id on the pod" )
57
- retrievedPod , err = f .ClientSet .CoreV1 ().Pods (f .Namespace .Name ).Get (submittedPod .Name , metav1.GetOptions {})
58
- o .Expect (err ).NotTo (o .HaveOccurred ())
59
- containerID , err := getContainerID (retrievedPod )
60
- o .Expect (err ).NotTo (o .HaveOccurred ())
61
-
62
- // now check the host config of the container which should have been updated by the
63
- // kubelet. If that is good then ensure we have the groups we expected.
64
- g .By ("inspecting the container" )
65
- dockerContainer , err := dockerCli .InspectContainer (containerID )
59
+ out , stderr , err := oc .Run ("exec" ).Args ("-p" , supplementalGroupsPod , "--" , "/usr/bin/id" , "-G" ).Outputs ()
60
+ if err != nil {
61
+ logs , _ := oc .Run ("logs" ).Args (supplementalGroupsPod ).Output ()
62
+ e2e .Failf ("Failed to get groups: \n %q, %q, pod logs: \n %q" , out , stderr , logs )
63
+ }
66
64
o .Expect (err ).NotTo (o .HaveOccurred ())
67
65
68
- g .By ("ensuring the host config has GroupAdd" )
69
- groupAdd := dockerContainer .HostConfig .GroupAdd
70
- o .Expect (groupAdd ).ToNot (o .BeEmpty (), fmt .Sprintf ("groupAdd on host config was %v" , groupAdd ))
71
-
72
- g .By ("ensuring the groups are set" )
66
+ split := strings .Split (out , " " )
67
+ o .Expect (split ).ToNot (o .BeEmpty (), fmt .Sprintf ("no groups in pod: %v" , out ))
73
68
group := strconv .FormatInt (fsGroup , 10 )
74
- o .Expect (groupAdd ).To (o .ContainElement (group ), fmt .Sprintf ("fsGroup %v should exist on host config: %v" , fsGroup , groupAdd ))
75
-
69
+ o .Expect (split ).To (o .ContainElement (group ), fmt .Sprintf ("fsGroup %v should exist in pod's groups: %v" , fsGroup , out ))
76
70
group = strconv .FormatInt (supGroup , 10 )
77
- o .Expect (groupAdd ).To (o .ContainElement (group ), fmt .Sprintf ("supGroup %v should exist on host config : %v" , supGroup , groupAdd ))
71
+ o .Expect (split ).To (o .ContainElement (group ), fmt .Sprintf ("supGroup %v should exist in pod's groups : %v" , supGroup , out ))
78
72
})
79
73
80
74
})
81
75
})
82
76
83
- // getContainerID is a helper to parse the docker container id from a status.
84
- func getContainerID (p * kapiv1.Pod ) (string , error ) {
85
- for _ , status := range p .Status .ContainerStatuses {
86
- if len (status .ContainerID ) > 0 {
87
- containerID := strings .Replace (status .ContainerID , "docker://" , "" , - 1 )
88
- return containerID , nil
89
- }
90
- }
91
- return "" , fmt .Errorf ("unable to find container id on pod" )
92
- }
93
-
94
77
// supGroupPod generates the pod requesting supplemental groups.
95
78
func supGroupPod (fsGroup int64 , supGroup int64 ) * kapiv1.Pod {
96
79
return & kapiv1.Pod {
97
80
ObjectMeta : metav1.ObjectMeta {
98
- Name : "supplemental-groups" ,
81
+ Name : supplementalGroupsPod ,
99
82
},
100
83
Spec : kapiv1.PodSpec {
101
84
SecurityContext : & kapiv1.PodSecurityContext {
@@ -104,7 +87,7 @@ func supGroupPod(fsGroup int64, supGroup int64) *kapiv1.Pod {
104
87
},
105
88
Containers : []kapiv1.Container {
106
89
{
107
- Name : "supplemental-groups" ,
90
+ Name : supplementalGroupsPod ,
108
91
Image : "openshift/origin-pod" ,
109
92
},
110
93
},
0 commit comments