Carving a Channel

A thin trickle of water rolls down the side of a mountain. At first, the craggy mountain scatters the stream, and droplets fly every which way. Over time, however, the repetitive nature of the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Advanced Docker Security with AppArmor

So you have your Docker Containers deployed, which in turn are hosting critical applications of your organization? Great! So far, so good!

For the interest of the organization, it remains extremely crucial to keep not only the Containers but also the hosted applications protected from security threats. By default, a deployed Docker originally remains secured through an auto-generated profile docker-default for its containers. This profile however provides moderate security on the application level, and thus it remains highly recommended to implement a security profile through AppArmor which works at the process/program level of an application.

AppArmor (Application Armor) is a Linux Security Module that allows to implement security on a program/process level. Specifically developed security profiles through AppArmor can allow capabilities like folder access, network access, and the permission(or not) to read, write, or execute files.

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.

Though AppArmor comes inbuilt with all Linux Kernels, it is not by default the security profile loaded with every boot. Apparmor can be set as the default security profile on every boot by setting the following parameter on kernel :

apparmor=1 security=apparmor

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 :

Above you can see the loaded profiles and processes with their respective statuses.

-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:

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 data
w - creating, deleting or write on an existing file
x - executing a file
m - memory mapping an executable file

Creating an AppArmor profile can be done through a Systemic or Stand-Alone method.

(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

(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 few targeted by Stand-Alone profiling.

In 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.

Add a comment

Related posts:

My nose piercing fell out

The hole I was sure I had pierced through the glass ceiling had closed up. A list of 5 concerns I had while staring at the small twisted piece of silver metal that lay next to me after falling out in…