-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Copy pathrun_fs_verification.go
150 lines (131 loc) · 3.45 KB
/
run_fs_verification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package builds
import (
"fmt"
"strings"
g "github.com/onsi/ginkgo/v2"
o "github.com/onsi/gomega"
admissionapi "k8s.io/pod-security-admission/api"
exutil "github.com/openshift/origin/test/extended/util"
"github.com/openshift/origin/test/extended/util/image"
)
var _ = g.Describe("[sig-builds][Feature:Builds] verify /run filesystem contents", func() {
defer g.GinkgoRecover()
var (
oc = exutil.NewCLIWithPodSecurityLevel("verify-run-fs", admissionapi.LevelBaseline)
testVerityRunFSWriteableBuildConfigYaml = fmt.Sprintf(`
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: verify-run-fs
spec:
runPolicy: Serial
source:
type: Dockerfile
dockerfile: |-
FROM %s
RUN chmod -R uga+rwx /run/secrets
USER 1001
strategy:
dockerStrategy:
env:
- name: BUILD_LOGLEVEL
value: "10"
imageOptimizationPolicy: SkipLayers
type: Docker
`, image.LimitedShellImage())
testVerifyRunFSContentsBuildConfigYaml = fmt.Sprintf(`
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: verify-run-fs
spec:
runPolicy: Serial
source:
type: Dockerfile
dockerfile: |-
FROM %s
RUN ls -R /run/secrets
USER 1001
strategy:
dockerStrategy:
env:
- name: BUILD_LOGLEVEL
value: "10"
imageOptimizationPolicy: SkipLayers
type: Docker
`, image.LimitedShellImage())
lsRSlashRun = `
/run/secrets:
rhsm
/run/secrets/rhsm:
ca
/run/secrets/rhsm/ca:
redhat-entitlement-authority.pem
redhat-uep.pem
`
lsRSlashRunFIPS = `
/run/secrets:
system-fips
`
lsRSlashRunOKD = `
/run/secrets:
`
lsRSlashRunRhel7 = `
/run/secrets:
rhsm
/run/secrets/rhsm:
ca
logging.conf
rhsm.conf
syspurpose
/run/secrets/rhsm/ca:
redhat-uep.pem
/run/secrets/rhsm/syspurpose:
valid_fields.json
`
)
g.Context("", func() {
g.BeforeEach(func() {
exutil.PreTestDump()
})
g.AfterEach(func() {
if g.CurrentSpecReport().Failed() {
exutil.DumpPodStates(oc)
exutil.DumpPodLogsStartingWith("verify-run-fs", oc)
}
})
g.Describe("do not have unexpected content", func() {
g.It("using a simple Docker Strategy Build [apigroup:build.openshift.io]", func() {
g.By("calling oc create with yaml")
err := oc.Run("create").Args("-f", "-").InputString(testVerifyRunFSContentsBuildConfigYaml).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("start and wait for build")
br, err := exutil.StartBuildAndWait(oc, "verify-run-fs")
o.Expect(err).NotTo(o.HaveOccurred())
br.AssertSuccess()
g.By("check build logs for ls -R /run/secrets")
logs, err := br.LogsNoTimestamp()
o.Expect(err).NotTo(o.HaveOccurred())
hasRightListing := false
if strings.Contains(logs, lsRSlashRun) ||
strings.Contains(logs, lsRSlashRunFIPS) ||
strings.Contains(logs, lsRSlashRunOKD) ||
strings.Contains(logs, lsRSlashRunRhel7) {
hasRightListing = true
}
o.Expect(hasRightListing).To(o.BeTrue())
})
})
g.Describe("are writeable", func() {
g.It("using a simple Docker Strategy Build [apigroup:build.openshift.io]", func() {
g.By("calling oc create with yaml")
err := oc.Run("create").Args("-f", "-").InputString(testVerityRunFSWriteableBuildConfigYaml).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("start and wait for build")
br, err := exutil.StartBuildAndWait(oc, "verify-run-fs")
o.Expect(err).NotTo(o.HaveOccurred())
br.AssertSuccess()
})
})
})
})