Skip to content

Commit c7d9fb8

Browse files
Merge pull request #14891 from bparees/root_builds
pass an internal pod object to SCC admission control so it works
2 parents 080fe59 + d186041 commit c7d9fb8

File tree

4 files changed

+108
-7
lines changed

4 files changed

+108
-7
lines changed

pkg/build/controller/strategy/sti.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,27 @@ func (bs *SourceBuildStrategy) CreateBuildPod(build *buildapi.Build) (*v1.Pod, e
112112
func (bs *SourceBuildStrategy) canRunAsRoot(build *buildapi.Build) bool {
113113
var rootUser int64
114114
rootUser = 0
115-
pod := &v1.Pod{
115+
pod := &kapi.Pod{
116116
ObjectMeta: metav1.ObjectMeta{
117-
Name: buildapi.GetBuildPodName(build),
117+
Name: buildapi.GetBuildPodName(build) + "-admissioncheck",
118118
Namespace: build.Namespace,
119119
},
120-
Spec: v1.PodSpec{
120+
Spec: kapi.PodSpec{
121121
ServiceAccountName: build.Spec.ServiceAccount,
122-
Containers: []v1.Container{
122+
Containers: []kapi.Container{
123123
{
124124
Name: "sti-build",
125125
Image: bs.Image,
126-
SecurityContext: &v1.SecurityContext{
126+
SecurityContext: &kapi.SecurityContext{
127127
RunAsUser: &rootUser,
128128
},
129129
},
130130
},
131-
RestartPolicy: v1.RestartPolicyNever,
131+
RestartPolicy: kapi.RestartPolicyNever,
132132
},
133133
}
134134
userInfo := serviceaccount.UserInfo(build.Namespace, build.Spec.ServiceAccount, "")
135-
attrs := admission.NewAttributesRecord(pod, pod, kapi.Kind("Pod").WithVersion(""), pod.Namespace, pod.Name, kapi.Resource("pods").WithVersion(""), "", admission.Create, userInfo)
135+
attrs := admission.NewAttributesRecord(pod, nil, kapi.Kind("Pod").WithVersion(""), pod.Namespace, pod.Name, kapi.Resource("pods").WithVersion(""), "", admission.Create, userInfo)
136136
err := bs.AdmissionControl.Admit(attrs)
137137
if err != nil {
138138
glog.V(2).Infof("Admit for root user returned error: %v", err)

test/extended/builds/s2i_root.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package builds
2+
3+
import (
4+
"fmt"
5+
6+
g "github.com/onsi/ginkgo"
7+
o "github.com/onsi/gomega"
8+
9+
exutil "github.com/openshift/origin/test/extended/util"
10+
s2istatus "github.com/openshift/source-to-image/pkg/util/status"
11+
)
12+
13+
var _ = g.Describe("[builds][Conformance] s2i build with a root user image", func() {
14+
defer g.GinkgoRecover()
15+
16+
var (
17+
buildFixture = exutil.FixturePath("testdata", "s2i-build-root.yaml")
18+
oc = exutil.NewCLI("s2i-build-root", exutil.KubeConfigPath())
19+
)
20+
21+
g.JustBeforeEach(func() {
22+
g.By("waiting for builder service account")
23+
err := exutil.WaitForBuilderAccount(oc.AdminKubeClient().Core().ServiceAccounts(oc.Namespace()))
24+
o.Expect(err).NotTo(o.HaveOccurred())
25+
})
26+
27+
g.Describe("Building using an image with a root default user", func() {
28+
g.It("should fail the build immediately", func() {
29+
oc.SetOutputDir(exutil.TestContext.OutputDir)
30+
31+
g.By(fmt.Sprintf("calling oc create -f %q", buildFixture))
32+
err := oc.Run("create").Args("-f", buildFixture).Execute()
33+
o.Expect(err).NotTo(o.HaveOccurred())
34+
35+
g.By("starting a test build")
36+
// this uses the build-quota dir as the binary input source on purpose - we don't really care what we upload
37+
// to the build since it will fail before we ever consume the inputs.
38+
br, _ := exutil.StartBuildAndWait(oc, "s2i-build-root", "--from-dir", exutil.FixturePath("testdata", "build-quota"))
39+
br.AssertFailure()
40+
o.Expect(string(br.Build.Status.Reason)).To(o.Equal(string(s2istatus.ReasonPullBuilderImageFailed)))
41+
o.Expect(string(br.Build.Status.Message)).To(o.Equal(string(s2istatus.ReasonMessagePullBuilderImageFailed)))
42+
43+
})
44+
})
45+
})

test/extended/testdata/bindata.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
kind: BuildConfig
3+
apiVersion: v1
4+
metadata:
5+
name: s2i-build-root
6+
creationTimestamp:
7+
labels:
8+
name: s2i-build-root
9+
spec:
10+
source:
11+
binary:
12+
asFile: ''
13+
strategy:
14+
type: Source
15+
sourceStrategy:
16+
from:
17+
kind: DockerImage
18+
name: centos

0 commit comments

Comments
 (0)