Skip to content

worker: Kubernetes Runtime Container SecurityContext #515

@cognifloyd

Description

@cognifloyd

Description

Add SecurityContext to containers in the kubernetes runtime as noted in this TODO:

https://github.com/go-vela/worker/blob/19081a02a335086f774e8a73f595e9efb873659d/runtime/kubernetes/container.go#L173

	// TODO: add SecurityContext options (runAsUser, runAsNonRoot, sysctls)

There are several settings that can be configured in SecurityContext, some of which can only be set on the whole Pod, others can only be set per-container, and others can be set in either context (container-level overriding pod-level).

Setting Type Pod Container Configure
Worker
w/ default
Step
override
(if worker allows)
Pipeline
override
(if worker allows)
Apply if
volumes
need it
allowPrivilegeEscalation boolean
implicitly toggled
by privileged
capabilities object
✔️ via CRD
- add, drop string arrays
fsGroup integer 💾
fsGroupChangePolicy string 💾
privileged boolean
✔️ allow list
of images
via opt/env

config exists
procMount string
readOnlyRootFilesystem boolean 💾
runAsGroup integer
runAsNonRoot boolean
✔️ pod-level only via CRD
runAsUser integer
config exists
(missing in k8s)
seLinuxOptions object
- level, role, type, user strings
seccompProfile object
- localhostProfile, type strings
supplementalGroups integer array 💾
sysctls object array
✔️ via CRD

ulimits exists

(but k8s can't do
per-step sysctls)
- name, value strings
windowsOptions object N/A N/A N/A
- gmsa*, hostProcess, runAsUserName mixed

Value

Allow using Vela in clusters where an admissions controller blocks the creation of pods unless SecurityContext requirements are met.
Make pipelines follow the principle of least-privileges: Like "privileged" only increase access if requested (and permitted).

Definition of Done

  • Each k8s worker can add global SecurityContext to all pipeline containers.
  • Different workers can have different settings (configurable somehow by the vela admin).
  • Maybe surface minimal override configuration for this in the pipeline yaml or in the repo settings.

Effort (Optional)

Adding the SecurityContext should be straight-forward.
But, how to configure that is not clear.

Impacted Personas (Optional)

Anyone who uses the kubernetes runtime and wants to apply SecurityContext settings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/workerIndicates a change to the workerfeatureIndicates a new feature

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions