Debian 13 Tutorial / Diagnose AppArmor Denials in enforce and complain Modes
Even if a file is readable based on file permissions in Debian 13, access by a program can be denied if the AppArmor profile does not allow it. Enforce mode enforces the policy, while complain mode tracks access attempts lacking allow rules and monitors them, so you need to check the mode, execution path, and denial logs together.
Distinguish File Permissions from AppArmor Policy
AppArmor is a Linux security feature that restricts the resources a program can access through profiles. In addition to DAC (Discretionary Access Control) based on owner, group, and general permission bits, it applies MAC (Mandatory Access Control) policies to programs. Just because AppArmor allows access does not mean denials from existing file permissions are removed.
Here, we copy the cat executable to a dedicated path and attach a profile only to that copy. We do not modify the original /usr/bin/cat, SSH, or system-wide security settings. Two harmless test files are created with the same permissions, and it is observed whether the policy affects results when the same user runs the dedicated program. Actual secret files are not used.
This is not an example of restricting read access for the entire account. Users can read test files with the original cat command without being bound to a profile. This is a comparison to understand program-specific restrictions, and to protect important data across the entire account or process, you need to design file permissions along with the actual service execution path. Refer to the basic concepts and modes in the Debian AppArmor documentation.
Check AppArmor and the Dedicated Lab Paths
cat /sys/module/apparmor/parameters/enabled
systemctl is-active apparmor.service
dpkg-query -W apparmor
sudo aa-status
ls -l /usr/local/libexec/lf-aa19-reader /etc/apparmor.d/lf-aa19-reader
ls -ld /srv/lf-aa19
This practice was carried out on a Debian 13 VM with AppArmor 4.1.0, AppArmor kernel parameter Y and apparmor.service active. Do not assume that writing profile files alone on a system with AppArmor disabled will provide the same protection. You need to check the kernel, boot configuration, and installation status first.
In aa-status, distinguish the number and mode of profiles and the processes to which they are applied. The fact that a program name is on the list does not necessarily mean that the program is installed, running, or receiving enforce-mode protection. There were enforce, complain, and unconfined mode profiles together in this environment as well. If a practice path already exists, check the previous content without overwriting it with a new task.
Prepare Two Equally Readable Files and a Dedicated Reader
Execute the following in an account with sudo privileges. Ensure that the test folder does not exist and that the path is not being used by another task.
sudo test ! -e /srv/lf-aa19 &&
sudo install -d -m 755 /srv/lf-aa19 &&
printf 'allowed-example\n' | sudo tee /srv/lf-aa19/allowed.txt > /dev/null &&
printf 'restricted-example\n' | sudo tee /srv/lf-aa19/restricted.txt > /dev/null &&
sudo chmod 644 /srv/lf-aa19/allowed.txt /srv/lf-aa19/restricted.txt &&
sudo install -d /usr/local/libexec &&
sudo test ! -e /usr/local/libexec/lf-aa19-reader &&
sudo install -m 755 /usr/bin/cat /usr/local/libexec/lf-aa19-reader
cmp /usr/bin/cat /usr/local/libexec/lf-aa19-reader
ls -ld /srv/lf-aa19
ls -l /srv/lf-aa19/allowed.txt /srv/lf-aa19/restricted.txt
If the prerequisites for folder creation or file copying fail, stop and check the existing contents. Both files are owned by the administrator with 644 permissions, and the folder is 755, so ordinary users can also read the files. This copy is a practice file separate from the system cat, and it is not an operational program where package updates are automatically applied. Delete it after practice.
Run these commands in a regular-user terminal as lfstudent. Another account can be used if it has the same ordinary read permissions.
/usr/local/libexec/lf-aa19-reader /srv/lf-aa19/allowed.txt
/usr/local/libexec/lf-aa19-reader /srv/lf-aa19/restricted.txt
Since the profile for this path has not been loaded yet, the contents of both files should be output. If this criterion is not checked first, it will be difficult to distinguish later whether a failure is due to regular permission issues or AppArmor policies.
Write and Validate the Complete Profile Before Loading
Create a new file as sudo nano /etc/apparmor.d/lf-aa19-reader and save the entire following contents. If nano is not available, you can use another editor. If a file with the same name or a loaded profile with the same name already exists, do not apply it.
#include <tunables/global>
profile lf-aa19-reader /usr/local/libexec/lf-aa19-reader {
#include <abstractions/base>
/usr/local/libexec/lf-aa19-reader mr,
/srv/lf-aa19/allowed.txt r,
}
The profile name is lf-aa19-reader, and the path that follows is the executable file to which the profile will be linked. r is for read permissions, and m is for executable memory mapping permissions. The base abstraction includes common access rules necessary for program execution. Here, note that there is no permission given for restricted.txt. No explicit deny rules have been added.
The path, commas, and include structure follow the apparmor.d profile syntax . Do not use this short example as a completed security policy for other complex services. If the required libraries, files, or process transitions differ, the allowed scope will also differ.
sudo apparmor_parser -Q -K /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
-Q is processed without being loaded into the kernel, and -K does not use cache reads or writes. Even if the first command finishes without errors, this profile should not exist for the second lookup yet. A non-matching exit code from grep is the expected result at this stage. If the check fails, modify and recheck, but passing the check does not guarantee the desired access policy.
sudo apparmor_parser -r -K /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
After loading or replacing the profile with -r, check lf-aa19-reader (enforce). Command options can be found in the apparmor_parser documentation . From now on, the newly executed dedicated read program is the target.
Match an enforce Denial to Its Kernel Log
Run the same two requests again from a regular user terminal. Loading the profile requires admin privileges, but the file read comparison is carried out as the same user as before.
/usr/local/libexec/lf-aa19-reader /srv/lf-aa19/allowed.txt
/usr/local/libexec/lf-aa19-reader /srv/lf-aa19/restricted.txt
echo $?
The file allowed.txt is expected to be displayed, while restricted.txt is expected to show Permission denied with exit code 1. Since the file permissions were not changed, this difference can be linked to the policy. Check the kernel log with administrative privileges.
sudo journalctl -k --since '-5 minutes' --no-pager | grep 'profile="lf-aa19-reader"'
The key fields of denials observed in the exercise are as follows. PID, timestamp, and user ID vary depending on the execution environment, so only the fields necessary for comparison are shown.
apparmor="DENIED" operation="open" profile="lf-aa19-reader" name="/srv/lf-aa19/restricted.txt" requested_mask="r" denied_mask="r"
Verify whether the profile, file path, and requested permissions match the operation you just performed. If there is no log, check the time range, kernel log access permissions, and whether the profile is actually linked. Not all failures, from missing files to DAC denials, are recorded in the same AppArmor log. Using unchecked chmod 777 or disabling AppArmor entirely is not a solution for troubleshooting.
Compare Allowed Access and Logging in complain Mode
Reload only the dedicated exercise profile in complain mode.
sudo apparmor_parser -r -C -K /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
After checking the complain display, try reading restricted.txt again as a regular user.
/usr/local/libexec/lf-aa19-reader /srv/lf-aa19/restricted.txt
echo $?
This time, the content is expected to be displayed, with exit code 0. Checking the kernel log again will show apparmor="ALLOWED" recorded with the same profile and path. In this exercise, we confirmed that a read without an actual allow rule can succeed and still be logged.
complain mode does not provide the same blocking behavior as enforce. However, explicit deny rules can still deny access in complain mode. Therefore, this comparison used the omission of allow rules without using explicit deny. If you change all accesses observed in the logs to allow rules unconditionally, it may include incorrect accesses of the program in the policy. First, determine whether the action is actually required.
sudo apparmor_parser -r -K /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
After finishing the comparison, check if it has returned to enforce. This command is the method of restoration in this example where there is no complain flag in the file's profile. If other profiles have permanent mode settings, you should check those settings as well.
Allow One Exact Path, Then Restore the Restriction
Only add the exact path if reading restricted.txt is determined to be a legitimate function of the program. Do not start by broadly opening an entire folder like /srv/** r,. Keep the original profile so it can be restored to the full content shown above, then add a line just below the allowed.txt rules of /etc/apparmor.d/lf-aa19-reader, before the closing brace.
/srv/lf-aa19/restricted.txt r,
sudo apparmor_parser -Q -K /etc/apparmor.d/lf-aa19-reader
sudo apparmor_parser -r -K /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
If you execute the same restricted.txt read again as a normal user while keeping enforce, it should succeed. This is the result of allowing only the necessary access without changing file permissions or overall security functionality. To revert, remove only the added line, validate the profile with -Q -K, reload with -r -K and confirm that the same read is denied again. In the exercise, this allowance and reversion were also compared.
First, check whether the actual package profile includes the local/ supplementary file. You can only manage local rules in that path if such an include exists. Do not just create a file assuming a non-existent include connection, or directly modify the common abstractions/base, as this could affect other profiles that include it.
Unload and Remove Only the Lab Profile
The reader exits after each request. Once the lab reader has finished, unload its profile from the kernel before deleting the profile file.
sudo apparmor_parser -R /etc/apparmor.d/lf-aa19-reader
sudo grep '^lf-aa19-reader ' /sys/kernel/security/apparmor/profiles
-R removes the profile. After confirming that it no longer appears in queries, run the dedicated program as a normal user to read restricted.txt again. This result demonstrates a comparison showing that the policy has been removed, not that the file's general permissions have been strengthened.
sudo rm -- /etc/apparmor.d/lf-aa19-reader /usr/local/libexec/lf-aa19-reader
sudo rm -- /srv/lf-aa19/allowed.txt /srv/lf-aa19/restricted.txt
sudo rmdir -- /srv/lf-aa19
systemctl is-active apparmor.service
sudo aa-status
The AppArmor service and existing profiles should be maintained. In this exercise’s verification, it was confirmed by comparing the profile names and mode lists before and after that they were preserved as is. Cleanup is not about turning off all features; it only removes the profile, executable, and test data created this time.




