[PROF-14068] Remove privileges for host-profiler#2953
[PROF-14068] Remove privileges for host-profiler#2953gh-worker-dd-mergequeue-cf854d[bot] merged 9 commits into
Conversation
5504b59 to
be37a57
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2953 +/- ##
==========================================
+ Coverage 41.50% 42.20% +0.69%
==========================================
Files 335 337 +2
Lines 28714 29290 +576
==========================================
+ Hits 11919 12363 +444
- Misses 16001 16113 +112
- Partials 794 814 +20
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
🎯 Code Coverage (details) 🔗 Commit SHA: 1720d02 | Docs | Datadog PR Page | Give us feedback! |
b23d2c1 to
87b1df2
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87b1df2f66
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7847cf22fa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| managers.SecurityContext().AddCapabilitiesToContainer(agent.DefaultCapabilitiesForHostProfiler(), apicommon.HostProfiler) | ||
|
|
||
| // AppArmor annotation | ||
| managers.Annotation().AddAnnotation(common.AppArmorAnnotationKey+"/"+string(apicommon.HostProfiler), "unconfined") |
There was a problem hiding this comment.
AppArmor: Do we want to expose a setting to override the "unconfined" ? I'm not familiar with how someone would override this.
There was a problem hiding this comment.
You can change it by changing the datadog agent's manifest and override the container.apparmor.security.beta.kubernetes.io/host-profiler annotation
As discussed on Thursday though, the profile provisioning is left to the user; neither the helm chart or the operator allow us to provision one automatically, that's why it's unconfined by default
| @@ -76,7 +76,7 @@ func (rc *RequiredComponent) IsConfigured() bool { | |||
| // IsPrivileged checks whether component requires privileged access. | |||
| func (rc *RequiredComponent) IsPrivileged() bool { | |||
There was a problem hiding this comment.
NIT, we are no longer privileged, so this could be slightly confusing 😄
There was a problem hiding this comment.
What do we consider as "privileged?" afaik system-probe is also not privileged but runs with elevated capabilities so I was mirroring that. This was done in response to #2953 (comment) but I can revert if you feel strongly about it :)
There was a problem hiding this comment.
Your change is good, I was just mentioning the name of the function
This is really minor.
| SecurityContext: &corev1.SecurityContext{ | ||
| ReadOnlyRootFilesystem: ptr.To(true), | ||
| ReadOnlyRootFilesystem: ptr.To(true), | ||
| AllowPrivilegeEscalation: ptr.To(false), |
There was a problem hiding this comment.
@r1viollet regarding DataDog/helm-charts#2586 (comment) and why we the seccomp allowed for GID/UID operations among other unnecessary syscalls:
It turns out that leaving AllowPrivilegeEscalation empty was in effect setting it to true, and this would cause runc to apply the seccomp profile before totally finishing its setup, including switching users from root to unprivileged! Those syscalls then got through my first syscall audit and got added to the seccomp profile 😁
helm-charts also has this issue, I will have to do a follow-up PR to both tighten seccomp allowlist and fix this.
I'm including the fix in this PR but will update the seccomp in a follow-up PR to keep the seccomp profile consistent between both operator and helm.
- favor a list of capabilities - seccomp profile - support for custom apparmor profile
Without it, seccomp restrictions are in place too soon, meaning runc's own `setuid/setgid/setgroups/capset` calls during container setup are subject to our filter and would need to be allowlisted.
2bed0b9 to
26e28a5
Compare
tbavelier
left a comment
There was a problem hiding this comment.
Not sure how feasible it is, but would it be possible to make all these changes solely inside the feature/hostprofiler code path instead of inside common + default ? I believe/understand you followed the pattern from system-probe but system-probe is in a slightly different position where it is used by multiple features while host-profiler is self-contained, so would be ideal if it's fully managed by the feature code path. It might not be technically possible however, would need to be investigated
b9c29ec to
c57fb7e
Compare
That's correct, I followed |
c57fb7e to
b03042c
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
tbavelier
left a comment
There was a problem hiding this comment.
slices comment not important, but the one about the init-container image is thus requesting changes
There was a problem hiding this comment.
Nit but slices can probably be used here to simplify/rewrite some helpers/assertions. Does not matter tho
| func buildSeccompSetupInitContainer() corev1.Container { | ||
| return corev1.Container{ | ||
| Name: "host-profiler-seccomp-setup", | ||
| Image: images.GetLatestAgentImage(), |
There was a problem hiding this comment.
See #3030 but tl;dr, make sure to use the same image as the other containers to avoid pulling it twice. Can be reproduced in current state with spec.global.registry: public.ecr.aws (or something different from the default gcr.io), and init-container will still pull from gcr.io
There was a problem hiding this comment.
Thank you so much for the draft PR! Took the liberty to cherry-pick the commit directly :)
remove privileges for the host profiler: - favor a list of capabilities - seccomp profile - support for custom apparmor profile add host profiler related FQDN to agent cilium egress allow list remove cap_sys_admin to favor stricter caps add tests hostProfiler should be considered as privileged drop all caps before adding necessary ones explicitly set AllowPrivilegeEscalation to false: Without it, seccomp restrictions are in place too soon, meaning runc's own `setuid/setgid/setgroups/capset` calls during container setup are subject to our filter and would need to be allowlisted. migrate everything to inside hostprofiler feature Use resolved image for host-profiler seccomp init Co-authored-by: tbavelier <[email protected]> Co-authored-by: theo.demagalhaes <[email protected]>
What does this PR do?
This PR mirrors DataDog/helm-charts#2586 for
datadog-operator:privileges: trueand replaces by list of capabilitiesintake.profile.%s: profiling intakesourcemap-intake.%s: symbol intakeotlp.%s: OTLP metrics intakeMotivation
https://datadoghq.atlassian.net/browse/REVIEW-85?focusedCommentId=3201542
Additional Notes
Anything else we should know when reviewing?
Minimum Agent Versions
Are there minimum versions of the Datadog Agent and/or Cluster Agent required?
Describe your test plan
Tested on a cluster with the host-profiler feature enabled via
agent.datadoghq.com/host-profiler-enabled: "true"annotation on the DDA.Profiles for both supported architectures can be found here
Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel