Skip to content

[CWS] Add declared hardening infos - #55994

Open
mftoure wants to merge 18 commits into
mainfrom
momar/secprofiles-add-security-context
Open

mftoure wants to merge 18 commits into
mainfrom
momar/secprofiles-add-security-context

Conversation

@mftoure

@mftoure mftoure commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

What

Enrich CWS security profiles with the declared Kubernetes hardening posture (privileged, seccomp profile, capabilities add/drop, bools: runAsNonRoot, allowPrivilegeEscalation, readOnlyRootFilesystem).

How

  • pkg/proto/datadog/workloadmeta + comp/core/workloadmeta — add ContainerSecurityContext, Capabilities, SeccompProfile and wire them through Container

  • pkg/security/resolvers/securitycontext — new WorkloadmetaResolver that reads the container's declared posture and derives the template-slot key by walking OwnerReferences (ReplicaSet → Deployment, Job → CronJob
    via the shared pkg/util/kubernetes name-suffix heuristic).

  • pkg/security/security_profile — Profile now carries a SecurityContexts map[Key]*SecurityContext. ManagerV2 upserts on profile creation

TODO

New release on agent-payload before merging: DataDog/agent-payload#519

@mftoure mftoure added changelog/no-changelog No changelog entry needed qa/done QA done before merge and regressions are covered by tests labels Sep 8, 2026
@dd-octo-sts dd-octo-sts Bot added internal Identify a non-fork PR team/agent-security labels Sep 8, 2026
@github-actions github-actions Bot added the long review PR is complex, plan time to review it label Sep 8, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review by Codex (OpenAI) - workflow run

patch is incorrect: the declared security context cannot reach system-probe through the existing remote workloadmeta transport, so the new field remains absent in deployed Agents.

Comment on lines +43 to +44
container, err := r.wmeta.GetContainer(string(id))
if err != nil || container == nil || container.SecurityContext == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Transport SecurityContext to system-probe before resolving it

System-probe uses workloadmeta.Remote, but Container.SecurityContext is marked proto:"ignore" in comp/core/workloadmeta/def/types.go and is omitted by the workloadmeta protobuf conversions. Consequently, even when the core Agent's kubelet collector populates this field, system-probe receives a container with a nil security context and this resolver always returns nil. Add the field to the remote workloadmeta transport and verify the deployed pipeline so Declared can actually be populated.

@dd-octo-sts

dd-octo-sts Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Go Package Import Differences

Baseline: f049eb5
Comparison: 50abd39

binaryosarchchange
system-probelinuxamd64
+1, -0
+github.com/DataDog/datadog-agent/pkg/security/resolvers/securitycontext
system-probelinuxarm64
+1, -0
+github.com/DataDog/datadog-agent/pkg/security/resolvers/securitycontext

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Code Coverage (details)
• Patch Coverage: 77.68%
• Overall Coverage: 57.02% (+0.09%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 50abd39 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Files inventory check summary

File checks results against ancestor f049eb5d:

Results for datadog-agent_7.85.0~devel.git.669.50abd39.pipeline.140097665-1_amd64.deb:

No change detected

Results for datadog-iot-agent_7.85.0~devel.git.669.50abd39.pipeline.140097665-1_amd64.deb:

No change detected

@dd-octo-sts

dd-octo-sts Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor f049eb5
📊 Static Quality Gates Dashboard
🔗 SQG Job

Successful checks

Info

Quality gate Change Size (prev → curr → max)
✅ agent_deb_amd64 +186.56 KiB (0.02% increase, -5.88% of buffer) 782.879 → 783.061 → 785.980
✅ agent_deb_amd64_fips +182.41 KiB (0.02% increase, -9.21% of buffer) 717.276 → 717.454 → 719.210
✅ agent_heroku_amd64 +24.34 KiB (0.01% increase, -0.42% of buffer) 317.549 → 317.573 → 323.180
✅ agent_msi +101.0 KiB (0.02% increase, -0.61% of buffer) 652.555 → 652.654 → 668.830
✅ agent_rpm_amd64 +186.56 KiB (0.02% increase, -5.90% of buffer) 782.863 → 783.045 → 785.950
✅ agent_rpm_amd64_fips +182.41 KiB (0.02% increase, -9.13% of buffer) 717.260 → 717.438 → 719.210
✅ agent_rpm_arm64 +182.44 KiB (0.02% increase, -4.19% of buffer) 753.665 → 753.843 → 757.920
✅ agent_rpm_arm64_fips +174.28 KiB (0.02% increase, -4.83% of buffer) 693.455 → 693.625 → 696.980
✅ agent_suse_amd64 +186.56 KiB (0.02% increase, -5.90% of buffer) 782.863 → 783.045 → 785.950
✅ agent_suse_amd64_fips +182.41 KiB (0.02% increase, -9.13% of buffer) 717.260 → 717.438 → 719.210
✅ agent_suse_arm64 +182.44 KiB (0.02% increase, -4.19% of buffer) 753.665 → 753.843 → 757.920
✅ agent_suse_arm64_fips +174.28 KiB (0.02% increase, -4.83% of buffer) 693.455 → 693.625 → 696.980
✅ docker_agent_amd64 +178.38 KiB (0.02% increase, -10.54% of buffer) 841.907 → 842.081 → 843.560
✅ docker_agent_arm64 +182.25 KiB (0.02% increase, -4.29% of buffer) 837.730 → 837.908 → 841.880
✅ docker_agent_jmx_amd64 +178.37 KiB (0.02% increase, -10.56% of buffer) 1032.821 → 1032.995 → 1034.470
✅ docker_agent_jmx_arm64 +182.25 KiB (0.02% increase, -4.29% of buffer) 1017.424 → 1017.602 → 1021.570
✅ docker_dogstatsd_amd64 +16.12 KiB (0.04% increase, -1.52% of buffer) 39.406 → 39.421 → 40.440
✅ docker_host_profiler_amd64 +21.73 KiB (0.01% increase, -0.19% of buffer) 308.056 → 308.077 → 319.490
✅ docker_host_profiler_arm64 +9.1 KiB (0.00% increase, -0.08% of buffer) 319.256 → 319.265 → 330.690
✅ dogstatsd_deb_amd64 +12.16 KiB (0.04% increase, -1.11% of buffer) 30.149 → 30.161 → 31.220
✅ dogstatsd_deb_arm64 +12.12 KiB (0.04% increase, -0.83% of buffer) 28.157 → 28.169 → 29.590
✅ dogstatsd_rpm_amd64 +12.16 KiB (0.04% increase, -1.11% of buffer) 30.149 → 30.161 → 31.220
✅ dogstatsd_suse_amd64 +12.16 KiB (0.04% increase, -1.11% of buffer) 30.149 → 30.161 → 31.220
✅ iot_agent_deb_amd64 +8.12 KiB (0.02% increase, -0.82% of buffer) 46.587 → 46.595 → 47.550
✅ iot_agent_deb_arm64 +12.16 KiB (0.03% increase, -1.17% of buffer) 43.204 → 43.216 → 44.220
✅ iot_agent_deb_armhf +12.08 KiB (0.03% increase, -1.19% of buffer) 44.029 → 44.041 → 45.020
✅ iot_agent_rpm_amd64 +8.12 KiB (0.02% increase, -0.82% of buffer) 46.588 → 46.596 → 47.550
✅ iot_agent_suse_amd64 +8.12 KiB (0.02% increase, -0.82% of buffer) 46.587 → 46.595 → 47.550
✅ docker_cluster_agent_amd64 +8.16 KiB (0.00% increase, -11.47% of buffer) 213.631 → 213.639 → 213.700
4 successful checks with minimal change (< 2 KiB)
Quality gate Current Size
✅ docker_cws_instrumentation_amd64 7.439 MiB
✅ docker_cws_instrumentation_arm64 6.877 MiB
✅ docker_dogstatsd_arm64 37.503 MiB
✅ docker_cluster_agent_arm64 226.600 MiB

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Job ID: b52a3de2-3432-414f-9cc9-6310d58b4076

Baseline: f049eb5
Comparison: 50abd39
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
➖ quality_gate_logs % cpu utilization +0.98 [+0.11, +1.84] 1 Logs bounds checks dashboard
➖ quality_gate_metrics_logs memory utilization +0.73 [+0.50, +0.96] 1 Logs bounds checks dashboard
➖ quality_gate_security_mean_fs_load memory utilization +0.42 [+0.38, +0.45] 1 Logs bounds checks dashboard
➖ dsd_uds_10mb_3k_timestamped_contexts_memory memory utilization +0.32 [+0.10, +0.54] 1 Logs
➖ quality_gate_idle memory utilization +0.24 [+0.19, +0.28] 1 Logs bounds checks dashboard
➖ quality_gate_security_no_fs_load memory utilization +0.17 [+0.10, +0.24] 1 Logs bounds checks dashboard
➖ quality_gate_security_idle memory utilization +0.14 [+0.10, +0.17] 1 Logs bounds checks dashboard
➖ quality_gate_idle_all_features memory utilization +0.09 [+0.05, +0.12] 1 Logs bounds checks dashboard
➖ python_openmetrics % cpu utilization +0.03 [-0.67, +0.72] 1 Logs bounds checks dashboard
➖ dsd_uds_10mb_3k_timestamped_contexts_cpu % cpu utilization -0.28 [-0.52, -0.04] 1 Logs
➖ dsd_uds_client_drop_detector_cpu % cpu utilization -0.39 [-0.89, +0.10] 1 Logs
➖ quality_gate_private_action_runner memory utilization -0.56 [-0.68, -0.43] 1 Logs bounds checks dashboard

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
✅ python_openmetrics checks_execution_time 10/10 79.37 ≤ 100 bounds checks dashboard
✅ python_openmetrics cpu_usage 10/10 1334.32 ≤ 1500 bounds checks dashboard
✅ python_openmetrics memory_usage 10/10 4.33GiB ≤ 4.75GiB bounds checks dashboard
✅ quality_gate_idle intake_connections 10/10 4 ≤ 5 bounds checks dashboard
✅ quality_gate_idle memory_usage 10/10 175.77MiB ≤ 179MiB bounds checks dashboard
✅ quality_gate_idle total_bytes_received 10/10 750.84KiB ≤ 819.20KiB bounds checks dashboard
✅ quality_gate_idle_all_features intake_connections 10/10 4 ≤ 5 bounds checks dashboard
✅ quality_gate_idle_all_features memory_usage 10/10 527.94MiB ≤ 537MiB bounds checks dashboard
✅ quality_gate_idle_all_features total_bytes_received 10/10 1.14MiB ≤ 1.25MiB bounds checks dashboard
✅ quality_gate_logs intake_connections 10/10 18 ≤ 40 bounds checks dashboard
✅ quality_gate_logs memory_usage 10/10 214.56MiB ≤ 228MiB bounds checks dashboard
✅ quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
✅ quality_gate_logs total_bytes_received 10/10 263.42MiB ≤ 292MiB bounds checks dashboard
✅ quality_gate_metrics_logs cpu_usage 10/10 369.57 ≤ 2000 bounds checks dashboard
✅ quality_gate_metrics_logs intake_connections 10/10 20 ≤ 40 bounds checks dashboard
✅ quality_gate_metrics_logs memory_usage 10/10 427.05MiB ≤ 455MiB bounds checks dashboard
✅ quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
✅ quality_gate_metrics_logs total_bytes_received 10/10 0.94GiB ≤ 1.04GiB bounds checks dashboard
✅ quality_gate_private_action_runner memory_usage 10/10 73.07MiB ≤ 75MiB bounds checks dashboard
✅ quality_gate_security_idle cpu_usage 10/10 31.30 ≤ 100 bounds checks dashboard
✅ quality_gate_security_idle memory_usage 10/10 325.24MiB ≤ 355MiB bounds checks dashboard
✅ quality_gate_security_mean_fs_load cpu_usage 10/10 64.15 ≤ 200 bounds checks dashboard
✅ quality_gate_security_mean_fs_load memory_usage 10/10 303.76MiB ≤ 335MiB bounds checks dashboard
✅ quality_gate_security_no_fs_load cpu_usage 10/10 24.76 ≤ 100 bounds checks dashboard
✅ quality_gate_security_no_fs_load memory_usage 10/10 318.29MiB ≤ 345MiB bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

✅ Passed. All Quality Gates passed.

  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_private_action_runner, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.

mftoure and others added 4 commits September 8, 2026 17:35
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	go.sum
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	comp/core/tagger/fx-remote/go.sum
#	comp/core/tagger/impl-remote/go.sum
#	comp/logs-library/go.sum
#	comp/otelcol/collector-contrib/impl/go.sum
#	comp/otelcol/ddflareextension/impl/go.sum
#	comp/otelcol/logsagentpipeline/go.sum
#	comp/otelcol/logsagentpipeline/logsagentpipelineimpl/go.sum
#	comp/otelcol/otlp/components/exporter/datadogexporter/go.sum
#	comp/otelcol/otlp/components/exporter/logsagentexporter/go.sum
#	comp/otelcol/otlp/components/exporter/serializerexporter/go.sum
#	comp/otelcol/otlp/components/processor/infraattributesprocessor/go.sum
#	go.sum
#	internal/qbranch/anomalydetection-testbench/go.sum
#	pkg/config/remote/go.sum
#	pkg/process/util/api/go.sum
#	pkg/proto/go.sum
#	pkg/serializer/go.sum
#	pkg/trace/otel/go.sum
#	pkg/util/grpc/go.sum
#	test/e2e-framework/go.sum
#	test/fakeintake/go.sum
#	test/new-e2e/go.sum
#	test/otel/go.sum
Co-authored-by: Cursor <cursoragent@cursor.com>
The workspace-wide dda inv tidy after merging main churned 24 nested
modules to propagate the agent-payload pseudo-version. That churn is
unrelated to this PR's intent: our only genuine dep change is the
agent-payload pin in the root go.mod. Restoring those nested files to
their origin/main state.

Note: this will fail the check-mod-tidy CI gate (which runs
'go work sync' + 'git diff --exit-code **/go.mod **/go.sum'). Accepted
for now; will be addressed either by re-adding the sync (if we keep the
agent-payload pseudo-version) or by cutting a real agent-payload release
and re-pinning to it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dd-octo-sts dd-octo-sts Bot added the team/container-platform The Container Platform Team label Sep 9, 2026
@mftoure
mftoure force-pushed the momar/secprofiles-add-security-context branch from f17c21f to 2c36c3e Compare September 9, 2026 11:20
@mftoure mftoure changed the title add HardeningDeclared [CWS] Add declared hardening infos Sep 10, 2026
@mftoure
mftoure marked this pull request as ready for review September 10, 2026 11:52
@mftoure
mftoure requested review from a team as code owners September 10, 2026 11:52

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review by Codex (OpenAI) - workflow run

The patch is incorrect: a transient workloadmeta miss can permanently omit declared hardening information from an active profile. The added unit tests do not exercise this startup ordering or verify delivery through fakeintake.

Start: eventTime,
End: eventTime,
}
secprof.Declared = m.resolveDeclared(event.ProcessContext.Process.ContainerContext.ContainerID)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Retry unresolved posture after profile creation

The remote tagger and remote workloadmeta populate independently, so image tags can be available before workloadmeta contains the container's security context. If this lookup returns nil, getOrCreateProfile subsequently returns the cached profile without resolving it again; the storage backfill only runs when loading a profile. Consequently, a transient startup or container-discovery delay leaves Declared absent for the profile's lifetime even after the data arrives. Retry resolution while the cached profile's Declared is nil, and cover delayed workloadmeta availability in a test.

Comment on lines +400 to +401
v := *src
return &v

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can use new(*src) instead of de-ref into a variable and reference again.

Comment on lines +400 to +401
v := *src
return &v

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar nit with new(*src)

Comment on lines +394 to +396
// copyBoolPtr returns a fresh *bool with src's value, or nil if src is nil,
// so wire-side callers never alias workloadmeta cache storage.
func copyBoolPtr(src *bool) *bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal but this defensive measure doesn't seem that necessary. This is used for proto streaming - not like it'll be passed around different components. Similar thought with the other copyBoolPtr .

Comment on lines +100 to +107
// copyBoolPtr returns a fresh *bool with src's value, or nil if src is nil.
func copyBoolPtr(src *bool) *bool {
if src == nil {
return nil
}
v := *src
return &v
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar nit and thoughts on this method in general.

Comment thread go.mod Outdated
github.com/CycloneDX/cyclonedx-go v0.12.0
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/DataDog/agent-payload/v5 v5.0.209
github.com/DataDog/agent-payload/v5 v5.0.211-0.20260910152323-44bb6d8404c1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already mentioned in the PR description, but another reminder to pin to a release version instead of a commit hash before merging.

Comment thread pkg/security/resolvers/securitycontext/resolver.go Outdated
Comment thread pkg/security/resolvers/securitycontext/resolver.go Outdated
Comment thread pkg/security/resolvers/securitycontext/resolver.go Outdated
Comment thread pkg/security/security_profile/profile/profile.go Outdated
Comment thread pkg/security/security_profile/manager_v2.go Outdated
Comment thread pkg/security/security_profile/manager_v2.go Outdated
Comment thread pkg/security/security_profile/manager_v2.go

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed component/system-probe internal Identify a non-fork PR long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/agent-build team/agent-security team/container-integrations team/container-platform The Container Platform Team team/kubernetes-experiences

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants