fix(core): guard strings.Split index in AppArmor annotation parsing - #2814
Open
bhuvan-somisetty wants to merge 1 commit into
Open
fix(core): guard strings.Split index in AppArmor annotation parsing#2814bhuvan-somisetty wants to merge 1 commit into
bhuvan-somisetty wants to merge 1 commit into
Conversation
bhuvan-somisetty
requested review from
Aryan-sharma11,
AryanBakliwal and
achrefbensaad
as code owners
July 29, 2026 03:07
Malformed container.apparmor.security.beta.kubernetes.io annotations (missing container suffix in the key, or a value without the localhost/<profile> form) indexed into strings.Split results without checking length, causing a panic on any pod add/update with a non-conforming annotation. Guard both splits and skip/log instead. Fixes kubearmor#2813 Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
bhuvan-somisetty
force-pushed
the
fix/apparmor-annotation-panic
branch
from
July 29, 2026 03:10
c6d5f9b to
0e9b491
Compare
Author
|
Hi @achrefbensaad @Aryan-sharma11 @AryanBakliwal, would appreciate a review on this whenever you get a chance. It fixes a daemon panic in the AppArmor annotation parsing path (issue #2813). Thanks! |
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.
Purpose of PR?:
UpdateContainer's AppArmor annotation loop indexed intostrings.Split(k, "/")[1]andstrings.Split(v, "/")[1]without checking the length of the returned slice. Any pod annotation key without a/-separated container name, or a non-unconfinedvalue without a/-separated profile, madestrings.Splitreturn a 1-element slice and panicked the goroutine handling pod updates.This pulls the parsing logic into
parseAppArmorAnnotations, guards both splits with a length check, and skips + logs a warning for a malformed annotation instead of indexing out of range.Fixes #2813
Does this PR introduce a breaking change?
No.
If the changes in this PR are manually verified, list down the scenarios covered::
TestParseAppArmorAnnotationscovering: well-formedunconfinedannotation, well-formedlocalhost/<profile>annotation, a bare annotation key with no container suffix, a value without a/separator, unrelated annotations, and nil annotations.go build ./...andgo test ./...pass locally.Additional information for reviewer? :
Checklist:
<type>(<scope>): <subject>