Skip to content

Commit 5c69e96

Browse files
committed
add securityContext of ReadOnlyRootFilesystem to steps
Signed-off-by: Hasan Awad <[email protected]> test again Fix test
1 parent 4e46c27 commit 5c69e96

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

pkg/config/config.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ func NewDefaultConfig() *Config {
215215
"ALL",
216216
},
217217
},
218-
RunAsUser: nonRoot,
219-
RunAsGroup: nonRoot,
218+
RunAsUser: nonRoot,
219+
RunAsGroup: nonRoot,
220+
ReadOnlyRootFilesystem: ptr.To(true),
220221
},
221222
},
222223

@@ -231,6 +232,14 @@ func NewDefaultConfig() *Config {
231232
Name: "HOME",
232233
Value: "/shared-home",
233234
},
235+
{
236+
Name: "TRIVY_CACHE_DIR",
237+
Value: "/trivy-workspace/trivy-cache",
238+
},
239+
{
240+
Name: "TMPDIR",
241+
Value: "/trivy-workspace/tmp",
242+
},
234243
},
235244
// The image processing step runs after the build strategy steps where an arbitrary
236245
// user could have been used to write the result files for the image digest. The
@@ -241,6 +250,7 @@ func NewDefaultConfig() *Config {
241250
AllowPrivilegeEscalation: ptr.To(false),
242251
RunAsUser: root,
243252
RunAsGroup: root,
253+
ReadOnlyRootFilesystem: ptr.To(true),
244254
Capabilities: &corev1.Capabilities{
245255
Add: []corev1.Capability{
246256
"DAC_OVERRIDE",
@@ -274,8 +284,9 @@ func NewDefaultConfig() *Config {
274284
"ALL",
275285
},
276286
},
277-
RunAsUser: nonRoot,
278-
RunAsGroup: nonRoot,
287+
RunAsUser: nonRoot,
288+
RunAsGroup: nonRoot,
289+
ReadOnlyRootFilesystem: ptr.To(true),
279290
},
280291
},
281292

pkg/config/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ var _ = Describe("Config", func() {
243243
"ALL",
244244
},
245245
},
246-
RunAsUser: nonRoot,
247-
RunAsGroup: nonRoot,
246+
RunAsUser: nonRoot,
247+
RunAsGroup: nonRoot,
248+
ReadOnlyRootFilesystem: ptr.To(true),
248249
},
249250
}))
250251
})

pkg/reconciler/buildrun/resources/image_processing.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
containerNameImageProcessing = "image-processing"
2424
outputDirectoryMountPath = "/workspace/output-image"
2525
paramOutputDirectory = "output-directory"
26+
trivyVolumeName = "trivy-work-dir"
27+
trivyVolumeMountPath = "/trivy-workspace"
2628
)
2729

2830
type VulnerablilityScanParams struct {
@@ -160,6 +162,12 @@ func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, crea
160162
stepArgs = append(stepArgs, "--result-file-image-size", fmt.Sprintf("$(results.%s-%s.path)", prefixParamsResultsVolumes, imageSizeResult))
161163
stepArgs = append(stepArgs, "--result-file-image-vulnerabilities", fmt.Sprintf("$(results.%s-%s.path)", prefixParamsResultsVolumes, imageVulnerabilities))
162164

165+
taskRun.Spec.TaskSpec.Volumes = append(taskRun.Spec.TaskSpec.Volumes, core.Volume{
166+
Name: trivyVolumeName,
167+
VolumeSource: core.VolumeSource{
168+
EmptyDir: &core.EmptyDirVolumeSource{},
169+
},
170+
})
163171
// add the push step
164172

165173
// initialize the step from the template and the build-specific arguments
@@ -173,8 +181,13 @@ func SetupImageProcessing(taskRun *pipelineapi.TaskRun, cfg *config.Config, crea
173181
ComputeResources: cfg.ImageProcessingContainerTemplate.Resources,
174182
SecurityContext: cfg.ImageProcessingContainerTemplate.SecurityContext,
175183
WorkingDir: cfg.ImageProcessingContainerTemplate.WorkingDir,
184+
VolumeMounts: []core.VolumeMount{
185+
{
186+
Name: trivyVolumeName,
187+
MountPath: trivyVolumeMountPath,
188+
},
189+
},
176190
}
177-
178191
if volumeAdded {
179192
imageProcessingStep.VolumeMounts = append(imageProcessingStep.VolumeMounts, core.VolumeMount{
180193
Name: prefixedOutputDirectory,

pkg/reconciler/buildrun/resources/taskrun_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ var _ = Describe("GenerateTaskrun", func() {
122122
})
123123

124124
It("should ensure top level volumes are populated", func() {
125-
Expect(len(got.Volumes)).To(Equal(1))
125+
Expect(len(got.Volumes)).To(Equal(2))
126126
})
127127

128128
It("should contain the shipwright system parameters", func() {

0 commit comments

Comments
 (0)