← All articles

SELinux vs AppArmor: How Do They Differ?

Compare SELinux and AppArmor: security labels, application profiles, policy enforcement, administration and practical choices for Linux systems.

SELinux and AppArmor are Linux security mechanisms that restrict what processes can do, even when ordinary user and file permissions would otherwise allow an operation. Both use the Linux Security Module (LSM) framework and can reduce the damage caused by a compromised application. Their main difference is how their policies describe and enforce access.

SELinux uses security contexts and policy rules to make access decisions. AppArmor confines programs using profiles, with file access commonly expressed through pathname rules. Neither provides useful confinement simply because its software is installed: the active policy, the processes it covers and the way it is maintained all matter.

SELinux vs AppArmor at a glance

SELinuxAppArmor
Main policy modelSecurity contexts for processes and objects, interpreted by a loaded policyProfiles describing the operations allowed to confined programs
File accessCommonly based on the process domain and the file’s security type, with additional constraints where applicableCommonly based on pathnames and access modes in the active profile
Common deploymentRHEL enables SELinux by default when installed with it; it is also widely used in the RHEL ecosystemUbuntu loads AppArmor by default and provides profiles for selected applications
Troubleshooting modeSystem-wide permissive mode, or a permissive domain where supportedComplain mode can be applied to a profile
AdministrationPolicy, contexts, labeling, Booleans and domain transitionsProfiles, rules, attachment, transitions and abstractions
ScopeDepends on the loaded policy and domains in useDepends on the loaded profiles and which processes are confined

These are broad descriptions rather than exhaustive feature lists. AppArmor has controls beyond files, and SELinux makes decisions about many kinds of objects beyond files. Distribution defaults and available features can change; always check the deployed system.

Why Linux needs more than file permissions

Traditional Linux permissions determine access using the process’s user and groups, ownership, permission bits and potentially access control lists. Privileged processes may also have Linux capabilities that affect what they can do.

Imagine a web service that is compromised through an application vulnerability. If its Unix account can read several directories, a malicious request might cause the service to read files it never legitimately needs. Mandatory access control can add another boundary: a policy may permit the service to read its content directory while denying access to other files, even where conventional permissions allow the read.

This protection is not automatic or absolute. A confined process can still perform operations that its policy allows, and vulnerabilities or mistakes in the application, kernel or policy can undermine the design. Both MAC and ordinary permissions remain important parts of the access decision.

How SELinux works

SELinux assigns security contexts to processes and many system objects. A context is often displayed in this form:

user:role:type[:range]

The type identifies a category used in type-enforcement policy. A process runs in a domain, which is a type used for a process; files and other objects also have types. The policy describes which operations are permitted between them. The optional range carries sensitivity and category information when applicable.

For example, if a web server runs in httpd_t, its policy might allow it to read files with an appropriate web-content type but deny it access to an unrelated file type. The actual decision depends on the installed policy, the process and object contexts, the requested operation and any relevant constraints. Names in this example are typical of some SELinux policies; the effective policy on the host is authoritative.

Inspect a file’s context with:

ls -Z /path/to/file

And inspect process contexts with:

ps -eZ

SELinux policies can also incorporate roles, transitions, users and MLS or MCS constraints. SELinux supports Multi-Level Security (MLS) and Multi-Category Security (MCS), but merely seeing an s0 or category field does not mean that a complete MLS system has been designed or deployed. The policy and configuration determine the constraints that are actually enforced.

How AppArmor works

AppArmor confines a process using an active profile. A profile describes permitted operations, such as access to files, execution of other programs, use of capabilities and other supported resources. Profiles can be associated with executables and can define transitions between profiles; a process may also run unconfined if no applicable confinement is in effect.

For file access, AppArmor commonly expresses rules as pathname patterns. A profile can, for example, allow a service to read files beneath a particular directory while withholding access to other locations. AppArmor can also use rules for resources other than files, and its capabilities and syntax depend on the version and distribution.

On a system with the tools installed, inspect AppArmor’s status with:

sudo aa-status

The output helps identify profiles and their modes. It should be read alongside the actual process confinement and policy; an enabled module does not mean that every application is protected by a suitable enforcing profile.

Commands prefixed with sudo require administrative privileges. If you are already using a root shell, omit sudo. The commands shown without sudo can normally be run as an ordinary user, though local access controls may affect the available output.

Security labels and file paths

The label-versus-path distinction is one of the most useful ways to understand the different approaches.

With SELinux, a file’s security type is associated with the object, and policy can make a decision using that type rather than relying solely on its pathname. File labels must still be correct: a file moved, created or deployed in an unexpected way may have a context that does not match its intended purpose. Filesystems, mounts and labeling configuration also affect the result.

With AppArmor, a profile commonly states which paths a confined application may access. This can make a profile easy to relate to an application’s directory layout. It also means that path aliases, mount namespaces, links, file moves and changes to directory structure deserve attention when designing and testing the profile. The exact result depends on the operation, profile and implementation; a change of path is not by itself proof of a bypass.

The shorthand has limits. AppArmor also uses security labels for confined tasks and other kernel objects, and supports additional kinds of policy rules. SELinux has pathname-related configuration and tools for assigning default file contexts. The distinction describes the main policy approach to file access, not the only information either system can use.

Enforcing and troubleshooting

A policy that blocks an application can be difficult to diagnose, but switching off all mandatory access control removes protection from more than the affected workload.

SELinux: enforcing and permissive

In enforcing mode, SELinux enforces the loaded policy. In system-wide permissive mode, policy denials are normally logged but enforcement is suspended. SELinux also supports making individual domains permissive when configured to do so, allowing a narrower investigation while other domains remain enforcing.

Find the current global mode with:

getenforce

On an audit-enabled system, recent denials can be inspected with:

sudo ausearch -m AVC,USER_AVC -ts recent -i

A globally enforcing system may still have individual permissive domains. Conversely, an absent audit message does not prove that SELinux was uninvolved: audit settings and dontaudit rules can affect what is recorded. Before changing policy, check labels, service configuration and conventional permissions. Our article Disable SELinux discusses troubleshooting alternatives in more detail.

AppArmor: enforce and complain

An AppArmor profile in enforce mode applies its restrictions. A profile in complain mode generally permits operations that would otherwise be denied and records them according to logging configuration; explicit deny rules have different behavior and should not be assumed to be bypassed. An unconfined process is a separate state: it is not equivalent to a confined process with a profile in complain mode.

Use aa-status to inspect profiles and modes, then examine the relevant AppArmor audit or kernel messages and the application profile. Profile names, audit locations and available tools vary by distribution. A generated or suggested profile change needs review: application behavior observed during testing is not necessarily behavior that should be allowed permanently.

Troubleshooting modes weaken confinement. Use the narrowest applicable scope for the shortest practical time, then restore enforcement and retest the intended and prohibited operations.

Which is more secure?

Neither name alone determines the security of a deployment. A carefully maintained AppArmor profile can provide effective confinement; a poorly configured SELinux domain can leave broad access, and the reverse is also true. A useful evaluation asks:

  • Which workloads are actually confined, and in which mode?
  • What can each workload read, change, execute or reach over the network?
  • Are policy changes reviewed and delivered consistently with the application?
  • Do negative tests show that forbidden operations are denied?
  • Can administrators diagnose a denial without broadly disabling protection?

SELinux is often a strong fit when an organization needs a consistent label-based policy across many services, or when the design requires SELinux MLS/MCS facilities. AppArmor is often a practical choice when administrators want application-centered profiles and their distribution provides appropriate tooling and policy. These are starting points, not guarantees: available policy, expertise and operational discipline matter in either environment.

For a high-assurance system, the choice should follow the required security properties and evidence. Define the trust boundaries, minimize permitted operations, test the policy under normal and failure conditions, and maintain the result as the system changes. Our Mandatory Access Control and SELinux pages provide more background.

Can SELinux and AppArmor run together?

Linux supports stacking multiple LSMs, but that does not mean that any particular kernel and distribution can be assumed to support SELinux and AppArmor together in a supported configuration. Kernel version, build options, active LSM selection and distribution integration all matter. Check the documentation for the actual platform before planning such a deployment; installing both sets of userspace tools is not proof that both policies are active.

The active LSM list can usually be inspected, if securityfs is mounted, with:

cat /sys/kernel/security/lsm

This lists registered security modules, not the completeness or effectiveness of their policies.

Practical questions to ask

Is SELinux harder to use than AppArmor? SELinux policy and labeling can have a steeper learning curve, especially for custom services. AppArmor profiles can be easier to connect to an application’s filesystem layout. Either can become difficult when policy, deployment and troubleshooting are poorly documented.

Does AppArmor protect only files? No. AppArmor profiles can restrict other resources and operations, including capabilities and supported network operations, depending on the implementation and policy.

Does SELinux protect every process equally? No. A system can have processes in unconfined or permissive domains, and the protections vary with the loaded policy and configuration.

Should I replace my distribution’s default? Start by understanding and verifying the protection your distribution supports and enables. A migration requires an appropriate policy, compatible tooling, testing and a maintenance plan; installing a different LSM alone does not establish equivalent confinement.

Choosing between SELinux and AppArmor

Choose SELinux when your requirements call for a label-based security model, fine-grained policy across services, or SELinux MLS/MCS capabilities—for example, as part of a carefully designed multi-tenant container platform. It is particularly suitable when your team has the expertise and resources to develop, test and maintain the policy.

Choose AppArmor when application-focused profiles fit your environment and you value a policy model that can be easier to relate to an application’s filesystem layout. It can provide effective confinement for desktops, servers and containerized workloads when suitable profiles are applied and maintained.

In either case, the security of the result depends on the policy, the workloads it covers and the evidence that the intended restrictions are enforced.

References

← Back to all articles

Contact Info

Send us a message

Tell us about your application, infrastructure or security requirements. All fields below are required.

Protected by our own security check.