Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

feat(plugins/k8s): add security_context option for on-demand runners pt2 #4346

Merged
merged 5 commits into from
Dec 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/4346.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
plugins/k8s: Add `security_context` to the TaskLauncherConfig (on-demand runner configuration)
```
1 change: 1 addition & 0 deletions builtin/k8s/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,7 @@ type Container struct {
// PodSecurityContext describes the security config for the Pod
type PodSecurityContext struct {
RunAsUser *int64 `hcl:"run_as_user"`
RunAsGroup *int64 `hcl:"run_as_group"`
RunAsNonRoot *bool `hcl:"run_as_non_root"`
FsGroup *int64 `hcl:"fs_group"`
}
Expand Down
15 changes: 15 additions & 0 deletions builtin/k8s/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ type TaskLauncherConfig struct {
// wordy because it's only for the WatchTask timing out waiting for the pod
// its watching to start up before it attempts to stream its logs.
WatchTaskStartupTimeoutSeconds int `hcl:"watchtask_startup_timeout_seconds,optional"`

// The PodSecurityContext to apply to the pod
SecurityContext *PodSecurityContext `hcl:"security_context,block"`
}

func (p *TaskLauncher) Documentation() (*docs.Documentation, error) {
Expand Down Expand Up @@ -379,6 +382,17 @@ func (p *TaskLauncher) StartTask(
}
}

var securityContext *corev1.PodSecurityContext = nil
podSc := p.config.SecurityContext
if podSc != nil {
securityContext = &corev1.PodSecurityContext{
RunAsUser: podSc.RunAsUser,
RunAsGroup: podSc.RunAsGroup,
RunAsNonRoot: podSc.RunAsNonRoot,
FSGroup: podSc.FsGroup,
}
}

resourceRequirements := corev1.ResourceRequirements{
Limits: resourceLimits,
Requests: resourceRequests,
Expand Down Expand Up @@ -428,6 +442,7 @@ func (p *TaskLauncher) StartTask(
Containers: []corev1.Container{container},
ImagePullSecrets: pullSecrets,
RestartPolicy: corev1.RestartPolicyOnFailure,
SecurityContext: securityContext,
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions embedJson/gen/platform-kubernetes.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,17 @@
"Category": false,
"SubFields": null
},
{
"Field": "run_as_group",
"Type": "int64",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "run_as_non_root",
"Type": "bool",
Expand Down
11 changes: 11 additions & 0 deletions embedJson/gen/task-kubernetes.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@
"EnvVar": "",
"Category": false,
"SubFields": null
},
{
"Field": "security_context",
"Type": "k8s.PodSecurityContext",
"Synopsis": "",
"Summary": "",
"Optional": false,
"Default": "",
"EnvVar": "",
"Category": false,
"SubFields": null
}
],
"type": "task",
Expand Down
4 changes: 4 additions & 0 deletions website/content/partials/components/platform-kubernetes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ A special supplemental group that applies to all containers in a pod.

- Type: **int64**

###### pod.security_context.run_as_group

- Type: **int64**

###### pod.security_context.run_as_non_root

Indicates that the container must run as a non-root user.
Expand Down
4 changes: 4 additions & 0 deletions website/content/partials/components/task-kubernetes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Memory resource request to be added to the task container.

- Type: **k8s.ResourceConfig**

#### security_context

- Type: **k8s.PodSecurityContext**

### Optional Parameters

These parameters are used in the [`use` stanza](/waypoint/docs/waypoint-hcl/use) for this plugin.
Expand Down