Skip to content

fix(core): guard strings.Split index in AppArmor annotation parsing - #2814

Open
bhuvan-somisetty wants to merge 1 commit into
kubearmor:mainfrom
bhuvan-somisetty:fix/apparmor-annotation-panic
Open

fix(core): guard strings.Split index in AppArmor annotation parsing#2814
bhuvan-somisetty wants to merge 1 commit into
kubearmor:mainfrom
bhuvan-somisetty:fix/apparmor-annotation-panic

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown

Purpose of PR?:

UpdateContainer's AppArmor annotation loop indexed into strings.Split(k, "/")[1] and strings.Split(v, "/")[1] without checking the length of the returned slice. Any pod annotation key without a /-separated container name, or a non-unconfined value without a /-separated profile, made strings.Split return 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::

  • Added TestParseAppArmorAnnotations covering: well-formed unconfined annotation, well-formed localhost/<profile> annotation, a bare annotation key with no container suffix, a value without a / separator, unrelated annotations, and nil annotations.
  • go build ./... and go test ./... pass locally.

Additional information for reviewer? :

Checklist:

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
bhuvan-somisetty force-pushed the fix/apparmor-annotation-panic branch from c6d5f9b to 0e9b491 Compare July 29, 2026 03:10
@bhuvan-somisetty

Copy link
Copy Markdown
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!

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.

core: unguarded strings.Split index in AppArmor annotation parsing can panic the daemon

1 participant