Skip to content

Commit ce97f21

Browse files
committed
add logging to seccomp profile hash name and fallback warning message
1 parent d4e81de commit ce97f21

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

charts/datadog/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Return the seccomp profile filename for the host-profiler, scoped to the image r
301301
to avoid races when multiple host-profiler versions coexist on the same node.
302302
*/}}
303303
{{- define "host-profiler-seccomp-name" -}}
304-
host-profiler-{{ include "ddot-ebpf-image" . | sha256sum | trunc 8 }}
304+
host-profiler-{{ include "ddot-ebpf-image" . | sha256sum | trunc 8 }}{{- if .Values.datadog.hostProfiler.loggingSeccomp }}-logging{{- end }}
305305
{{- end -}}
306306

307307
{{/*

charts/datadog/templates/_host-profiler-init.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
{{- $dst := printf "/host%s/%s" .Values.datadog.hostProfiler.seccompRoot (include "host-profiler-seccomp-name" .) }}
77
command:
88
{{- if .Values.datadog.hostProfiler.loggingSeccomp }}
9-
# Prefer the logging profile, falling back to the default if the image predates it.
109
- sh
1110
- -c
12-
- if [ -f /etc/dd-host-profiler/logging-seccomp.json ]; then cp /etc/dd-host-profiler/logging-seccomp.json {{ $dst }}; else cp /etc/dd-host-profiler/seccomp.json {{ $dst }}; fi
11+
- "if [ -f /etc/dd-host-profiler/logging-seccomp.json ]; then cp /etc/dd-host-profiler/logging-seccomp.json {{ $dst }}; else echo 'WARNING: logging-seccomp.json not found in image, falling back to default seccomp profile'; cp /etc/dd-host-profiler/seccomp.json {{ $dst }}; fi"
1312
{{- else }}
1413
- cp
1514
- /etc/dd-host-profiler/seccomp.json

test/datadog/host_profiler_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,18 @@ func TestHostProfilerLoggingSeccomp(t *testing.T) {
138138
overrides := copyMap(hostProfilerBaseOverrides)
139139
overrides["datadog.hostProfiler.loggingSeccomp"] = "true"
140140
ds := renderHostProfilerDaemonSet(t, overrides)
141+
141142
initContainer, ok := getContainer(t, ds.Spec.Template.Spec.InitContainers, "host-profiler-seccomp-setup")
142143
require.True(t, ok)
143-
144-
// Prefer the logging profile, falling back to the default if the image predates it.
145144
cmd := strings.Join(initContainer.Command, " ")
146-
assert.Contains(t, cmd, "if [ -f /etc/dd-host-profiler/logging-seccomp.json ]",
147-
"init container should guard the logging profile copy; command: %v", initContainer.Command)
148145
assert.Contains(t, cmd, "cp /etc/dd-host-profiler/logging-seccomp.json")
149-
assert.Contains(t, cmd, "cp /etc/dd-host-profiler/seccomp.json", "should fall back to the default profile")
146+
assert.Contains(t, cmd, "cp /etc/dd-host-profiler/seccomp.json")
147+
assert.Contains(t, cmd, "WARNING: logging-seccomp.json not found in image, falling back to default seccomp profile")
148+
149+
hpContainer, ok := getContainer(t, ds.Spec.Template.Spec.Containers, "host-profiler")
150+
require.True(t, ok)
151+
require.NotNil(t, hpContainer.SecurityContext.SeccompProfile)
152+
assert.Regexp(t, `^host-profiler-[0-9a-f]{8}-logging$`, *hpContainer.SecurityContext.SeccompProfile.LocalhostProfile)
150153
}
151154

152155
func containsString(slice []string, s string) bool {

0 commit comments

Comments
 (0)