quentin.dufour.io/_posts/2017-08-22-hardening-lxc-co...

2.5 KiB

layout slug status sitemap title description disqus categories tags
post hardening-lxc-containers-running-systemd draft true Hardening LXC containers running systemd Especially with systemd in the equation false
security
linux
containers

LXC Logo

*By Mr. Rollers. License CC BY-NC-ND 2.0*

Hardening Linux Containers, and more especially LXC containers, is needed to prevent a malicious user to escape your container. But before starting, we need to understand how containers work under the hood.

As said by Jessie Frazelle in her blog post Setting the Record Straight: containers vs. Zones vs. Jails vs. VMs, containers in Linux are not a top level design like Zone in Solaris and Jails in BSD.

A "container" is just a term people use to describe a combination of Linux namespaces and cgroups. Linux namespaces and cgroups ARE first class objects. NOT containers.

In this article, we'll discuss the different "primitives" exposed by the Linux kernel like namespaces, cgroups, Linux Security Modules, capabilities and seccomp. Our container tool like LXC or Docker, which is a user space binary, will interact with these primitives. We'll see that we can interact with them through the LXC configuration file to improve (or worsen) the security of our LXC container.

The challenge when it comes to hardening a LXC container, compared to other solutions, is that there is a great probability that you'll run systemd in your container. And systemd heavily uses the primitives quoted before. Especially, systemd rely on cgroups to handle its services. We can also mention that many systemd daemon will be provided with a configuration that need to interact with the capabilities.

If you feel a bit lost with all these terms, a good start is the reading of this whitepaper by the NCCGroup: Understanding and Hardening Linux Containers. This post is also inspired by the article written by Christian Seiler, LXC containers without CAP_SYS_ADMIN under Debian Jessie, but we'll see that, due to evolutions in the Linux kernel, the proposed configuration does not work anymore out of the box.

Creating a standard LXC container