Everyday Guidebooks
Cover of Linux Debian

Cybersecurity & IT

Linux Debian: AppArmor for Service Protection

A Practical Guide to Inspecting, Testing, and Enforcing Service Profiles

by Todd Michael

Available now

A service can be running normally while still having more access than it needs. This practical guide shows you how to use AppArmor on Debian to examine and narrow that access with confidence.

Built around a repeatable service-protection lab, Linux Debian: AppArmor for Service Protection takes you from checking profile status to reading denial messages, writing focused rules, and testing the results. You’ll learn how complain and enforce modes differ, how to investigate file and capability requests, and why automatically accepting every suggested rule can undermine your policy.

Command examples and troubleshooting guidance help you work through common problems, while a staged enforcement checklist covers backups, representative testing, monitoring, and rollback. The book also explains how service changes and package updates can affect a profile over time.

Whether you administer a small server or are building practical skills for IT certification, you’ll finish with a disciplined approach to protecting services without losing sight of their operational needs.

Contents
  1. 1. Service Protection and the AppArmor Model
  2. 2. Build a Safe Debian Practice Environment
  3. 3. Inspect AppArmor and Service Status
  4. Start with the AppArmor overview
  5. Check the service unit
  6. Identify the running process
  7. Read the process confinement label
  8. Use the journal to add context
  9. Work through unexpected results
  10. Record a useful baseline
  11. 4. Read a Profile Before Changing It
  12. 5. Map What the Service Actually Needs
  13. Start with the service’s purpose
  14. Identify what systemd starts
  15. Build an access inventory
  16. Establish the ordinary operating tasks
  17. Turn the inventory into a test matrix
  18. Record results without jumping to rules
  19. Review the map before collecting more evidence
  20. 6. Observe Behavior in Complain Mode
  21. 7. Find and Interpret Denials
  22. 8. Write Focused File Access Rules
  23. Read the service's primary configuration at startup.
  24. 9. Handle Execution, Capabilities, and Other Requests
  25. 10. Use Profile Tools Without Surrendering Judgment
  26. 11. Test, Refine, and Document the Policy
  27. Establish a Testable Baseline
  28. Turn the Inventory into a Test Run
  29. Compare Success, Failure, and Policy Evidence
  30. Refine One Decision at a Time
  31. Review Grants as Carefully as Denials
  32. Keep a Decision-Oriented Change Log
  33. Perform a Regression Review
  34. Prepare the Policy for Enforcement Review
  35. 12. Move from Complain Mode to Enforcement
  36. 13. Troubleshoot Enforcement and Maintain Profiles
  37. 14. Capstone: Protect a Second Service
  38. Other Books by Todd Michael

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…

More Cybersecurity & IT

Cover of The White Hat Bible, Volume 1The White Hat Bible, Volume 1Available nowCover of The White Hat Bible, Volume 2The White Hat Bible, Volume 2Available nowCover of The White Hat Bible, Volume 3The White Hat Bible, Volume 3Available nowCover of The White Hat Bible, Volume 4The White Hat Bible, Volume 4Available nowThe White Hat Bible, Volume 5Available nowCover of The White Hat Pocket GuideThe White Hat Pocket GuideAvailable now

About Todd Michael

Todd Michael is an American author and the founder of ToddMichael.tv. He writes practical, plain-English books on money, health, preparedness, technology, games, humor and more.

About the author Todd Michael · Todd Michael’s author site

Part of the ToddMichael.tv network.