Using Mandatory Access Control to Lock Down Your Linux Desktop with AppArmor

Introduction to AppArmor

I’ve been using AppArmor for years to add an extra layer of security to my Linux systems. It’s a Mandatory Access Control (MAC) system that lets you restrict what applications and services can do. By defining a set of rules, you can control file access, network connections, and system calls. This helps prevent malicious activities and gives you more peace of mind.

Installing and Enabling AppArmor

To get started with AppArmor, you’ll need to install the apparmor package. On Debian-based systems, I usually start with:

sudo apt-get install apparmor apparmor-profiles apparmor-utils

On other distributions like Arch Linux, you can use:

sudo pacman -S apparmor

Once installed, load the kernel module with:

sudo modprobe apparmor

Don’t bother with manually loading the module every time - you can configure your system to load it automatically on boot.

Creating and Managing AppArmor Profiles

AppArmor profiles are where you define the rules for a specific application or service. I usually create a new profile using:

sudo aa-genprof /usr/bin/firefox

This generates a profile for the Firefox browser. To refine the profile, use:

sudo aa-logprof

If you want to test a profile without enforcing the rules, you can put it into complain mode with:

sudo aa-complain /usr/bin/firefox

For more information on creating and managing profiles, check out the official AppArmor documentation.

Troubleshooting AppArmor Issues

In practice, you’ll likely encounter some issues with AppArmor. When that happens, use the aa-notify command to display notifications and aa-logprof to analyze log files. You can also check the current status of AppArmor with:

sudo apparmor_status

This shows you which profiles are loaded and which processes are being confined.

Further Reading

AppArmor is a powerful tool for locking down your Linux desktop. By creating and managing profiles, you can restrict application actions and improve system security. For more information, refer to the kernel.org documentation and the debian.org wiki.


See also