Skip to content

Consistent refusal when apparmor is off - #1702

Open
philocalyst wants to merge 5 commits into
trifectatechfoundation:mainfrom
philocalyst:increased-armoring
Open

philocalyst wants to merge 5 commits into
trifectatechfoundation:mainfrom
philocalyst:increased-armoring

Conversation

@philocalyst

@philocalyst philocalyst commented Oct 18, 2026 •

Copy link
Copy Markdown

A sudoers rule, say (APPARMOR_PROFILE=), or Defaults apparmor_profile, may select an AppArmor profile for a given command. Builds without the apparmor feature would let go of that selection silently, leaving a system which DID enforce AppArmor failing to confine the given command. An example of this situation is sudo-rs for... Debian! Sudoedit ignored the profile in every build :(

Changes

  • Responsibly, refus Restrictions always carries the selected profile, and set_profile_for_next_exec runs in every build. Already, it asks the kernel whether AppArmor is enabled: when it is not, the profile is ignored, as before. When it is, a build without the feature now just refuses the command (saying: unable to change AppArmor profile to BLANK: this build of sudo-rs does not support AppArmor) instead of it's current unconstrained behavior. This matches an existing policy in NOEXEC:. Every cfg(feature = "apparmor") now lives in apparmor.rs.
  • Confine sudoedit's editor. Another thing to match OG sudo behavior, the profile is prepared prior to the start of the editor: the pending profile then gets inherited across the fork and only takes effect when the editor is executed. Furthermore, it is prepared once the user is authenticated, yet BEFORE the files are opened, as otherwise it'll create the file! A refused request can't go on leaving an empty file behind.
  • Docs. The man page is now superceded to talk about both. The README is updated, no longer saying that pre-supplied binaries miss it (util/build-release.sh has enabled it since 0.2.7.)
  • With AppArmor disabled in the kernel, a selected profile is still ignored. (OG sudo is equal here).

Verification

Debian 13 arm64 VM with AppArmor enabled, a profile that denies writing one path, and upstream main (base) against this branch (fix), each built with (aa) and without (noaa) the feature.

Keep policy-selected profiles available in every build and check runtime
AppArmor availability before command execution. Return an unsupported
error when AppArmor is enabled but this build cannot apply the profile.

Keep AppArmor FFI behind its feature flag, update policy fixtures, and
cover profile precedence and behavior without build support.
Extract policy-selected profile preparation and error mapping into a
helper that sudoedit can reuse. Keep the command execution order intact.
Prepare the selected profile after authentication and before opening
files, so an unsupported profile is rejected before files are created.
The pending transition takes effect when the editor executes.

Document editor confinement in both the manual source and generated page.
The release build already enables the apparmor feature. Update the
README to match the flags used by util/build-release.sh.
Explain that profiles are ignored when AppArmor is disabled and that
builds without AppArmor support reject configured profiles when it is
enabled. Update the default-profile reference and the README guidance.

Keep the manual source and generated page in sync.
@bjorn3

bjorn3 commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

og-sudo also seems to silently ignore apparmor_profile when apparmor support is disabled when building it.

@philocalyst

Copy link
Copy Markdown
Author

gasp let me check what they've said about it i'm sure it's come up before

@philocalyst

Copy link
Copy Markdown
Author

yeah i read through their mailing list and see no discussion on this. to me this feels more intuitive, yet i'm biased, but... it really is (more intuitive)

[they added apparmor support in 2022]

This branch has not been deployed

No deployments
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.

2 participants