fix(appArmor): update Missing AppArmor Profile query for new kubernetes syntax#7979
Open
cx-artur-ribeiro wants to merge 2 commits intomasterfrom
Open
fix(appArmor): update Missing AppArmor Profile query for new kubernetes syntax#7979cx-artur-ribeiro wants to merge 2 commits intomasterfrom
cx-artur-ribeiro wants to merge 2 commits intomasterfrom
Conversation
Contributor
cx-miguel-dasilva
requested changes
Mar 16, 2026
Collaborator
cx-miguel-dasilva
left a comment
There was a problem hiding this comment.
Hi,
Please take a look at my comments.
| } | ||
|
|
||
| # build search path for apparmor profile | ||
| get_apparmor_search_path(specInfo, typeKey, containerIndex, annotationsPath) = path { |
Collaborator
There was a problem hiding this comment.
use get_nested_values_info instead
Comment on lines
+182
to
187
| } else = searchLine { | ||
| contains(path, "securityContext") | ||
| searchLine := common_lib.build_search_line(split(path, "."), []) | ||
| } else = searchLine { | ||
| searchLine := common_lib.build_search_line(split(annotationsPath, "."), []) | ||
| searchLine := common_lib.build_search_line(split(path, "."), []) | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| } else = searchLine { | |
| contains(path, "securityContext") | |
| searchLine := common_lib.build_search_line(split(path, "."), []) | |
| } else = searchLine { | |
| searchLine := common_lib.build_search_line(split(annotationsPath, "."), []) | |
| searchLine := common_lib.build_search_line(split(path, "."), []) | |
| } | |
| } else = searchLine { | |
| searchLine := common_lib.build_search_line(split(path, "."), []) | |
| } |
| annotations := object.get(metadataInfo.metadata, "annotations", {}) | ||
| expectedKey := sprintf("container.apparmor.security.beta.kubernetes.io/%s", [container]) | ||
|
|
||
| not isValidAppArmorProfile(annotations[expectedKey]) |
Collaborator
There was a problem hiding this comment.
Suggested change
| not isValidAppArmorProfile(annotations[expectedKey]) | |
| ek := annotations[expectedKey]) | |
| not isValidAppArmorProfile(ek) |
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.








Closes #7967
Reason for Proposed Changes
container.apparmor.security.beta.kubernetes.io/<name>). Manifests that use the newersecurityContext.appArmorProfileAPI (Kubernetes 1.23+, stable in 1.31) were still flagged as missing a valid AppArmor profile, producing false positives.spec.securityContext.appArmorProfile) and container level (spec.containers[i].securityContext.appArmorProfile), with container-level overriding pod-level. Valid types areRuntimeDefaultandLocalhost;Unconfinedis not accepted for this security check.spec.securityContext/spec.containers[i].securityContext) so that line numbers resolve, and keep expected/actual messages and search values consistent with the path used.Proposed Changes
Query logic (query.rego):
runtime/defaultorlocalhost/...) or a validsecurityContext.appArmorProfile(new API).validAppArmorProfileType(allowRuntimeDefaultandLocalhostonly; excludeUnconfined).hasValidAppArmorProfileNewSyntax: container-level profile wins over pod-level; only consider typesRuntimeDefaultandLocalhost.not hasValidAppArmorProfileNewSyntax(...)so new-syntax config is not reported when it is valid.Search path and line resolution :
get_apparmor_search_path: whensecurityContextexists, point tospec.securityContextorspec.containers[i].securityContext(or.appArmorProfilewhen present) so the path exists in the document andsearch_lineis not -1..securityContextwhenappArmorProfileis missing; use.securityContext.appArmorProfilewhen it exists.build_search_line_for_apparmorto build the search line for both annotation paths and the new spec paths.Messages and search value:
get_apparmor_messages: expected/actual text and search key refer to the path we report (annotations vsspec.securityContext/spec.containers[i].securityContext.appArmorProfile).get_apparmor_search_value: for new-syntax paths usekind.searchPath(e.g.Pod.spec.securityContext); for annotation-based findings keep existing search value behaviour.Tests:
spec.securityContextand Deploymentspec.template.spec.securityContext; no container-level in this file).spec.containers[i].securityContext).spec.securityContext.appArmorProfile.type: RuntimeDefault).I submit this contribution under the Apache-2.0 license.