Skip to content

Replace privileged:true with minimal capabilities in integration tests#3447

Open
robbycochran wants to merge 4 commits into
masterfrom
rc-remove-privileged
Open

Replace privileged:true with minimal capabilities in integration tests#3447
robbycochran wants to merge 4 commits into
masterfrom
rc-remove-privileged

Conversation

@robbycochran

Copy link
Copy Markdown
Collaborator

Summary

  • Deploy collector with CAP_BPF, CAP_PERFMON, CAP_SYS_PTRACE, and CAP_SYS_RESOURCE instead of privileged: true across all three container runtime paths (Docker/Podman, CRI, K8s)
  • Add CapAdd field to ContainerStartConfig and wire it through Docker and CRI executors
  • K8s path sets explicit SecurityContext with allowPrivilegeEscalation: false, drop: ALL, and the four capabilities

This is Phase 2 of the collector privilege reduction effort. Phase 1 (stackrox/stackrox#21065) updated the production Helm templates. This PR validates that BPF collection works correctly under the reduced privilege model by running the existing integration test suite without privileged: true.

Files changed

File Change
pkg/config/container_config.go Add CapAdd []string field to ContainerStartConfig
pkg/executor/executor_docker_api.go Wire CapAdd to Docker HostConfig.CapAdd
pkg/executor/executor_cri.go Wire CapAdd to CRI LinuxContainerSecurityContext.Capabilities with drop: ALL
pkg/collector/collector_k8s.go Replace privileged: true with capability-based SecurityContext
pkg/collector/collector_docker.go Set Privileged: false with CapAdd for the four capabilities

Capabilities justification

Capability Why
CAP_BPF Load BPF programs and create BPF maps via bpf() syscall
CAP_PERFMON Attach BPF programs to kernel tracing infrastructure (tp_btf/)
CAP_SYS_PTRACE Read restricted /proc/pid/ entries across namespaces via hostPath mount
CAP_SYS_RESOURCE Raise RLIMIT_MEMLOCK to RLIM_INFINITY for BPF map allocation

Known considerations

  • Docker seccomp: Dockers default seccomp profile allows bpf() since 20.10 but may filter perf_event_open(). If Docker-path tests fail, we may need seccomp=unconfined on the Docker executor. Podman/CRI are unaffected.
  • SELinux: All test VMs use setenforce 0 (permissive). SELinux enforcing validation is deferred to Phase 3 (custom SCC).
  • node-inventory: Remains privileged: true (separate workstream).

Test plan

  • All existing integration tests pass on RHEL/RHCOS VMs (podman/CRI path)
  • All existing integration tests pass on Ubuntu/COS VMs (Docker path)
  • K8s integration tests pass on KinD
  • No regression in benchmark tests
  • If Docker-path tests fail due to seccomp, add seccomp=unconfined follow-up

Deploy collector with CAP_BPF, CAP_PERFMON, CAP_SYS_PTRACE, and
CAP_SYS_RESOURCE instead of privileged:true across all three container
runtime paths (Docker, CRI, K8s).

Changes:
- Add CapAdd field to ContainerStartConfig
- Wire CapAdd to Docker HostConfig
- Wire CapAdd to CRI LinuxContainerSecurityContext with drop ALL
- Set K8s SecurityContext with explicit capabilities and
  allowPrivilegeEscalation:false
- Set Docker collector manager to Privileged:false with CapAdd
@robbycochran robbycochran requested a review from a team as a code owner June 10, 2026 23:47
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: a4d65f2e-9d05-4ab7-bb1b-cdf95b6b0290

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rc-remove-privileged

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

codecov-commenter commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.34%. Comparing base (339edbf) to head (ab4f6f9).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3447   +/-   ##
=======================================
  Coverage   27.34%   27.34%           
=======================================
  Files          95       95           
  Lines        5420     5420           
  Branches     2545     2545           
=======================================
  Hits         1482     1482           
  Misses       3211     3211           
  Partials      727      727           
Flag Coverage Δ
collector-unit-tests 27.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

RHCOS 4.12-4.19 and RHEL 8 run kernel 4.18.0 where CAP_BPF is not
functional as a discrete capability — libbpf_probe_bpf_map_type()
returns EPERM. Add NeedsPrivileged() helper that detects these platforms
via VM_CONFIG and falls back to privileged: true, while modern kernels
(RHEL 9+, Ubuntu, COS, Flatcar) use the reduced capability set.
RHEL-SAP kernel builds (even on 5.14+) restrict BPF capability probing,
causing libbpf_probe_bpf_map_type() to return EPERM with discrete
CAP_BPF. Fall back to privileged mode on rhel-sap and rhel-s390x VMs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants