Skip to content

Commit 3999ec6

Browse files
authored
Merge pull request #37 from olhado/ebpf-enhancements
Backwards incompatible change: Changed capabilities definition to yaml list
2 parents 31f4f78 + e0ef39a commit 3999ec6

File tree

8 files changed

+91
-10
lines changed

8 files changed

+91
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The following kubernetes objects are created when the chart is installed:
4848
| apiReader.tolerations | list | `[]` | |
4949
| apiReader.podAnnotations | string | {} | |
5050
| apiReader.priorityClassName | string | `""` | Optionally set the priority class name for the daemonset pods. Note that priority classes are not created via this helm chart. Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ |
51-
| capabilities | string | `"[\"AUDIT_CONTROL\", \"SYS_ADMIN\", \"SYS_PTRACE\"]\n"` | Docker capabilites required for the proper operation of the agent |
51+
| capabilities | list | `["AUDIT_CONTROL", "SYS_ADMIN", "SYS_PTRACE", "SYS_NICE"]` | Docker capabilites required for the proper operation of the agent |
5252
| customDaemonsetCmd | object | `{}` | Uncomment the `command` and `args` sub-attributes, and define them as desired to run custom commands in the daemonset. |
5353
| daemonset.additionalRuntimeConfig | string | `"log.level info"` | |
5454
| daemonset.affinity | object | `{}` | |
@@ -57,6 +57,7 @@ The following kubernetes objects are created when the chart is installed:
5757
| daemonset.customTsAuditdConfig | string | `""` | |
5858
| daemonset.enableContainerd | bool | `unset` | Configures the daemonset agents to listen to the containerd daemon socket. **By default in agent 2.4.0+, the agent detects if containerd is running at startup** |
5959
| daemonset.enableDocker | bool | `unset` | Configures the daemonset agents to listen to the docker daemon socket. **By default in agent 2.4.0+, the agent detects if docker is running at startup** |
60+
| daemonset.enableLowPowerMode | bool | false | Configures the daemonset agents to perform better in tightly-resourced environments. The agent trades some telemetry reporting for reduced CPU and memory consumption. Ref: https://threatstack.zendesk.com/hc/en-us/articles/360016132692-Threat-Stack-Kubernetes-Deployment |
6061
| daemonset.nodeSelector | object | `{}` | |
6162
| daemonset.podAnnotations."container.apparmor.security.beta.kubernetes.io/threatstack-agent" | string | `"unconfined"` | |
6263
| daemonset.priorityClassName | string | `""` | Optionally set the priority class name for the daemonset pods. Note that priority classes are not created via this helm chart. Ref: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/ |

templates/_helpers.tpl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,35 @@ Create chart name and version as used by the chart label.
3131
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
3232
{{- end -}}
3333

34+
{{/*
35+
Return capabilities required for daemonset agent pods
36+
*/}}
37+
{{- define "threatstack-agent.daemonset-capabilities" -}}
38+
{{- $ebpf_caps := list "SYS_RESOURCE" "IPC_LOCK" -}}
39+
{{- if .Values.ebpfEnabled -}}
40+
{{- $cap_list := concat .Values.capabilities $ebpf_caps -}}
41+
{{- range $cap_list -}}"{{- . -}}", {{ end -}}
42+
{{- else -}}
43+
{{- range .Values.capabilities -}}"{{- . -}}", {{ end -}}
44+
{{- end -}}
45+
{{- end -}}
46+
47+
{{/*
48+
Return capabilities required for api-reader pod
49+
*/}}
50+
{{- define "threatstack-agent.apireader-capabilities" -}}
51+
{{- range .Values.capabilities -}}"{{- . -}}", {{ end -}}
52+
{{- end -}}
53+
54+
{{/*
55+
Return eBPF configuration required if enabled
56+
*/}}
57+
{{- define "threatstack-agent.daemonset-ebpf-config" -}}
58+
{{- if .Values.ebpfEnabled -}}
59+
{{- "enable_bpf_sensors 1" -}}
60+
{{- end -}}
61+
{{- end -}}
62+
3463
{{/*
3564
Return runtime config if docker is disabled
3665
*/}}
@@ -58,3 +87,16 @@ Return runtime config if containerd is disabled
5887
{{- end -}}
5988
{{- end -}}
6089
{{- end -}}
90+
91+
{{/*
92+
Return low-power config if setting is enabled
93+
*/}}
94+
{{- define "threatstack-agent.daemonset-lowpower-config" -}}
95+
{{- if kindIs "invalid" .Values.daemonset.enableLowPowerMode -}}
96+
{{- else -}}
97+
{{- if eq .Values.daemonset.enableLowPowerMode false -}}
98+
{{- else -}}
99+
{{- default "--low-power=true" -}}
100+
{{- end -}}
101+
{{- end -}}
102+
{{- end -}}

templates/configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ metadata:
88
app.kubernetes.io/instance: {{ .Release.Name }}
99
app.kubernetes.io/managed-by: {{ .Release.Service }}
1010
data:
11-
config-args: {{ include "threatstack-agent.docker-config" . }} {{ include "threatstack-agent.containerd-config" . }} {{ .Values.daemonset.additionalRuntimeConfig}}
11+
config-args: {{ include "threatstack-agent.docker-config" . }} {{ include "threatstack-agent.containerd-config" . }} {{ include "threatstack-agent.daemonset-ebpf-config" . }} {{ .Values.daemonset.additionalRuntimeConfig}}
1212
kubernetes-api-config-args: enable_kubes_master 1 {{ .Values.apiReader.additionalRuntimeConfig }}
1313
{{- if .Values.daemonset.customAuditRules }}
1414
custom-audit-rules-content: {{ toYaml .Values.daemonset.customAuditRules | indent 4 }}

templates/daemonset.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ spec:
110110
securityContext:
111111
{{- toYaml .Values.daemonset.securityContext | nindent 10 }}
112112
capabilities:
113-
add: {{ .Values.capabilities | trim }}
113+
add: [{{ include "threatstack-agent.daemonset-capabilities" . | trimSuffix ", " }}]
114114
{{- if .Values.daemonset.resources }}
115115
resources:
116116
{{ toYaml .Values.daemonset.resources | trim | indent 10 }}
@@ -140,6 +140,14 @@ spec:
140140
- name: custom-luafilter-config
141141
mountPath: /opt/threatstack/etc/tsauditd-custom.lua
142142
subPath: tsauditd-custom.lua
143+
{{- end }}
144+
{{- if .Values.ebpfEnabled }}
145+
- name: kernel-debug
146+
mountPath: /sys/kernel/debug
147+
- name: cgroup
148+
mountPath: /sys/fs/cgroup
149+
- name: bpf
150+
mountPath: /sys/fs/bpf
143151
{{- end }}
144152
volumes:
145153
- hostPath:
@@ -168,4 +176,15 @@ spec:
168176
items:
169177
- key: custom-luafilter-content
170178
path: tsauditd-custom.lua
179+
{{- end }}
180+
{{- if .Values.ebpfEnabled }}
181+
- hostPath:
182+
path: /sys/kernel/debug
183+
name: kernel-debug
184+
- hostPath:
185+
path: /sys/fs/cgroup
186+
name: cgroup
187+
- hostPath:
188+
path: /sys/fs/bpf
189+
name: bpf
171190
{{- end }}

templates/deployment-api-reader.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ spec:
9999
securityContext:
100100
{{- toYaml .Values.apiReader.securityContext | nindent 10 }}
101101
capabilities:
102-
add: {{ .Values.capabilities | trim }}
102+
add: [{{ include "threatstack-agent.apireader-capabilities" . | trimSuffix ", " }}]
103103
{{- if .Values.apiReader.resources }}
104104
resources:
105105
{{ toYaml .Values.apiReader.resources | trim | indent 10 }}

templates/pod-security-policy.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ spec:
1919
readOnly: false
2020
- pathPrefix: "/run/containerd/containerd.sock"
2121
readOnly: false
22+
{{- if .Values.ebpfEnabled }}
23+
- pathPrefix: "/sys/kernel/debug"
24+
readOnly: false
25+
- pathPrefix: "/sys/fs/cgroup"
26+
readOnly: false
27+
- pathPrefix: "/sys/fs/bpf"
28+
readOnly: false
29+
{{- end }}
2230
hostNetwork: true
2331
hostPID: true
2432
seLinux:

templates/secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ metadata:
1010
app.kubernetes.io/managed-by: {{ .Release.Service }}
1111
type: Opaque
1212
stringData:
13-
ts-setup-args: "--deploy-key {{ .Values.agentDeployKey }} --ruleset '{{ .Values.rulesets }}' {{ .Values.additionalSetupConfig }}"
13+
ts-setup-args: "--deploy-key {{ .Values.agentDeployKey }} --ruleset '{{ .Values.rulesets }}' {{ include "threatstack-agent.daemonset-lowpower-config" . }} {{ .Values.additionalSetupConfig }}"
1414
{{- end -}}

values.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ rbac:
4646
#
4747
# rulesets :: Define what rules will be applied to the agent by default
4848
# additionalSetupConfig :: Additional parameters passed to the backend during initial agent registration
49-
# additionalConfig :: Additional parameters to configure the running agent
5049
# capabilities :: Docker capabilites required for the proper operation of the agent
51-
capabilities: |
52-
["AUDIT_CONTROL", "SYS_ADMIN", "SYS_PTRACE", "SYS_NICE"]
50+
rulesets: "Base Rule Set, Docker Rule Set, Kubernetes Rule Set"
51+
additionalSetupConfig: ""
52+
capabilities:
53+
- AUDIT_CONTROL
54+
- SYS_ADMIN
55+
- SYS_PTRACE
56+
- SYS_NICE
5357

5458
#####
5559
# WARNING!
@@ -62,8 +66,6 @@ capabilities: |
6266
#####
6367
agentDeployKey: ""
6468

65-
rulesets: "Base Rule Set, Docker Rule Set, Kubernetes Rule Set"
66-
additionalSetupConfig: ""
6769

6870
#####
6971
#
@@ -167,6 +169,15 @@ daemonset:
167169
# enableDocker: false
168170
# enableContainerd: false
169171

172+
# Enable low-power mode
173+
# Configures the daemonset agents to perform better in
174+
# tightly-resourced environments. The agent trades some telemetry
175+
# reporting for reduced CPU and memory consumption.
176+
#
177+
# Ref: https://threatstack.zendesk.com/hc/en-us/articles/360016132692-Threat-Stack-Kubernetes-Deployment
178+
#
179+
enableLowPowerMode: true
180+
170181
additionalRuntimeConfig: "log.level info"
171182
# Override the agent's liveness probe logic from the default:
172183
# In case of issues with the probe, you can disable it with the

0 commit comments

Comments
 (0)