Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(executor): set seccomp profile to runtimedefault #12984

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions test/e2e/executor_plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"

Expand Down Expand Up @@ -39,8 +40,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"},
}, spec.SecurityContext)
if assert.Len(t, spec.Volumes, 4) {
assert.Contains(t, spec.Volumes[0].Name, "kube-api-access-")
Expand Down Expand Up @@ -71,7 +73,9 @@ func (s *ExecutorPluginsSuite) TestTemplateExecutor() {
RunAsNonRoot: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
ReadOnlyRootFilesystem: pointer.Bool(true),
Privileged: pointer.Bool(false),
Capabilities: &apiv1.Capabilities{Drop: []apiv1.Capability{"ALL"}},
SeccompProfile: &v1.SeccompProfile{Type: "RuntimeDefault"},
}, 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()
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
// 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