Read a sample: 1. Service Protection and the AppArmor Model
A service can be doing exactly what it was installed to do and still have more access than it needs. A web process may need to read a configuration file and serve a small directory of documents. If its operating-system account can also read unrelated files, however, a flaw in the application may give an attacker a way to reach those files too.
AppArmor addresses part of that problem by placing an additional policy around processes. Instead of relying only on the permissions associated with a user account, an administrator can define what a particular program is allowed to access as it runs. A profile might permit a service to read its configuration and a designated content directory, while withholding access to unrelated parts of the filesystem.
That distinction is the foundation of this book. The objective is not to write the largest or strictest profile possible. It is to understand what a service needs, express those needs in policy, and test that the service remains useful while unnecessary access is constrained.
AppArmor is one layer in a service-protection strategy, not a substitute for secure application configuration, patching, careful account management, or network controls. Its value is more specific: it can reduce a process’s available actions according to a policy that the administrator can inspect and refine.
A Linux service usually runs as one or more processes. Those processes may read configuration, open files, create sockets, write logs, start helper programs, and perform other operations on behalf of users or other systems. Some services run continuously; others start when requested or perform scheduled work.
When a process opens a file, the kernel decides whether that access is permitted. When it starts another program or requests a privileged operation, further checks may apply. Good service protection asks two related questions:
1. What does the service need to do to fulfill its intended role?
2. What should happen if it attempts something outside that role?
The first question requires practical knowledge of the application. The second requires controls that can distinguish expected behavior from access that should not be granted. AppArmor contributes to that second part, but an effective profile starts with the first.
Consider a small internal document service. Its ordinary job might be to read files from /srv/practice-site and return them to a client. It may also need access to shared libraries and a place for a runtime file. It should not need to read a colleague’s private documents merely because the service account happens to have permission to do so.
That example is a design exercise, not a ready-made policy. The actual executable, paths, and operating requirements of our practice service will be established in the lab. The important point is that a service’s purpose gives us a basis for deciding which access is justified.
Linux administrators are already familiar with discretionary access control, often abbreviated DAC. File ownership, group membership, permission bits, and access control lists are common mechanisms for deciding whether an account can access a file.
For example, a file may be readable by its owner, readable by members of its group, and inaccessible to others. A service running under a dedicated account must have the appropriate ordinary permissions to read that file. If those permissions do not allow access, adding an AppArmor rule does not make the file readable.
Discretionary controls are essential. A dedicated service account limits which ordinary permissions the service receives and makes ownership easier to reason about. Carefully chosen file permissions can prevent one service from reading another service’s data even before AppArmor is considered.
The limitation is that permissions are associated primarily with identities and objects, not with a detailed description of each program’s purpose. If an account can read several locations, a process running under that account may be able to read them as well, subject to other applicable checks. Accounts are therefore important boundaries, but they do not by themselves describe the complete behavior expected of a service.
Privileged processes introduce another reason to use layers. A service may start with elevated authority and later drop privileges, or it may require a narrowly defined privileged operation. The precise outcome of a DAC check depends on the process’s credentials and capabilities as well as the object’s permissions. AppArmor provides a separate policy mechanism that can constrain covered operations even when ordinary permissions would otherwise permit them.
AppArmor is a mandatory access control, or MAC, system. In this context, “mandatory” means that policy is enforced as a security control rather than left solely to a file owner’s choice of discretionary permissions. AppArmor is integrated with the Linux security framework and uses the kernel to apply policy to confined processes.
A useful simplified model is:
- Ordinary permissions determine whether the process’s credentials permit an operation.
- AppArmor policy determines whether the confined process is permitted to perform the covered operation.
- Other applicable security checks may also affect the result.
For an operation governed by both DAC and an enforcing AppArmor policy, permission from one layer does not override a denial from the other. A profile that allows a file read does not repair restrictive file ownership. Conversely, a world-readable file is not necessarily readable by a process whose enforced profile does not permit that read.
This model is deliberately simplified. Not every security decision is reducible to a single file rule, and the details depend on the operation, the…