Это старая версия документа.


AppArmor

AppArmor - это реализация Модуля безопасности линукс по управлению доступом на основе имен. AppArmor ограничивает отдельные программы набором перечисленных файлов и возможностями в соответствии с правилами Posix 1003.1e.

AppArmor устанавливается и загружается по умолчанию. Он использует профили приложений для определения какие файлы и права доступа требуются приложению. Некоторые пакеты устанавливают свои собственные профили, а дополнительные профили можно найти в пакете apparmor-profiles.

Для установки пакета apparmor-profiles наберите в терминале:

sudo apt-get install apparmor-profiles

Профили AppArmor имеют два режима выполнения:

  1. Фиксации/Обучения: нарушения профиля разрешаются и сохраняются в журнале. Полезно для тестирования и разработки новых профилей

  2. Предписаний/Ограничений: принуждает следовать политике профиля, при этом также записывает нарушения в журнал.

Использование AppArmor

Пакет apparmor-utils содержит утилиты командной строки, которые можно использовать для изменения режима выполнения AppArmor, поиска статуса профиля, создания новых профилей и т.д.

1. apparmor_status используется для просмотра текущего статуса профиля AppArmor.

sudo apparmor_status

2. aa-complain переводит профиль в режим сравнения.

sudo aa-complain /path/to/bin

3. aa-enforce переводит профиль в принудительный режим работы.

sudo aa-enforce /path/to/bin

4. Профили AppArmor по умолчанию расположены в директории /etc/apparmor.d. Эту директорию можно использовать для настройки режимов всех профилей.

Введите следующую команду для перевода всех профилей в режим сравнения:

sudo aa-complain /etc/apparmor.d/*

Перевод всех профилей в принудительный режим работы:

sudo aa-enforce /etc/apparmor.d/*

5. Команда apparmor_parser используется для загрузки профиля в ядро. Она также может использоватся для перезагрузки недавно загруженного профиля при использовании опции '-r'. Для загрузки введите:

cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a

Для перезагрузки:

cat /etc/apparmor.d/profile.name | sudo apparmor_parser -r

6. /etc/init.d/apparmor служит для перезагрузки всех профилей:

sudo /etc/init.d/apparmor reload

7. Директория /etc/apparmor.d/disable может использоваться совместно с опцией '-r' apparmor_parser для отключения профиля.

sudo ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/profile.name

Для активации отключенного профиля удалите символическую ссылку на профиль в /etc/apparmor.d/disable/. Затем загрузите профиль используя опцию '-a'.

sudo rm /etc/apparmor.d/disable/profile.name
cat /etc/apparmor.d/profile.name | sudo apparmor_parser -a

8. AppArmor можно отключить, а модуль ядра выгрузить следующей командой:

sudo /etc/init.d/apparmor stop
sudo update-rc.d -f apparmor remove

Для включеня AppArmor введите: <code>sudo /etc/init.d/apparmor start sudo update-rc.d apparmor defaults<code>

Замените profile.name на имя вашего профиля, который вы хотите настроить. Также необходимо заменить /path/to/bin/ на реальный путь выполнения файла. Например, для команды ping используйте /bin/ping

Профили

Профили AppArmor - это простые текстовые файлы, которые расположены в /etc/apparmor.d/. The files are named after the full path to the executable they profile replacing the «/» with «.». For example /etc/apparmor.d/bin.ping is the AppArmor profile for the /bin/ping command.

There are two main type of rules used in profiles:

  Path entries: which detail which files an application can access in the file system.
  Capability entries: determine what privileges a confined process is allowed to use.

As an example take a look at /etc/apparmor.d/bin.ping:

#include <tunables/global> /bin/ping flags=(complain) {

#include <abstractions/base>
#include <abstractions/consoles>
#include <abstractions/nameservice>
capability net_raw,
capability setuid,
network inet raw,

/bin/ping mixr,
/etc/modules.conf r,

}

  #include <tunables/global>: include statements from other files. This allows statements pertaining to multiple applications to be placed in a common file.
  /bin/ping flags=(complain): path to the profiled program, also setting the mode to complain.
  capability net_raw,: allows the application access to the CAP_NET_RAW Posix.1e capability.
  /bin/ping mixr,: allows the application read and execute access to the file.

After editing a profile file the profile must be reloaded. See Using AppArmor for details.

Создание профиля

  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 commands supported by the init script.
  Generate the new profile: Use aa-genprof to generate a new profile. From a terminal:
  sudo aa-genprof executable
  For example:
  sudo aa-genprof slapd
  To get your new profile included in the apparmor-profiles package, file a bug in Launchpad against the AppArmor package:
      Include your test plan and test cases.
      Attach your new profile to the bug.

Обновление профилей

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. From a terminal:

sudo aa-logprof

Ссылки

  See the AppArmor Administration Guide for advanced configuration options.
  For details using AppArmor with other Ubuntu releases see the AppArmor Community Wiki page.
  The OpenSUSE AppArmor page is another introduction to AppArmor.
  A great place to ask for AppArmor assistance, and get involved with the Ubuntu Server community, is the #ubuntu-server IRC channel on freenode.