Fix AppArmor annotations for absent containers in annotation overrides#2897
Merged
Fix AppArmor annotations for absent containers in annotation overrides#2897
Conversation
…verrides The fix in a0dc8c0 added a container existence check to overrideAppArmorProfile(), preventing invalid AppArmor annotations when a container (e.g. security-agent with directSendFromSystemProbe=true) is absent from the pod spec. However, the same guard was missing from the direct annotation loop in PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations to the pod template. Any AppArmor annotation set via that path would bypass the existing fix and still produce an invalid DaemonSet. Apply the same container existence check when iterating override.Annotations: skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/<name>) if <name> does not match any container in the pod spec.
a2196a7 to
0f26877
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2897 +/- ##
==========================================
+ Coverage 40.06% 40.07% +0.01%
==========================================
Files 319 319
Lines 28039 28041 +2
==========================================
+ Hits 11233 11237 +4
+ Misses 15983 15982 -1
+ Partials 823 822 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
✅ Code Coverage 🎯 Code Coverage (details) 🔗 Commit SHA: 8290902 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
Member
|
Since we're duplicating the logic, should we use a shared helper #2898 ? Also uses the opportunity to use slices.ContainsFunc instead of looping |
Contributor
Author
|
@tbavelier Thanks. I cherry-pick your commit |
6c89448 to
8290902
Compare
tbavelier
approved these changes
Apr 14, 2026
dd-octo-sts Bot
pushed a commit
that referenced
this pull request
Apr 14, 2026
#2897) * Fix AppArmor annotations for absent containers in direct annotation overrides The fix in a0dc8c0 added a container existence check to overrideAppArmorProfile(), preventing invalid AppArmor annotations when a container (e.g. security-agent with directSendFromSystemProbe=true) is absent from the pod spec. However, the same guard was missing from the direct annotation loop in PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations to the pod template. Any AppArmor annotation set via that path would bypass the existing fix and still produce an invalid DaemonSet. Apply the same container existence check when iterating override.Annotations: skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/<name>) if <name> does not match any container in the pod spec. * Use slices shared helper instead of duplicating same logic * Add unit tests --------- Co-authored-by: Timothée Bavelier <timothee.bavelier@datadoghq.com> (cherry picked from commit 9678903)
Merged
3 tasks
3 tasks
tbavelier
added a commit
that referenced
this pull request
Apr 14, 2026
#2897) (#2899) * Fix AppArmor annotations for absent containers in direct annotation overrides The fix in a0dc8c0 added a container existence check to overrideAppArmorProfile(), preventing invalid AppArmor annotations when a container (e.g. security-agent with directSendFromSystemProbe=true) is absent from the pod spec. However, the same guard was missing from the direct annotation loop in PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations to the pod template. Any AppArmor annotation set via that path would bypass the existing fix and still produce an invalid DaemonSet. Apply the same container existence check when iterating override.Annotations: skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/<name>) if <name> does not match any container in the pod spec. * Use slices shared helper instead of duplicating same logic * Add unit tests --------- (cherry picked from commit 9678903) Co-authored-by: Sylvain Baubeau <sylvain.baubeau@datadoghq.com> Co-authored-by: Timothée Bavelier <timothee.bavelier@datadoghq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…verrides
The fix in a0dc8c0 added a container existence check to overrideAppArmorProfile(), preventing invalid AppArmor annotations when a container (e.g. security-agent with directSendFromSystemProbe=true) is absent from the pod spec.
However, the same guard was missing from the direct annotation loop in PodTemplateSpec(), which blindly copies spec.override.nodeAgent.annotations to the pod template. Any AppArmor annotation set via that path would bypass the existing fix and still produce an invalid DaemonSet.
Apply the same container existence check when iterating override.Annotations: skip AppArmor annotations (container.apparmor.security.beta.kubernetes.io/) if does not match any container in the pod spec.
What does this PR do?
A brief description of the change being made with this pull request.
Motivation
What inspired you to submit this pull request?
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
Write there any instructions and details you may have to test your PR.
Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel