User Tools

Site Tools


howtos:apparmor_and_ubuntu
no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


howtos:apparmor_and_ubuntu [02/12/2018 21:34] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Introduction ======
 +AppArmor is a Linux Security Module implementation of name-based access controls. AppArmor confines individual programs to a set of listed files and posix 1003.1e draft capabilities.
  
 +AppArmor was first made available to Ubuntu in Ubuntu 7.04 in Universe.
 +
 +Further information about AppArmor can be found on the AppArmor project's [[http://apparmor.wiki.kernel.org|wiki]].
 +
 +====== Installation ======
 +===== Ubuntu 8.04 (Hardy) and Higher =====
 +AppArmor is installed and loaded by default in Hardy. Some packages will install their own '''enforcing''' profiles. Additional profiles can be found in the package ''apparmor-profiles'' from the Universe repository.  When filing bugs against an installed apparmor profile, please see: https://wiki.ubuntu.com/DebuggingApparmor
 +
 +====== Install additional AppArmor profiles ======
 +  * Enable the Universe repository.
 +  * Install [[apt://apparmor-profiles|apparmor-profiles]]. Click the link to install, or see InstallingSoftware for more installation options.
 +
 +
 +===== Ubuntu 7.10 (Gutsy) =====
 +AppArmor is installed and loaded by default in Gutsy. Some packages will install their own profiles. Additional profiles can be found in the package ''apparmor-profiles'' from the Universe repository.  When filing bugs against an installed apparmor profile, please see: https://wiki.ubuntu.com/DebuggingApparmor
 +
 +====== Install additional AppArmor profiles ======
 +  * Enable the Universe repository.
 +  * Install ''[[apt://apparmor-profiles|apparmor-profiles]]''. Click the link to install, or see InstallingSoftware for more installation options.
 +
 +===== Ubuntu 7.04 (Feisty) =====
 +AppArmor is not included by default in the Feisty kernel. It needs to be compiled manually.
 +  * 
 +  * Enable the Universe repository.
 +  * Install ''[[apt:apparmor-modules-source|apparmor-modules-source]]'' and ''[[apt:module-assistant|module-assistant]]'' packages. Click the links to install, or see InstallingSoftware for more installation options.
 +  * Compile the apparmor kernel module :
 +<code>
 +sudo m-a -v -t prepare
 +sudo m-a -v -t -f build apparmor-modules
 +sudo m-a -v -t install apparmor-modules
 +</code>
 +
 +  * Install ''[[apt://apparmor-profiles|apparmor-profiles]]'', ''[[apt://apparmor-utils|apparmor-utils]]'' and ''[[apt://apparmor|apparmor]]'' packages. Click the links to install, or see InstallingSoftware for more installation options.
 +
 +==== Installing the latest version ====
 +To install the latest apparmor packages on feisty, the packages have to be rebuilt. 
 +See [[https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/116627|latest apparmor utilities for feisty (LP #116627)]].
 +
 +==== Kernel upgrade / apparmor-module-source upgrade ====
 +When a new kernel is installed or when a new version of apparmor-module-source is installed, the apparmor module has to be recompiled :
 +
 +<code>
 +sudo m-a -v -t -f build apparmor-modules
 +sudo m-a -v -t install apparmor-modules
 +</code>
 +
 +In order to make sure that all running processes are protected, the system must then be rebooted.
 +
 +====== Usage ======
 +All of the following commands should be executed from a terminal.
 +
 +===== List the current status of apparmor =====
 +<code>
 +sudo apparmor_status
 +</code>
 +
 +===== Put a profile in complain mode =====
 +<code>
 +sudo aa-complain /path/to/bin
 +</code>
 +
 +Example:
 +
 +<code>
 +sudo aa-complain /bin/ping
 +</code>
 +
 +===== Put all profiles into complain mode =====
 +<code>
 +sudo aa-complain /etc/apparmor.d/*
 +</code>
 +
 +===== Put a profile in enforce mode =====
 +<code>
 +sudo aa-enforce /path/to/bin
 +</code>
 +
 +Example:
 +
 +<code>
 +sudo aa-enforce /bin/ping
 +</code>
 +
 +===== Put all profiles in enforce mode =====
 +<code>
 +sudo aa-enforce /etc/apparmor.d/*
 +</code>
 +
 +===== Put all profiles except for one in enforce mode =====
 +<code>
 +GLOBIGNORE="*profile.name"
 +sudo aa-enforce /etc/apparmor.d/*
 +</code>
 +
 +Example:
 +<code>
 +GLOBIGNORE="*bin.ping"
 +sudo aa-enforce /etc/apparmor.d/*
 +</code>
 +
 +===== Disable AppArmor framework =====
 +Systems should not generally need to have AppArmor disabled entirely. It is highly recommended that users leave AppArmor enabled and put the problematic profile into complain mode (see above), then file a bug using the procedures found in https://wiki.ubuntu.com/DebuggingApparmor. If AppArmor must be disabled (eg to use SELinux instead), users can:
 +
 +<code>
 +sudo invoke-rc.d apparmor kill
 +sudo update-rc.d -f apparmor remove
 +</code>
 +
 +On Ubuntu 8.10 (Intrepid) and Ubuntu 9.04 (Jaunty):
 +
 +<code>
 +sudo invoke-rc.d apparmor stop
 +sudo update-rc.d -f apparmor remove
 +</code>
 +
 +Using <code>kill</code> with Ubuntu 8.10 or later gives the following error:
 +<code>
 +Killing AppArmor module - failed, AppArmor is builtin: Failed.
 +</code>
 +
 +On Ubuntu 9.10 and later, you can either:
 +  * adjust your kernel boot command line (see /boot/grub/menul.lst for Grub or ```/boot/grub/grub.cfg``` for Grub 2) to include either
 +    * 'apparmor=0'
 +    * 'security=XXX' where XXX can be "" to disable AppArmor or an alternative LSM name, eg. 'security="selinux"'
 +  * remove the ```apparmor``` package with your package manager. Do not 'purge' apparmor if you think you might want to reenable AppArmor at a later date
 +
 +
 +===== Enable AppArmor framework =====
 +<code>
 +sudo invoke-rc.d apparmor start
 +sudo update-rc.d apparmor start 37 S .
 +</code>
 +
 +===== Reload all profiles =====
 +<code>
 +sudo invoke-rc.d apparmor reload
 +</code>
 +
 +===== Reload one profile =====
 +<code>
 +sudo apparmor_parser -r /etc/apparmor.d/profile.name
 +</code>
 +
 +Example:
 +<code>
 +sudo apparmor_parser -r /etc/apparmor.d/bin.ping
 +</code>
 +
 +===== Disable one profile =====
 +<code>
 +sudo ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/
 +sudo apparmor_parser -R /etc/apparmor.d/profile.name
 +</code>
 +
 +Example:
 +<code>
 +sudo ln -s /etc/apparmor.d/bin.ping /etc/apparmor.d/disable/
 +sudo apparmor_parser -R /etc/apparmor.d/bin.ping
 +</code>
 +
 +===== Enable one profile =====
 +By default, profiles are enabled (ie loaded into the kernel and applied to processes).
 +<code>
 +sudo rm /etc/apparmor.d/disable/profile.name
 +sudo apparmor_parser -r /etc/apparmor.d/profile.name
 +</code>
 +
 +Example:
 +<code>
 +sudo rm /etc/apparmor.d/disable/bin.ping
 +sudo apparmor_parser -r /etc/apparmor.d/bin.ping
 +</code>
 +
 +====== Profile customization ======
 +
 +Profiles can found in <code>/etc/apparmor.d</code>. These are simple text files and can be edited either with a text editor, or by using <code>aa-logprof</code>.
 +
 +Some customization can be made in <code>/etc/apparmor.d/tunables/</code>. When updating profiles, it is important to use these when appropriate. For example, rather than using a rule like:
 +<code>
 +  /home/*/ r,
 +</code>
 +use:
 +<code>
 +  @{HOME}/ r,
 +</code>
 +
 +After updating a profile, be sure to reload it (see above).
 +
 +===== Set home directories location =====
 +The location of home directories can be tuned in <code>/etc/apparmor.d/tunables/home</code>.
 +
 +====== FAQ ======
 +===== apparmor_status reports processes that are unconfined but have a profile defined =====
 +Restart the listed processes. Rebooting will also fix the problem.
 +
 +AppArmor can only track and protect processes that are started after the kernel module has been loaded. After the apparmor packages have been installed, apparmor will be started. But running processes won't be protected by AppArmor. Either restarting the processes or rebooting will fix this.
 +
 +You can also apply a profile to an already running process by issuing the following command:
 +<code>
 +sudo sh -c "echo 'setprofile /path/to/bin' > /proc/pid/attr/current"
 +</code>
 +
 +===== How can I enable AppArmor for Firefox? =====
 +Since Ubuntu 9.10 (Karmic), AppArmor ships with a profile for Firefox which is disabled by default.
 +
 +You can enable it using the following command:
 +<code>
 +sudo aa-enforce /etc/apparmor.d/usr.bin.firefox-3.5
 +</code>
 +
 +
 +====== Creating a new profile ======
 +===== Design a test plan =====
 +Try to think about how the application should be exercised. The test plan should be divided into small test cases. Each test case should have a small description and list the steps to follow.
 +
 +Some standard test cases are :
 + * starting the program
 + * stopping the program
 + * reloading the program
 + * testing all the command supported by the init script
 +In the case of graphical programs, your test cases should also include anything you normally do.  Downloading and opening files, saving files, uploading files, using plugins, saving configurations changes, and launching other programs are all possibilities.
 +
 +===== Generate the new profile =====
 +Use ''aa-genprof'' to generate a new profile.
 +
 +From a terminal, use the command ''aa-genprof'':
 +<code>
 +sudo aa-genprof executable
 +</code>
 +
 +Example:
 +<code>
 +sudo aa-genprof slapd
 +</code>
 +
 +The man page has more information: <code>man aa-genprof</code>.
 +
 +===== Include your new profile in apparmor-profiles package =====
 +To get your new profile included in the apparmor-profiles package, file a bug in Launchpad against the [[https://bugs.launchpad.net/ubuntu/+source/apparmor/+filebug|AppArmor package]]:
 +  * Include your test plan and testcases.
 +  * Attach your new profile to the bug.
 +
 +===== Migrating an apparmor-profiles profile to a package =====
 +Please see https://wiki.ubuntu.com/ApparmorProfileMigration
 +
 +
 +====== Update profiles ======
 +When the program is misbehaving, audit messages are sent to the log files. The program ''aa-logprof'' can be used to scan log files for AppArmor audit messages, review them and update the profiles.
 +<code>
 +sudo aa-logprof
 +</code>
 +
 +The man page has more information : <code>man aa-logprof</code>
 +
 +====== Debug AppArmor problems ======
 +When filing bugs against an installed apparmor profile, please see: https://wiki.ubuntu.com/DebuggingApparmor
 +
 +====== Resources ======
 +  * [[http://en.opensuse.org/AppArmor_Geeks|Intro to AppArmor for Geeks]] - detailed usage of apparmor.
 +  * [[http://outflux.net/blog/archives/2007/04/02/apparmor-now-in-feisty/|AppArmor now in Feisty]] - small tutorial about generating a new profile for evince.
 +
 +====== External Links ======
 +  * [[http://bodhizazen.net/aa-profiles/|AppArmor Profile Repository]] - Find some sample profiles for some common applications done by members of the Ubuntu community.
 +
 +
 +
 +----
 +----
 +
 +Source: https://help.ubuntu.com/community/AppArmor
howtos/apparmor_and_ubuntu.txt · Last modified: 02/12/2018 21:34 by 127.0.0.1