An application starts, then refuses to open a file, a socket, or a directory while the Unix rights seem correct. On Ubuntu, AppArmor may block this action with a profile loaded in enforce mode.
Before modifying a profile, note the denial in the kernel messages and identify its name. You can then conduct a limited test in complain mode, and then restore protection to enforce once the rule is corrected.
Confirm that AppArmor is protecting the machine
Start by checking the status of the service and profiles. On Ubuntu, the module may be loaded while the diagnostic tool is missing. Install apparmor-utils if aa-status is not found, then rerun the command with sudo.
sudo aa-status
sudo systemctl status apparmor --no-pager
aa-status lists the loaded profiles and distinguishes between enforce and complain modes. Keep the displayed name in mind. The binary path and the profile name often look similar, but it is better to compare them before a command that changes the mode.
This method pertains to Ubuntu and Debian with AppArmor. On Rocky Linux, RHEL, or Fedora, first look for a SELinux event using the appropriate tools. Both mechanisms produce similar denials, but their profiles and commands remain different.
Read the denial in the kernel log
An AppArmor message typically contains apparmor="DENIED", the profile= field, and the targeted resource in name=. These are the three elements that link the denial to the concerned application.
sudo journalctl -k -b --no-pager | grep 'apparmor="DENIED"'
sudo dmesg | grep 'apparmor="DENIED"'
Use the first command on a machine with systemd. The second is handy when you need to directly read the kernel buffer. The guide dmesg on Linux explains how to filter these messages without confusing a warning with an error.
A denial may target a configuration file, a data directory, or a kernel capability. Do not deduce the rule to add based solely on the path. First, rerun the action that fails and keep the time of the test, this avoids modifying a profile based on an old event.
Temporarily switch the correct profile to complain
Complain mode allows the action while writing it to the logs. It is used to confirm a diagnosis on a VM, a test machine, or an application whose scope you control. On an exposed server, keep a copy of the profile before this change and limit the test to a few minutes.
APP='/usr/bin/application-name'
sudo cp "/etc/apparmor.d/usr.bin.application-name" /root/usr.bin.application-name.bak
sudo aa-complain "$APP"
sudo aa-status | grep -F "$APP"
Adapt the path of the profile file to that read in aa-status. The backup should target the actual profile, not a guessed variant. If the application runs during this test and a new DENIED appears, you have confirmed the scope of the profile to correct.
Reserve this mode for a short diagnosis. Leaving it in complain on a web service or an agent processing data makes the denial invisible to the application, without correcting the access intended.
Return to enforce after the correction
Add or adjust the rule in the profile after precisely identifying the expected access. Then reload this profile, set it back to enforce, and repeat the failed test. The log should remain silent for this action.
sudo apparmor_parser -r /etc/apparmor.d/usr.bin.application-name
sudo aa-enforce /usr/bin/application-name
sudo aa-status
sudo journalctl -k -b --no-pager | grep 'apparmor="DENIED"'
A final DENIED line may belong to the previous test. Reperform the operation that caused the issue, then rerun the search noting the time. The Ubuntu documentation on AppArmor details the complain and enforce modes. For a service restarted during the test, also check its status with systemctl.
A profile in enforce that produces no more denials during the targeted test remains the best result. Disabling AppArmor or keeping it in complain circumvents the symptom but does not correct the access intended by the application.