Skip to content

Commit fefbd3e

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

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

cmd/git/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
typeUndef credentialType = iota
2828
typePrivateKey
2929
typeUsernamePassword
30+
writeableDir = "/writeable-workspace"
3031
)
3132

3233
var useNoTagsFlag = false
@@ -309,7 +310,7 @@ func clone(ctx context.Context) error {
309310
return err
310311
}
311312

312-
sshPrivateKeyFile, err := os.CreateTemp(os.TempDir(), "ssh-private-key")
313+
sshPrivateKeyFile, err := os.CreateTemp(writeableDir, "ssh-private-key")
313314
if err != nil {
314315
return err
315316
}
@@ -393,7 +394,7 @@ func clone(ctx context.Context) error {
393394

394395
repoURL.User = url.UserPassword(string(username), string(password))
395396

396-
credHelperFile, err := os.CreateTemp(os.TempDir(), "cred-helper-file")
397+
credHelperFile, err := os.CreateTemp(writeableDir, "cred-helper-file")
397398
if err != nil {
398399
return err
399400
}

pkg/config/config.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ func NewDefaultConfig() *Config {
187187
"ALL",
188188
},
189189
},
190-
RunAsUser: nonRoot,
191-
RunAsGroup: nonRoot,
190+
RunAsUser: nonRoot,
191+
RunAsGroup: nonRoot,
192+
ReadOnlyRootFilesystem: ptr.To(true),
192193
},
193194
},
194195

@@ -215,8 +216,9 @@ func NewDefaultConfig() *Config {
215216
"ALL",
216217
},
217218
},
218-
RunAsUser: nonRoot,
219-
RunAsGroup: nonRoot,
219+
RunAsUser: nonRoot,
220+
RunAsGroup: nonRoot,
221+
ReadOnlyRootFilesystem: ptr.To(true),
220222
},
221223
},
222224

@@ -274,8 +276,9 @@ func NewDefaultConfig() *Config {
274276
"ALL",
275277
},
276278
},
277-
RunAsUser: nonRoot,
278-
RunAsGroup: nonRoot,
279+
RunAsUser: nonRoot,
280+
RunAsGroup: nonRoot,
281+
ReadOnlyRootFilesystem: ptr.To(true),
279282
},
280283
},
281284

pkg/config/config_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ var _ = Describe("Config", func() {
142142
"ALL",
143143
},
144144
},
145-
RunAsUser: nonRoot,
146-
RunAsGroup: nonRoot,
145+
RunAsUser: nonRoot,
146+
RunAsGroup: nonRoot,
147+
ReadOnlyRootFilesystem: ptr.To(true),
147148
},
148149
}))
149150
})
@@ -243,8 +244,9 @@ var _ = Describe("Config", func() {
243244
"ALL",
244245
},
245246
},
246-
RunAsUser: nonRoot,
247-
RunAsGroup: nonRoot,
247+
RunAsUser: nonRoot,
248+
RunAsGroup: nonRoot,
249+
ReadOnlyRootFilesystem: ptr.To(true),
248250
},
249251
}))
250252
})

pkg/reconciler/buildrun/resources/sources/git.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
commitSHAResult = "commit-sha"
2323
commitAuthorResult = "commit-author"
2424
branchName = "branch-name"
25+
workspaceSource = "source"
2526
)
2627

2728
// AppendGitStep appends the Git step and results and volume if needed to the TaskSpec
@@ -67,6 +68,13 @@ func AppendGitStep(
6768
ComputeResources: cfg.GitContainerTemplate.Resources,
6869
SecurityContext: cfg.GitContainerTemplate.SecurityContext,
6970
WorkingDir: cfg.GitContainerTemplate.WorkingDir,
71+
VolumeMounts: []corev1.VolumeMount{
72+
{
73+
Name: workspaceSource,
74+
MountPath: "/writeable-workspace",
75+
ReadOnly: false,
76+
},
77+
},
7078
}
7179

7280
// Check if a revision is defined

0 commit comments

Comments
 (0)