Seccomp & AppArmor 101
Seccomp is an important security feature of Linux that restricts the actions a program can and cannot do. To explain, picture a security guard at the entrance of an office. The security guard is responsible for making sure that only authorised people are allowed into the building and that they do what they are supposed to do. In this scenario, Seccomp is the security guard.
Seccomp allows you to create and enforce a list of rules of what actions (system calls) the application can make. For example, allowing the application to make a system call to read a file but not allowing it to make a system call to open a new network connection (such as a reverse shell).
These profiles are helpful because they reduce attackers' ability to execute malicious commands whilst maintaining the application's functionality. For example, a Seccomp profile for a web server may look like the following:
This Seccomp profile:
Allows files to be read and written to
Allows a network socket to be created
But does not allow execution (for example,
execve
)
To create a Seccomp profile, you can simply create a profile using your favourite text editor. This room will use nano
. An example Seccomp profile (profile.json) has been provided below. This profile will allow reading and writing access to files but no network connections.
With our Seccomp profile now created, we can apply it to our container at runtime by using the --security-opt seccomp
flag with the location of the Seccomp profile. For example:
Docker already applies a default Seccomp profile at runtime. However, this may not be suitable for your specific use case, especially if you wish to harden the container further while maintaining functionality. You can learn more about using Seccomp with Docker here.
AppArmor
AppArmor is a similar security feature in Linux because it prevents applications from performing unauthorised actions. However, it works differently from Seccomp because it is not included in the application but in the operating system.
This mechanism is a Mandatory Access Control (MAC) system that determines the actions a process can execute based on a set of rules at the operating system level. To use AppArmor, we first need to ensure that it is installed on our system:
With the output "apparmor module is loaded", we can confirm that AppArmor is installed and enabled. To apply an AppArmor profile to our container, we need to do the following:
Create an AppArmor profile
Load the profile into AppArmor
Run our container with the new profile
First, let's create our AppArmor profile. You can use your favourite text editor for this. Note that there are tools out there that can help generate AppArmor profiles based on your Dockerfile. However, this is out-of-scope for this room and can be "unreliable".
Provided below is an example AppArmor profile (profile.json) for an "Apache" web server that:
Can read files located in /var/www/, /etc/apache2/mime.types and /run/apache2.
Read & write to /var/log/apache2.
Bind to a TCP socket for port 80 but not other ports or protocols such as UDP.
Cannot read from directories such as /bin, /lib, /usr.
Now that we have created the AppArmor profile, we will need to import this into the AppArmor program to be recognised.
With our AppArmor profile now imported, we can apply it to our container at runtime by using the --security-opt apparmor
flag with the location of the AppArmor profile. For example:
Just like Seccomp, Docker already applies a default AppArmor profile at runtime. However, this may not be suitable for your specific use case, especially if you wish to harden the container further while maintaining functionality. You can learn more about using AppArmor with Docker here.
What's the Difference
Well, to put it briefly:
AppArmor determines what resources an application can access (i.e., CPU, RAM, Network interface, filesystem, etc) and what actions it can take on those resources.
Seccomp is within the program itself, which restricts what system calls the process can make (i.e. what parts of the CPU and operating system functions).
It's important to note that it is not a "one or the other" case. Seccomp and AppArmor can be combined to create layers of security for a container.
Last updated