visit
One of the beauties of AppArmor is that it allows a Learning Mode which logs profile violations without preventing them proactively. The Learning Mode Log eventually helps administrators to create a security profile which forms a much hardened security armor based on an application's process execution. Default Security policies when clubbed with Learning Mode Logs, help forming security policies for even very complex applications in quick turnaround.AppArmor proactively protects the operating system and applications from external or internal threats and even zero-day attacks by enforcing a specific rule set on a per-application basis. Security policies completely define what system resources individual applications can access, and with what privileges. Access is denied by default if no profile says otherwise.
apparmor=1 security=apparmor
CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE=1 CONFIG_DEFAULT_SECURITY_APPARMOR=y
To load all AppArmor security profiles on boot, enable
apparmor.service
.The system default AppArmor comes with a number of security profiles, on top of which an administrator can add his own security profiles based on the Learning Mode. To check the list of AppArmor security profiles correctly loaded :
$ aa-enabled
------------
Yes
To display the current loaded status use
apparmor_status
:# apparmor_statusapparmor module is loaded.
29 profiles are loaded.
29 profiles are in enforce mode.
...
0 profiles are in complain mode.
0 processes have profiles defined.
0 processes are in enforce mode.
0 processes are in complain mode.
0 processes are unconfined but have a profile defined.
AppArmor allows a number of options using
apparmor_parser
to parse either its default or custom generated profiles. apparmor_parser
is widely used to load, unload, debug, remove, replace, cache and match-strings within profiles out of the other available options.-a
- Default Action to load a new profile in enforce mode.-C
- Loading a new profile in complain mode.-r
- Overwrite an existing profile.-R
- Remove an existing profile in the kernel.-V
- Display the profile version.-h
- Display reference guide.AppArmor profiles are text files found under
/etc/apparmor.d/
. A quick look into a profile file explains its execution as shown below:/etc/apparmor.d/usr.bin.test
#include <tunables/global>
profile test /usr/lib/test/test_binary
{
#include <abstractions/base>
# Main libraries and plugins
/usr/share/TEST/** r,
/usr/lib/TEST/** rm,
# Configuration files and logs
@{HOME}/.config/ r,
@{HOME}/.config/TEST/** rw,
}
Strings following the
@
symbol are variables defined under abstractions (/etc/apparmor.d/abstractions/
), tunables (/etc/apparmor.d/tunables/
) or by the profile itself. #include
includes other profile-files directly. Paths followed by a set of characters are access permissions while the Globbing Syntax helps with pattern matching.Commonly used command options on profile files :r
- reading dataw
- creating, deleting or write on an existing filex
- executing a filem
- memory mapping an executable fileCreating an AppArmor profile can be done through a Systemic or Stand-Alone method.
1) Stand-Alone Profile Creation
(
aa-genprof
) : Used for creating a profile affecting single program/application which runs for a finite amount of time, such as a web browsing client, mail client, etc. Though a Stand-Alone profile is comparatively quicker and easier to be developed, it comes with its own limitations as such the profiling is lost on a reboot. A Stand-Alone profile can be created through AppArmor's aa-genprof
profile generating utility. It runs aa-autodep
on the specified program/application by creating an approximate profile, sets it to complain mode, reloads it into AppArmor, marks the log, and prompts the user to execute the program and exercise its functionality.aa-genprof [ -d
/path/to/profiles
]
PROGRAM
2) Systemic Profile Creation
(
aa-autodep
): Used for creating a profile affecting multiple programs and/or applications that runs indefinitely or continuously across reboots, such as network server applications like mail servers, security policies, etc. This method updates all of the profiles on the system at once, as opposed to one or a few targeted by Stand-Alone profiling.Steps to create Systemic profile for a program :
aa-autodep
to create an approximate profile for a program - this lets AppArmor consider the program for monitoring.aa-complain /etc/apparmor.d/*
aa-logprof
./etc/apparmor.d/
as required.aa-enfore /etc/apparmor.d/*
which eventually enforces the rules of the profiles.aa-notify
aa-logprof
to update the policyIn case you would like to disable AppArmor for the current session, you can do so by clearing out all AppArmor profiles for the current session by
# aa-teardown.
Additionally, to prevent the kernel from loading AppArmor profiles at the next boot disable
apparmor.service
and remove apparmor=1 security=apparmor
from kernel parameters.AppArmor when implemented properly, provides an enhanced level of security to the deployed containers at a program level. There are endless possibilities of creating varied profiles through Learning Mode, and hence makes it stand apart from the system generated
docker-default
profile.