AppArmor Profile Generation

Usage instructions for confining user-space applications through mandatory access control

1. Introduction

This guide explains how to design, generate, and maintain AppArmor profiles in order to confine user-space applications using Mandatory Access Control (MAC).

The focus is on understanding the profile generation workflow, from observation to enforcement, rather than on distribution-specific tooling or automation. The reader is expected to be familiar with Linux process execution, filesystem layouts, and basic security models.

This document is intended for:

The goal is not perfect confinement, but controlled reduction of application capabilities.

2. Scope and non-goals

In scope

Out of scope

3. AppArmor security model overview

3.1 Mandatory Access Control

AppArmor enforces access rules independently of user permissions.

Key characteristics:

MAC is additive to discretionary access control, not a replacement.

3.2 Path-based confinement

Unlike label-based systems, AppArmor uses filesystem paths.

Implications:

This simplifies reasoning but introduces fragility.

3.3 Profiles and execution context

Each confined process:

Profile attachment is deterministic and explicit.

4. Prerequisites

System requirements

Operational requirements

A test environment is strongly recommended.

5. Profile lifecycle overview

AppArmor profiles typically evolve through four phases:

  1. Discovery
  2. Learning
  3. Enforcement
  4. Maintenance

Skipping phases usually leads to breakage or over-permissive policies.

6. Identifying the confinement target

Before generating a profile, clearly define:

Ambiguous execution paths lead to incomplete confinement.

7. Initial profile generation

7.1 Profile skeleton

A minimal profile defines:

At this stage, the profile is intentionally incomplete.

7.2 Complain (learning) mode

In learning mode:

This mode is essential for dynamic or complex applications.

Learning mode does not guarantee coverage of rare code paths.

8. Observing application behavior

8.1 Log-driven refinement

During execution, AppArmor reports:

Logs reflect what happened, not what is required in all cases.

8.2 Behavioral boundaries

When interpreting logs:

Not all observed behavior should be allowed.

9. Refining the profile

9.1 Filesystem access

Rules should:

Overly broad file rules defeat confinement.

9.2 Execution control

Pay attention to:

Execution permissions are often the weakest point.

9.3 Capabilities and privileges

Allowing Linux capabilities:

Capabilities expand the attack surface.

10. Transition to enforce mode

Once the profile is sufficiently refined:

Enforce mode changes application behavior by design.

11. Handling denials in production

Expected denials

Unexpected denials

Denials indicate mismatch between policy and reality.

12. Profile maintenance

AppArmor profiles are not static artifacts.

Maintenance requires:

Stale rules accumulate silently.

13. Common mistakes and pitfalls

Profiles encode assumptions that must be revisited.

14. Limitations and trade-offs

Strengths

Weaknesses

AppArmor improves security posture, not correctness.

15. Variants and alternatives

System-wide confinement

Used for:

Trade-off:

Per-user applications

Used for:

Trade-off:

Alternative MAC systems

Label-based systems:

Choice depends on operational constraints.

16. Conclusion

AppArmor profile generation is an iterative, observational process that trades convenience for control.

Effective confinement requires:

Used carefully, AppArmor provides meaningful reduction of attack surface while remaining understandable and debuggable.