Course contentsShow
← Linux
Lesson 999 of 1,8199. Security Hardening and Mandatory Access ControlFree lesson

Monitoring for Policy Bypass Attacks

Implement canary files and monitoring to detect attempts to bypass security policy constraints.

In this lesson, you will learn how to deploy "canary files" and integrated monitoring to detect when an attacker attempts to circumvent your Mandatory Access Control (MAC) policies.

The Canary Strategy

Even with a robust AppArmor profile, a sophisticated attacker might attempt to exploit kernel-level vulnerabilities or misconfigurations to "escape" or bypass your policy constraints. A canary file is a high-value, bait-like asset placed in a restricted location. Because it serves no functional purpose, any process attempting to read, write, or access this file acts as a high-fidelity signal that your security perimeter has been breached.

To be effective, the canary must be placed in a directory where a compromised application would logically try to look for sensitive data, such as a hidden system config or a simulated credential file.

Implementation and Monitoring

By leveraging auditd, you can trigger real-time alerts whenever a process interacts with these specific paths. Since you have already mastered Auditd and MAC Integration, you can configure a watch rule specifically for your canary:

# Place a canary file in a restricted zone
touch /etc/apparmor.d/canary_secret.key

# Add an audit rule to log any access attempt
auditctl -w /etc/apparmor.d/canary_secret.key -p wa -k policy_bypass_attempt

Once the watch is set, any attempt by a sandboxed process to touch this file will trigger an audit record. You should then configure your log aggregation system to treat this specific key (policy_bypass_attempt) as a critical security event.

If an AppArmor-constrained process accesses this file, it implies two things: either your profile's Advanced Globbing is too permissive, or the process has managed to elevate privileges or bypass the MAC enforcement entirely. By cross-referencing these logs with AppArmor Reporting and Compliance data, you can distinguish between a noisy, misconfigured profile and a genuine attempt to navigate around your security policy.

This creates a "tripwire" effect—you aren't just relying on the profile to stop the attacker; you are actively watching them navigate the trap you’ve set for them.

Key Takeaway: Canary files provide a low-noise, high-signal detection mechanism that flags malicious intent when standard MAC enforcement is being probed for weaknesses.