41.7 Managing AppArmor Profiles: aa-status, aa-enforce, aa-complain

Alright, let’s get our hands dirty with the actual management of AppArmor profiles. You’ve got them installed, but now what? How do you know what’s even running? How do you tweak it when it inevitably breaks your perfectly good application? This is where you move from a passive user to someone who’s actually in control. First things first, you need to take stock of the situation. AppArmor, unlike some other security frameworks (we won’t name names), is actually pretty good at telling you what it’s doing.

41.6 AppArmor: Profile-Based MAC for Ubuntu and SUSE

Alright, let’s talk AppArmor. If SELinux is the over-engineered, paranoid security guard who demands to see your papers and calls his supervisor twice before letting you into your own house, AppArmor is the pragmatic bouncer who just checks the list. It’s path-based, not context-based, which is a fancy way of saying it cares about where you are, not who you are or what label you’re wearing. This makes it conceptually simpler and, frankly, a lot less of a headache to wrap your brain around on a Tuesday afternoon.

41.5 audit2allow: Generating Policy Modules from AVC Denials

Alright, let’s talk about audit2allow. You’ve just been smacked down by an SELinux AVC denial. Your first instinct might be to just flip the setenforce 0 switch and call it a day. I get it. I’ve been there. But we’re better than that. We’re going to fix this properly, and audit2allow is the power tool we use to build a custom policy module that says, “Hey, SELinux, this thing I want to happen? Let it.”

41.4 SELinux Booleans: Adjusting Policy Without Recompiling

Right, so you’ve got SELinux running. Good for you. It’s standing between your system and the abyss like a particularly grumpy, rules-obsessed bouncer. But now you want to do something slightly out of the ordinary—let’s say, allow httpd to send email. The default policy says no. The old, terrifying way was to dive into the policy source code, which is written in a language only its mother and a few Red Hat engineers could love, recompile the entire policy, and load it back in. That’s a weekend project you didn’t sign up for.

41.3 SELinux Contexts: User, Role, Type, and Level

Right, let’s talk about SELinux contexts. This is where most people’s eyes glaze over, which is a shame because it’s actually the cleverest part of the whole system. Forget “Disable SELinux” as a troubleshooting step for a second. The context is a label—a sticky note—slapped on every single object on your system: processes, files, directories, ports, you name it. The kernel uses these labels to make its access control decisions. It’s not just “Can user Bob read file.txt?” It’s “Can the process running as Bob, labeled with this specific context, read file.txt, labeled with that specific context?” This is a million times more granular than standard Unix permissions.

41.2 SELinux Modes: Enforcing, Permissive, and Disabled

Alright, let’s talk about SELinux modes, because this is where most people’s relationship with it goes sideways. You’ve probably already felt the pain: something isn’t working, you throw setenforce 0 at the problem like a magical incantation, and it starts working. Congratulations, you’ve just entered the “please don’t hurt me” mode of SELinux. Let’s demystify that magic and understand what you’re actually doing when you run that command. SELinux has three fundamental states of being: Enforcing, Permissive, and Disabled. Think of them not as a simple on/off switch, but as a spectrum of how much of a hassle it’s going to be for you today.

41.1 Mandatory Access Control vs Discretionary Access Control

Alright, let’s cut through the noise. You’ve been using Discretionary Access Control (DAC) your entire computing life, even if you didn’t know its official name. It’s the model where access to objects (files, sockets, etc.) is based on the identity of the user and the groups they belong to. The classic rwx permissions. The “discretionary” part is the problem: if you own a file (userA), you can discretionarily change its permissions to chmod 777, making it world-readable and writable. This is bonkers from a security perspective. A single misconfigured script or a compromised user process can blow the doors off your entire system.

— joke —

...