Skip to content

apparmor: allow signals and ptrace for stacked profile peers - #14487

Merged
mxpv merged 1 commit into
containerd:mainfrom
jonyhy96:fix/apparmor-stacked-peer
Nov 16, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
jonyhy96:fix/apparmor-stacked-peer

Conversation

@jonyhy96

@jonyhy96 jonyhy96 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14485

On Ubuntu, apparmor_restrict_unprivileged_unconfined=1 turns runc's change_onexec into a stack. Container tasks are then labeled cri-containerd.apparmor.d//&unconfined. The default profile only allows signal and ptrace for the literal profile name, so processes in the same container cannot signal each other (could not signal for checkpoint: Permission denied from PostgreSQL).

Allow the exact stacked peer {{.Name}}//&unconfined for the same signal and ptrace permissions the unstacked name already has. The test requires both exact stacked rules, preserves the unstacked permissions, and rejects wildcard stacked peers. The template comment now describes the kernel restriction instead of tying the behavior to a userspace AppArmor version.

Validation on Linux/arm64 with Go 1.24.13:

go test -count=1 ./contrib/apparmor
go test -race -count=1 ./contrib/apparmor
go vet ./contrib/apparmor

The updated regression test fails against the previous wildcard rules and passes with the narrowed rules. Formatting and whitespace checks pass. AppArmor parsers 2.13.6, 3.0.8, and 4.1.0 each accept 16 generated profiles covering two profile names, two daemon profiles, optional RootlessKit, and optional policy includes (48 parser checks in total, using apparmor_parser -Q -K).

Runtime enforcement on an affected Ubuntu kernel has not been revalidated for the narrowed rules.

AI assistance: Codex.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The AppArmor signal and ptrace changes need runtime validation on an affected Ubuntu host and compatibility checks with supported older parsers, since string-rendering tests cannot verify wildcard stacked-peer matching or enforcement.

No open issues 🎉

What changed in this PR

Updates containerd’s default AppArmor profile to allow signaling and tracing between stacked-profile peers, addressing the Ubuntu behavior reported in #14485.

Changes:

  • Adds {{.Name}}//&* peer rules for signal and ptrace permissions while retaining existing unstacked rules.
  • Adds a template-generation test checking both stacked rules and the existing unstacked signal rule.
File Description
contrib/​apparmor/​template.go Allows signal and ptrace permissions for stacked-profile peers.
contrib/​apparmor/​template_test.go Tests generation of stacked-peer rules and preservation of the unstacked signal rule.

Review effort: Balanced

@marekwiecek

Copy link
Copy Markdown

FYI - Ran into this after kernel upgrade and cnpg set-up, verified the fix on Ubuntu 26.04 / apparmor 5.0.2 / kernel 7.0.0-42 that peer={{.Name}}//&* matches the stacked peer — signals succeed in both pre-existing and fresh containers, and CloudNativePG's PostgreSQL 18 bootstraps without any per-workload AppArmor override.

@javirub

javirub commented Oct 31, 2026

Copy link
Copy Markdown

I ran into this today on a single-node k3s box (k3s v1.37.1, containerd v2.3.4-k3s1, Ubuntu 26.04). After a reboot my CloudNativePG primary never came back. Postgres logged "ready to accept connections", but every new connection got stuck in authentication, and the end-of-recovery checkpoint only ran once the checkpointer's 5 min timeout fired. When I tried to stop it, the postmaster couldn't even signal its own children, so I had to send SIGQUIT to everything from the host. The kernel log was full of:

apparmor="DENIED" operation="signal" profile="cri-containerd.apparmor.d" comm="postgres" requested_mask="send" denied_mask="send" signal=urg peer="cri-containerd.apparmor.d//&unconfined"

What confused me at first was that I hadn't changed anything AppArmor-related. apparmor_restrict_unprivileged_unconfined was already 1 before the reboot, and the journal from the previous boot already had the "converted to stacking" audit messages, yet there were zero signal denials. The only thing that changed was the kernel, from 7.0.0-38 to 7.0.0-42. Its changelog includes apparmor: fix unconfined user namespace restriction forced stack (LP: #2169638). So my guess is that the stacked label wasn't really enforced on signal mediation before, and now it is. That would mean anyone on Ubuntu 26.04 with non-root containers will start hitting this as they pick up that kernel.

For now I've set kernel.apparmor_restrict_unprivileged_unconfined=0 and recreated the pods, and everything is back. I'd rather not keep that hardening disabled, though, so I'd love to see this land.

Since the review note asked about older parsers, I cherry-picked this PR onto current main (aefce4e). It applies cleanly and the package tests pass. I then rendered the default profile with the same inputs loadData() uses (tunables/global, abstractions/base, abi/3.0 when it exists) and ran apparmor_parser -Q -K in a few distro containers. It parsed fine everywhere, same as the profile on main:

  • Ubuntu 20.04 (2.13.3), Debian 11 (2.13.6): no abi
  • Ubuntu 22.04 (3.0.4), Debian 12 (3.0.8), Leap 15.6 (3.1.7), Ubuntu 24.04 (4.0.1), Debian 13 (4.1.0), Ubuntu 26.04 (5.0.2), Tumbleweed (5.0.2): with abi/3.0

A couple of small things I noticed:

Also, would it be possible to backport this to 2.3.x? That's what k3s ships, and they closed k3s-io/k3s#13625 until there's an upstream release with the fix.

Yanis-Kouidri added a commit to Yanis-Kouidri/k3s-personal-servers that referenced this pull request Nov 4, 2026
Kernel 7.0.0-42 makes runc stack the containerd profile with unconfined,
so processes in a container cannot signal each other and Postgres never
starts (authentik, immich, n8n, sonarqube down). Set
kernel.apparmor_restrict_unprivileged_unconfined=0 until k3s ships the
containerd fix (containerd/containerd#14487, k3s-io/k3s#13625).

Co-authored-by: Yanis Kouidri <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Comment thread contrib/apparmor/template.go Resolved
Copilot AI balanced review requested due to automatic review settings November 6, 2026 03:19
@kubernetes-prow kubernetes-prow Bot added size/M and removed size/S labels Nov 6, 2026

@AkihiroSuda AkihiroSuda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Nov 16, 2026
@mxpv
mxpv added this pull request to the merge queue Nov 16, 2026
Merged via the queue into containerd:main with commit 447ef19 Nov 16, 2026
96 of 98 checks passed
@AkihiroSuda

Copy link
Copy Markdown
Member

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.0

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #14589

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.0

Instructions 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.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #14590

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.0

Instructions 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.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@AkihiroSuda: new pull request created: #14591

Details

In response to this:

/cherry-pick release/2.4
/cherry-pick release/2.3
/cherry-pick release/2.0

Instructions 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 cherry-pick/2.4.x Change to be cherry picked to release/2.4 priority/P0 size/M

Projects

Development

Successfully merging this pull request may close these issues.

Default AppArmor profile denies signals inside a container when the label is stacked (//&unconfined, Ubuntu apparmor_restrict_unprivileged_unconfined=1)

9 participants