Skip to content

Commit

Permalink
feat(agent): [SMAGENT-8138][SMAGENT-8501] add full securityContext to…
Browse files Browse the repository at this point in the history
… agent charts (#2102)

Update the agent charts so to include a full securityContext.
Beware of kubernetes/kubernetes#125012 affecting Windows kubelet.

Compared to #2017, just removed the "add: -ALL" part which was breaking some systems like ROKS and probably also Azure, which seemed unnecessary (probably redundant given we have privileged: true).
  • Loading branch information
iurly authored Jan 8, 2025
1 parent 1a8dc2d commit 3dfcf31
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ sources:
- https://app.sysdigcloud.com/#/settings/user
- https://github.com/draios/sysdig
type: application
version: 1.34.5
version: 1.34.6
4 changes: 4 additions & 0 deletions charts/agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,12 @@ annotations:
privileged: true
runAsNonRoot: false
runAsUser: 0
runAsGroup: 0
readOnlyRootFilesystem: false
allowPrivilegeEscalation: true
capabilities:
drop:
- ALL
{{- else }}
allowPrivilegeEscalation: false
seccompProfile:
Expand Down
10 changes: 10 additions & 0 deletions charts/agent/templates/daemonset-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ spec:
{{ toYaml .Values.global.image.pullSecrets | nindent 8 }}
{{- end }}
securityContext:
privileged: true
{{- if ( semverCompare ">= 1.31.0" (.Capabilities.KubeVersion.GitVersion )) }}
runAsNonRoot: false
runAsGroup: 0
{{- end }}
readOnlyRootFilesystem: false
allowPrivilegeEscalation: true
capabilities:
add:
- ALL
windowsOptions:
hostProcess: true
runAsUserName: "NT AUTHORITY\\SYSTEM"
Expand Down
4 changes: 4 additions & 0 deletions charts/agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ spec:
securityContext:
privileged: true
runAsNonRoot: false
runAsGroup: 0
runAsUser: 0
readOnlyRootFilesystem: false
allowPrivilegeEscalation: true
capabilities:
drop:
- ALL
resources:
{{- if (include "agent.gke.autopilot" .) }}
{{- $resources := merge .Values.slim.resources (dict "requests" (dict "ephemeral-storage" .Values.gke.ephemeralStorage))}}
Expand Down
4 changes: 4 additions & 0 deletions charts/agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ spec:
privileged: true
runAsNonRoot: false
runAsUser: 0
runAsGroup: 0
readOnlyRootFilesystem: false
allowPrivilegeEscalation: true
capabilities:
add:
- ALL
env:
- name: RUN_MODE
value: nodriver
Expand Down
3 changes: 3 additions & 0 deletions charts/agent/tests/readiness_probe_windows_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ kubernetesProvider:
tests:

- it: "Windows Agent Probes (agent < 1.3.0)"
capabilities:
majorVersion: 1
minorVersion: 31
set:
windows:
enabled: true
Expand Down
36 changes: 36 additions & 0 deletions charts/agent/tests/security_context_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ tests:
readOnlyRootFilesystem: false
runAsNonRoot: false
runAsUser: 0
runAsGroup: 0
capabilities:
drop:
- ALL

- it: Ensure the securityContext for a non-privileged agent contains the keys defined
set:
Expand Down Expand Up @@ -125,3 +129,35 @@ tests:
- SYS_TIME
- SYS_TTY_CONFIG
- WAKE_ALARM

- it: Ensure the securityContext contains the mandatory keys
asserts:
- isSubset:
path: spec.template.spec['initContainers','containers'][:].securityContext.capabilities
content:
drop:
- ALL
- exists:
path: spec.template.spec.initContainers[:].securityContext.runAsNonRoot
- exists:
path: spec.template.spec.containers[:].securityContext.runAsNonRoot
- exists:
path: spec.template.spec.initContainers[:].securityContext.runAsUser
- exists:
path: spec.template.spec.containers[:].securityContext.runAsUser
- exists:
path: spec.template.spec.initContainers[:].securityContext.runAsGroup
- exists:
path: spec.template.spec.containers[:].securityContext.runAsGroup
- exists:
path: spec.template.spec.initContainers[:].securityContext.privileged
- exists:
path: spec.template.spec.containers[:].securityContext.privileged
- exists:
path: spec.template.spec.initContainers[:].securityContext.allowPrivilegeEscalation
- exists:
path: spec.template.spec.containers[:].securityContext.allowPrivilegeEscalation
- exists:
path: spec.template.spec.initContainers[:].securityContext.readOnlyRootFilesystem
- exists:
path: spec.template.spec.containers[:].securityContext.readOnlyRootFilesystem
4 changes: 2 additions & 2 deletions charts/sysdig-deploy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: sysdig-deploy
description: A chart with various Sysdig components for Kubernetes
type: application
version: 1.73.0
version: 1.73.1
maintainers:
- name: AlbertoBarba
email: alberto.barba@sysdig.com
Expand All @@ -26,7 +26,7 @@ dependencies:
- name: agent
# repository: https://charts.sysdig.com
repository: file://../agent
version: ~1.34.5
version: ~1.34.6
alias: agent
condition: agent.enabled
- name: common
Expand Down

0 comments on commit 3dfcf31

Please sign in to comment.