Skip to content

Commit f2a47df

Browse files
Merge pull request #16408 from runcom/fix-test-no-docker
Automatic merge from submit-queue. test: extended: avoid using docker directly This test fails when running against CRI-O (https://ci.openshift.redhat.com/jenkins/job/test_branch_origin_extended_conformance_crio/40/console) because it uses docker. Modify the test to check groups in container instead. ref #16403 @smarterclayton PTAL Signed-off-by: Antonio Murdaca <[email protected]>
2 parents 344cf64 + 356a379 commit f2a47df

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

test/extended/security/supplemental_groups.go

+21-38
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,33 @@ import (
88
g "github.com/onsi/ginkgo"
99
o "github.com/onsi/gomega"
1010

11+
exutil "github.com/openshift/origin/test/extended/util"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
1314
e2e "k8s.io/kubernetes/test/e2e/framework"
15+
)
1416

15-
testutil "github.com/openshift/origin/test/util"
17+
const (
18+
supplementalGroupsPod = "supplemental-groups"
1619
)
1720

1821
var _ = g.Describe("[security] supplemental groups", func() {
1922
defer g.GinkgoRecover()
2023

2124
var (
22-
f = e2e.NewDefaultFramework("security-supgroups")
25+
oc = exutil.NewCLI("sup-groups", exutil.KubeConfigPath())
26+
f = oc.KubeFramework()
2327
)
2428

2529
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() {
3031

3132
fsGroup := int64(1111)
3233
supGroup := int64(2222)
3334

35+
_, err := oc.AsAdmin().Run("adm").Args("policy", "add-scc-to-user", "anyuid", oc.Username()).Output()
36+
o.Expect(err).NotTo(o.HaveOccurred())
37+
3438
// create a pod that is requesting supplemental groups. We request specific sup groups
3539
// so that we can check for the exact values later and not rely on SCC allocation.
3640
g.By("creating a pod that requests supplemental groups")
@@ -52,50 +56,29 @@ var _ = g.Describe("[security] supplemental groups", func() {
5256
err = f.WaitForPodRunning(submittedPod.Name)
5357
o.Expect(err).NotTo(o.HaveOccurred())
5458

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+
}
6664
o.Expect(err).NotTo(o.HaveOccurred())
6765

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))
7368
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))
7670
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))
7872
})
7973

8074
})
8175
})
8276

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-
9477
// supGroupPod generates the pod requesting supplemental groups.
9578
func supGroupPod(fsGroup int64, supGroup int64) *kapiv1.Pod {
9679
return &kapiv1.Pod{
9780
ObjectMeta: metav1.ObjectMeta{
98-
Name: "supplemental-groups",
81+
Name: supplementalGroupsPod,
9982
},
10083
Spec: kapiv1.PodSpec{
10184
SecurityContext: &kapiv1.PodSecurityContext{
@@ -104,7 +87,7 @@ func supGroupPod(fsGroup int64, supGroup int64) *kapiv1.Pod {
10487
},
10588
Containers: []kapiv1.Container{
10689
{
107-
Name: "supplemental-groups",
90+
Name: supplementalGroupsPod,
10891
Image: "openshift/origin-pod",
10992
},
11093
},

0 commit comments

Comments
 (0)