Skip to content

Commit

Permalink
feat: set the seccomp profile for artifact gc to runtimedefault
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Hankeln <lukashankeln@googlemail.com>
  • Loading branch information
lukashankeln committed May 11, 2024
1 parent a4fc318 commit c2a5458
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
6 changes: 4 additions & 2 deletions test/e2e/executor_plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ func (s *ExecutorPluginsSuite) TestTemplateExecutor() {
spec := pod.Spec
assert.Equal(t, pointer.Bool(false), spec.AutomountServiceAccountToken)
assert.Equal(t, &apiv1.PodSecurityContext{
RunAsUser: pointer.Int64(8737),
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
RunAsNonRoot: pointer.Bool(true),
SeccompProfile: &v1.SeccompProfile{Type: "RuntimeDefault"}

Check failure on line 44 in test/e2e/executor_plugins_test.go

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected newline in composite literal; possibly missing comma or }

Check failure on line 44 in test/e2e/executor_plugins_test.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' before newline in composite literal (typecheck)

Check failure on line 44 in test/e2e/executor_plugins_test.go

View workflow job for this annotation

GitHub Actions / E2E Tests (test-plugins, plugins)

missing ',' before newline in composite literal
}, spec.SecurityContext)
if assert.Len(t, spec.Volumes, 4) {
assert.Contains(t, spec.Volumes[0].Name, "kube-api-access-")
Expand Down Expand Up @@ -72,6 +73,7 @@ func (s *ExecutorPluginsSuite) TestTemplateExecutor() {
AllowPrivilegeEscalation: pointer.Bool(false),
ReadOnlyRootFilesystem: pointer.Bool(true),
Capabilities: &apiv1.Capabilities{Drop: []apiv1.Capability{"ALL"}},
SeccompProfile: &v1.SeccompProfile{Type: "RuntimeDefault"}

Check failure on line 76 in test/e2e/executor_plugins_test.go

View workflow job for this annotation

GitHub Actions / Lint

syntax error: unexpected newline in composite literal; possibly missing comma or } (typecheck)

Check failure on line 76 in test/e2e/executor_plugins_test.go

View workflow job for this annotation

GitHub Actions / Lint

missing ',' before newline in composite literal (typecheck)
}, agent.SecurityContext)
}
}
Expand Down
26 changes: 26 additions & 0 deletions workflow/common/security_context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package common

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
)

func MinimalCtrSC() *corev1.SecurityContext {
return &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}},
Privileged: pointer.Bool(false),
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
SeccompProfile: &corev1.SeccompProfile{Type: "RuntimeDefault"},
}
}

func MinimalPodSC() *corev1.PodSecurityContext {
return &corev1.PodSecurityContext{
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
SeccompProfile: &corev1.SeccompProfile{Type: "RuntimeDefault"},
}
}
19 changes: 4 additions & 15 deletions workflow/controller/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,7 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro
Image: woc.controller.executorImage(),
ImagePullPolicy: woc.controller.executorImagePullPolicy(),
Env: envVars,
SecurityContext: &apiv1.SecurityContext{
Capabilities: &apiv1.Capabilities{
Drop: []apiv1.Capability{"ALL"},
},
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
SecurityContext: common.MinimalCtrSC(),
Resources: apiv1.ResourceRequirements{
Requests: map[apiv1.ResourceName]resource.Quantity{
"cpu": resource.MustParse("10m"),
Expand Down Expand Up @@ -221,12 +213,9 @@ func (woc *wfOperationCtx) createAgentPod(ctx context.Context) (*apiv1.Pod, erro
},
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyOnFailure,
ImagePullSecrets: woc.execWf.Spec.ImagePullSecrets,
SecurityContext: &apiv1.PodSecurityContext{
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
},
RestartPolicy: apiv1.RestartPolicyOnFailure,
ImagePullSecrets: woc.execWf.Spec.ImagePullSecrets,
SecurityContext: common.MinimalPodSC(),
ServiceAccountName: serviceAccountName,
AutomountServiceAccountToken: pointer.Bool(false),
Volumes: podVolumes,
Expand Down
12 changes: 3 additions & 9 deletions workflow/controller/artifact_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ func (woc *wfOperationCtx) createArtifactGCPod(ctx context.Context, strategy wfv
OwnerReferences: ownerReferences,
},
Spec: corev1.PodSpec{
Volumes: volumes,
Volumes: volumes,
SecurityContext: common.MinimalPodSC(),
Containers: []corev1.Container{
{
Name: common.MainContainerName,
Expand All @@ -444,14 +445,7 @@ func (woc *wfOperationCtx) createArtifactGCPod(ctx context.Context, strategy wfv
// if this pod is breached by an attacker we:
// * prevent installation of any new packages
// * modification of the file-system
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{Drop: []corev1.Capability{"ALL"}},
Privileged: pointer.Bool(false),
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
SecurityContext: common.MinimalCtrSC(),
// if this pod is breached by an attacker these limits prevent excessive CPU and memory usage
Resources: corev1.ResourceRequirements{
Limits: map[corev1.ResourceName]resource.Quantity{
Expand Down
11 changes: 3 additions & 8 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,9 @@ func (woc *wfOperationCtx) newExecContainer(name string, tmpl *wfv1.Template) *a
}
// lock down resource pods by default
if tmpl.GetType() == wfv1.TemplateTypeResource && exec.SecurityContext == nil {
exec.SecurityContext = &apiv1.SecurityContext{
Capabilities: &apiv1.Capabilities{
Drop: []apiv1.Capability{"ALL"},
},
RunAsNonRoot: pointer.Bool(true),
RunAsUser: pointer.Int64(8737),
AllowPrivilegeEscalation: pointer.Bool(false),
}
exec.SecurityContext = common.MinimalCtrSC()
// TODO: always set RO FS once #10787 is fixed
exec.SecurityContext.ReadOnlyRootFilesystem = nil
if exec.Name != common.InitContainerName && exec.Name != common.WaitContainerName {
exec.SecurityContext.ReadOnlyRootFilesystem = pointer.Bool(true)
}
Expand Down

0 comments on commit c2a5458

Please sign in to comment.