Skip to content

Commit 8f06eb8

Browse files
authored
updating PodSecurityContext and SecurityContext for scorecard pod/containers (#6294)
Signed-off-by: Adam D. Cornett <adc@redhat.com>
1 parent 5cbdad9 commit 8f06eb8

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

internal/scorecard/scorecard.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,29 @@ func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfigurat
224224
// Create a Pod to run the test
225225
podDef := getPodDefinition(r.configMapName, test, r)
226226
if podSec {
227-
secCtx := v1.PodSecurityContext{}
228-
secCtx.RunAsNonRoot = &podSec
229-
secCtx.SeccompProfile = &v1.SeccompProfile{
227+
// creating a pod security context to support running in default namespace
228+
podSecCtx := v1.PodSecurityContext{}
229+
podSecCtx.RunAsNonRoot = &podSec
230+
podSecCtx.RunAsUser = &[]int64{1000}[0]
231+
podSecCtx.RunAsGroup = &[]int64{1000}[0]
232+
podSecCtx.SeccompProfile = &v1.SeccompProfile{
230233
Type: v1.SeccompProfileTypeRuntimeDefault,
231234
}
232235

233-
podDef.Spec.SecurityContext = &secCtx
236+
// creating a security context to be used by all containers in the pod
237+
secCtx := v1.SecurityContext{}
238+
secCtx.RunAsNonRoot = &podSec
239+
secCtx.AllowPrivilegeEscalation = &[]bool{false}[0]
240+
secCtx.Capabilities = &v1.Capabilities{
241+
Drop: []v1.Capability{
242+
"ALL",
243+
},
244+
}
245+
246+
podDef.Spec.SecurityContext = &podSecCtx
247+
248+
podDef.Spec.Containers[0].SecurityContext = &secCtx
249+
podDef.Spec.InitContainers[0].SecurityContext = &secCtx
234250
}
235251

236252
if test.Storage.Spec.MountPath.Path != "" {

0 commit comments

Comments
 (0)