Repository navigation
Conversation
0318798 to
b65590b
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds AppArmor “stacking mode” allowances so stacked profiles (e.g., name//&unconfined) can still signal/ptrace peer processes, and introduces a regression test to ensure the generated profile includes these rules.
Changes:
- Extend the generated AppArmor profile template with
//&*peer rules forsignalandptrace. - Add a Go test that renders the template and asserts the stacking rules are present.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| contrib/apparmor/template.go | Adds AppArmor template rules permitting signal/ptrace to stacked peer profiles (//&*). |
| contrib/apparmor/template_test.go | Adds a template-generation test that asserts stacking rules are included in output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d36e163 to
a173e5a
Compare
a173e5a to
56af135
Compare
Any compatibility issues with this change on older kernels? (just double checking; I recall we've had some at some point) |
|
@thaJeztah no. They're plain AARE peer patterns on the same rule types already in the template a couple of lines up, so there's nothing new for the parser to understand — The breakages you're thinking of were in version/ABI detection rather than rules: #9464 (parsing |
56af135 to
16f6908
Compare
16f6908 to
d9ba8c6
Compare
d9ba8c6 to
96dbd3b
Compare
96dbd3b to
20cc0d6
Compare
On kernel 6.17 with AppArmor profile stacking enabled, processes
created via CRI ExecSync (kubectl exec, exec-based probes) run under
a stacked profile like "cri-containerd.apparmor.d//&unconfined"
instead of plain "cri-containerd.apparmor.d".
The existing signal and ptrace rules use peer={{.Name}} which does not
match the stacked peer name, causing AppArmor DENIED audit events for
SIGURG (Go runtime goroutine preemption) and potentially ptrace
operations from exec'd processes.
Add signal and ptrace rules that match the stacked label. Its components
are ordered lexically rather than by stacking order, so this profile can
appear at either end or in the middle of the label, and each position
needs its own rule. The glob is ** rather than *, because * stops at "/"
while both profile names and the remaining components can contain one.
Stacking only ever narrows privileges, since a task carrying a stacked
label is confined by every profile in it. A peer whose label contains
this profile is therefore already within the peer set the pre-existing
peer={{.Name}} rule grants in full.
Tested by loading the modified profile via apparmor_parser --replace
on Ubuntu 25.10 aarch64, kernel 6.17.0-1007-raspi, AppArmor parser
5.0.0~alpha1. After loading, zero DENIED entries over 56+ seconds
(11+ exec probe cycles), whereas before there were continuous denials.
Fixes: containerd#12886
Assisted-By: Claude <[email protected]>
Signed-off-by: Aleksei Sviridkin <[email protected]>
20cc0d6 to
24f370f
Compare
|
#13905 fixes the same thing, found independently. The difference is coverage: the literal Happy to consolidate either way, including closing this one, as long as the rule that lands is the glob. Two things I ran into that don't belong here. The NOTE about keeping in sync with the docker profile: moby's template has no stacked-label rules at all, so there is nothing to mirror mechanically, and how you want that handled is your call. And nothing checks that the generated profile parses, The red required check is not this change. |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
On kernel 6.17 with AppArmor profile stacking enabled (
/sys/kernel/security/apparmor/features/domain/stack=yes), processes created via CRI ExecSync (kubectl exec, exec-based probes) run under a stacked profilecri-containerd.apparmor.d//&unconfined:The existing signal and ptrace rules use
peer={{.Name}}, which expands tocri-containerd.apparmor.dand does not match the stacked peer namecri-containerd.apparmor.d//&unconfined. This causes AppArmor DENIED audit events when exec'd Go processes send SIGURG for goroutine preemption:This change adds rules with
peer={{.Name}}//&*to match stacked profile peers for both signal and ptrace operations. The//&*glob matches any stacked profile suffix (e.g.,//&unconfined).Tested on Ubuntu 25.10 (questing) aarch64 with kernel 6.17.0-1007-raspi, AppArmor parser 5.0.0~alpha1, containerd v2.1.5-k3s1. The modified profile was loaded via
apparmor_parser --replace. After loading, zero new DENIED entries over 56+ seconds (11+ probe cycles at 5s interval), whereas before the fix there were continuous denials every cycle.Note: the
abi <abi/3.0>pin from #12864 is already on main and does not resolve this issue.Fixes: #12886
Why the rule is shaped this way
A flat
peer=<profile>rule does not match a stacked peer label. The kernel matches the peer label as a single string:label_compound_match()walks the components and inserts the literal//&between them, so a rule whose text iscri-containerd.apparmor.dnever matchescri-containerd.apparmor.d//&unconfined. The component fallback inlabel_components_match()does not rescue it either. It intersects permissions across components (accum->allow &= addend->allow & ~addend->deny), soNamecontributessend,receive,unconfinedcontributesreceive, and the intersection dropssend. That is the SIGURG symptom in the report.**rather than*, becausesignal.ccandptrace.cccompile the peer label throughconvert_aaregex_to_pcre(peer_label, 0, glob_default, ...), where*becomes[^/\x00]*and**becomes[^\x00]*. A single*stops at/. That leaves out path-named profiles and any stack deeper than two components, since the tail then contains a/.Three positions, because the components of a stacked label are sorted lexically rather than by stacking order (
profile_cmp()insecurity/apparmor/label.c). This profile can end up at the head, at the tail, or in the middle.The rules do not widen privileges. A stacked label is an intersection of confinements: a task labelled
A//&Bis confined by both A and B, so its permissions are a subset of what A alone allows. A peer carrying this profile as a component is already inside the set that the existingpeer={{.Name}}rule grants in full. The literal//&in the pattern also keeps hat profiles (parent//child, no&) out of the match.Checked on a live kernel, Ubuntu 24.04, kernel 6.8,
domain/stack=yes, AppArmor 4.0.1, entering the stacked label withaa-execand runningkill -9on an own child.<profile>below is the generated profile name,cri-containerd.apparmor.dby default:<profile>//&unconfinedpeer={{.Name}}only<profile>//&unconfined//&*<profile>//&other/sub//&unconfined//&*<profile>//&other/sub//&unconfined//&**<profile>//&zzz-peer//&**onlyaaa-peer//&<profile>//&**only<profile>//&zzz-peeraaa-peer//&<profile>The last two rows ran against the profile this template generates, not a hand-written stand-in.
The reported case looked like it needed only one rule because
csorts beforeu, socri-containerd.apparmor.dhappens to precedeunconfinedin the label. A profile named with a path always sorts first,/being0x2f, and would not have been covered.There is a narrower one-line alternative, relaxing
signal (receive) peer=unconfinedto(send,receive)so the component fallback covers the stack. That works, but it grants against every peer namedunconfined, host processes included. The stacked-label form stays inside this profile's own stack.The generated profile compiles on
apparmor_parser2.12, 2.13.3, 2.13.6, 3.0.4 and 4.0.1 when given a current kernel feature set, with the new rules present in the compiled policy rather than dropped. I checked that by compiling with and without them and comparing the cache, using removal of an ordinary file rule as a control to confirm the comparison detects a change at all.&is not an AARE metacharacter, so older parsers treat//&as a literal and need no awareness of stacking. One caveat if you reproduce this: without a feature set, in a container with no AppArmor, 3.0.4 and 4.0.1 printsignal rules not enforced, drop those rules, and still exit 0, so a bare parse check in that setup proves less than it appears to.