Skip to content

AppArmor profile enforcement unconditionally skipped in rootless mode #2543

Description

@phil-02

Summary

pkg/apparmor/internal/supported/supported.go returns "AppArmor is not supported on rootless containers" unconditionally when unshare.IsRootless() is true. The comment in apparmor_linux.go justifies this as "requires root", but aa_change_onexec() operates by writing to /proc/self/attr/exec — this does not require elevated privileges and works from unprivileged processes on kernels that support it.

The result is that podman info reports apparmorEnabled: false on rootless systems with AppArmor fully operational, and apparmor_profile in containers.conf is silently ignored.

Affected files

  • pkg/apparmor/internal/supported/supported.go — IsSupported() hard-gates on IsRootless()
  • pkg/apparmor/apparmor_linux.go — lines 86–87, 152–153, 265–269

Comparison with Docker

Docker applies docker-default to all containers automatically. Switching to rootless Podman silently removes this layer without warning.

Proposed fix

Replace the unconditional IsRootless() guard with a runtime capability probe:

  1. Attempt aa_change_onexec() with a known-loaded profile in a test exec
  2. If it succeeds, AppArmor is usable in this rootless context
  3. If it returns EPERM/EACCES, fall back gracefully and log a clear warning

This respects kernel-level restrictions (apparmor_restrict_unprivileged_unconfined) without hardcoding a blanket "rootless = no AppArmor" rule. The existing verifierImpl interface already provides the right abstraction for mocking this in tests.

Environment

  • containers/common: 0.57.4
  • Kernel: 6.17.0 (Ubuntu)
  • apparmor_restrict_unprivileged_unconfined: 0
  • apparmor_restrict_unprivileged_userns: 1

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions