SlideShare a Scribd company logo
Practical Container Security
Mrunal Patel
Principal Software Engineer
Thomas Cameron
Cloud Strategy Evangelist
AGENDA
3
AGENDA
Containers and Security
INTRODUCTION
Who are we, and why should you care? What makes up container security?
RED HAT AND CONTAINERS
A brief history
KERNEL NAMESPACES
What are they?
WHAT ARE CONTAINERS?
How do they work?
WHAT ARE CONTAINERS NOT?
Mythbusting
CONTAINER SECURITY
4
AGENDA
Containers and Security
CONTROL GROUPS
What are they?
THE DOCKER DAEMON
How it works and the security it provides
LINUX KERNEL CAPABILITIES
libcap and how Docker deals with it
SELINUX
What it is, what it does, and why it matters
TIPS AND TRICKS
What do do, and what not to do.
THE DOCKER DAEMON CONCLUSIONS
Go forth and contain!
INTRODUCTION
6
INTRODUCTION
Who am I, and why should you care?
My name is Thomas Cameron, and I'm the global solutions architect leader at Red
Hat.
●
In IT since 1993
●
I was a police officer before that, educational background is in law enforcement &
security
●
At Red Hat since 2005
●
Red Hat Certified Architect, Red Hat Certified Security Specialist, and other certs
●
In the past, I was an MCSE, a MCT, and a CNE
●
Spent a lot of time focusing on security in organizations like banks, manufacturing
companies, e-commerce, etc.
●
I do NOT know everything. But I have some pretty impressive scars.
RED HAT AND CONTAINERS
8
RED HAT AND CONTAINERS
A brief history
Red Hat has been working on container technologies since before 2010
●
Makara acquisition 2010 – PaaS
●
Rebranded as OpenShift
●
“Cartridges” using SELinux, cgroups, kernel namespaces
●
Docker came to prominence in 2013(-ish)
●
Docker gained community adoption and we started participating in 2013.
Meritocracy rules!
●
Red Hat is a top contributor to Docker (#2 behind Docker at last check)
9
RED HAT AND CONTAINERS
A brief history
Industry adoption of Docker is incredible
●
Docker has been through multiple successful venture capital rounds
●
Apcera, Cisco, EMC, Fujitsu Limited, Goldman Sachs, HP, Huawei, IBM, Intel,
Joyent, Mesosphere, Pivotal, Rancher Labs, Red Hat and VMware are all on board
with container standardization with Docker.
10
RED HAT AND CONTAINERS
A brief history
Industry adoption of Docker is incredible
●
Even Microsoft announced that they will support Docker containers!
11
WHAT ARE CONTAINERS?
13
WHAT ARE CONTAINERS?
How do they work?
Containerization, specifically Docker, is a technology which allows applications (web,
database, app server, etc.) to be run abstracted from, and in some isolation from, the
underlying operating system. The docker service can launch containers regardless of
the underlying Linux distro.
Containers can enable incredible application density, since you don't have the
overhead of a full OS image for each app. Linux control groups also enable maximum
utilization of the system.
The same container can run on different versions of Linux
●
Ubuntu containers on Fedora
●
CentOS containers on RHEL
14
WHAT ARE CONTAINERS?
How do they work?
OK, maybe not...
Containers make it really easy for application developers to build and deploy apps.
WHAT ARE CONTAINERS
NOT?
16
WHAT ARE CONTAINERS NOT?
Mythbusting
Containers are not a panacea. They are not “the cure to all that ails you!”
17
WHAT ARE CONTAINERS NOT?
Mythbusting
Containers are not a fit for every application.
18
WHAT ARE CONTAINERS NOT?
Mythbusting
They are not virtualization. You can run containers on an OS on bare metal.
CONTAINER SECURITY
20
CONTAINER SECURITY
What makes up container security?
Containers use several mechanisms for security:
●
Linux kernel namespaces
●
Linux Control Groups (cgroups)
●
The Docker daemon
●
Linux capabilities (libcap)
●
Linux security mechanisms like AppArmor or SELinux
KERNEL NAMESPACES
22
LINUX KERNEL NAMESPACES
What are they?
Namespaces are just a way to make a global resource appear to be unique and
isolated. The namespaces that the Linux kernel can manage are:
●
Mount namespaces
●
PID namespaces
●
UTS namespaces
●
IPC namespaces
●
Network namespaces
●
User namespaces
MOUNT NAMESPACES
24
LINUX KERNEL NAMESPACES
What are they?
Mount namespaces allow a container to “think” that a directory which is actually
mounted from the host OS is exclusively the container's.
When you start a container with the -v [host-path]:[container-path]:[rw|ro] argument,
you can mount a directory from the host in the container. The container “sees” the
directory in its own mount namespace, not knowing that it is actually on the host. So
multiple containers could, for instance use the host's /var/www/html directory without
having to copy content to all the containers.
25
PID NAMESPACES
27
LINUX KERNEL NAMESPACES
What are they?
PID namespaces let the container think it's a new instance of the OS. When you start
a container on a host, it will get a new process ID. PID namespaces enable the
container to “see” the PIDs inside the container as unique, as if the container were its
own instance of an OS.
In the following example, I launch a Fedora container running bash, and run “ps ax”
The container only “sees” its own PID namespace, so the bash process exists within
the container as PID 1. On the host, however, the docker process is PID 18557:
28
29
USER NAMESPACES
31
LINUX KERNEL NAMESPACES
What are they?
When you start a container, assuming you've added your user to the docker group,
you start it as your user account. In the following example, I start the container as
tcameron. Once the container is started, my user inside the container is root. This is
an example of user namespaces.
32
NETWORK NAMESPACES
34
LINUX KERNEL NAMESPACES
What are they?
Network namespaces allow a container to have its own IP address, independent of
that of the host. These addresses are not available from outside of the host, this is
private networking similar to that of virtualization. The Docker service sets up an
iptables masquerading rule so that the container can get to the rest of the Internet.
In the following query, I find that my Fedora instance has the address 172.17.0.7,
even though the host doesn't have an address associated with the ethernet interface:
35
IPC NAMESPACES
37
LINUX KERNEL NAMESPACES
What are they?
IPC namespaces do the same thing with interprocess communications. My container
has no IPCs mapped, but my host has many:
38
39
UTS NAMESPACES
41
LINUX KERNEL NAMESPACES
What are they?
UTS (UNIX Timesharing System) namespaces let the container “think” it's a separate
OS, with its own hostname and domain name:
42
43
CONTROL GROUPS
45
CONTROL GROUPS
What are they?
From the documentation at
https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt:
“Control Groups provide a mechanism for aggregating/partitioning sets of tasks, and
all their future children, into hierarchical groups with specialized behavior.”
This allows us to put various system resources into a group, and apply limits to it, like
how much disk IO, CPU use, memory use, network use, namespaces, and so on. In
the case of containers, the resources are those assigned to that container.
46
CONTROL GROUPS
What are they?
This ensures that, even if a container is compromised (or just spins out of control),
there are limits in place which minimizes the risk of that misbehaved container
impacting the host or other containers.
47
CONTROL GROUPS
What are they?
Note that when I run the command systemctl status docker.service, I get the control
group and slice information:
48
49
CONTROL GROUPS
What are they?
You can navigate the /sys/fs/cgroup/ pseudo-directory to see what resources are
allocated to your containers.
There are over 8500 entries in this directory on my system, so it is not practical to talk
about the details of individual cgroups, but you can get information about memory,
cpu, block I/O, network I/O, and so on here.
50
THE DOCKER DAEMON
52
THE DOCKER DAEMON
How it works and the security it provides
The docker daemon (/usr/bin/docker) is responsible for managing the control groups,
orchestrating the namespaces, and so on so that docker images can be run and
secured.
Because of the need to manage kernel functions, Docker runs with root privileges. Be
aware of this!
53
THE DOCKER DAEMON
How it works and the security it provides
There are some considerations for running Docker:
●
Only allow trusted users to run docker. The Docker documentation recommends
that you add users to the docker group so they can run docker commands. With
this flexibility comes risk. Make sure you only delegate this ability to trusted users.
Remember that they can mount the host filesystem in their container with root
privileges!
●
If you are using the REST API to manage your host(s), make sure you do not have
vulnerabilities exposed. Ensure you have strong authentication.
●
Use SSL if you are going to expose the REST API over http. Don't expose it except
to secured networks or VPN.
LINUX KERNEL CAPABILITIES
(libcap)
55
LINUX KERNEL CAPABILITIES
libcap and how Docker deals with it
The root user historically had the ability to do anything, once authenticated. Linux
capabilities is a set of fine grained controls which allow services or even users with
root equivalence to be limited in their scope.
It also allows non-root users to be granted extra privileges. A regular user, for
instance, could be granted the net_bind_service capability and they could bind a
service to a privileged port (below 1024).
56
LINUX KERNEL CAPABILITIES
libcap and how Docker deals with it
In containers, many of the capabilities to manage network and other services are not
actually needed. SSH services, cron, services, filesystem mounts and unmounts are
not needed, network management is not needed, etc.
By default, Docker disallows many root capabilities, including the ability to modify
logs, change networking, modify kernel memory, and the catch-all CAP_SYS_ADMIN.
57
SELINUX
59
SELINUX
What it is, what it does, and why it matters
Security Enhanced Linux (SELinux) is a mandatory access control system.
Processes, files, memory, network interfaces, and so on are labeled, and there is a
policy which is administratively set and fixed.
That policy will determine how processes can interact with files, each other, network
ports, and the like.
60
SELINUX
What it is, what it does, and why it matters
SELinux is primarily concerned with labeling and type enforcement. For a mythical
service “foo,” the executable file on disk might have the label foo_exec_t. The startup
scripts for foo might have the label foo_config_t. The log files for foo might have the
label foo_log_t. The data for foo might have the label foo_data_t. When foo is running,
the process in memory might have the label foo_t.
Type enforcement is the rule set that says that when a process running in the foo_t
context tries to access a file on the filesystem with the label foo_config_t or
foo_data_t, that access is allowed. When the process with the label foo_t tries to write
to a log file with the foo_log_t, that would be allowed, as well. Any other access,
unless explicitly allowed by policy, is denied.
61
SELINUX
What it is, what it does, and why it matters
If the foo process, running in the foo_t context tries to access, for instance, the
directory /home/tcameron, with the label user_home_dir_t, even if the permissions are
wide open, the policy will stop that access.
SELinux labels are stored as extended attributes on the filesystem, or in memory.
62
SELINUX
What it is, what it does, and why it matters
SELinux labels are stored in the format:
●
selinux_user:selinux_role:selinux_type:mls:mcs
So for the mythical “foo” service, the full syntax for the label of the running process
might be:
●
user_u:object_r:foo_t:s0:c0
63
SELINUX
What it is, what it does, and why it matters
The default policy for SELinux is “targeted.” In the targeted policy, we don't use the
SELinux user or role, so we'll ignore them for today. We will also ignore the MLS
(multilevel security) label, since that is only used in the MLS policy (think top secret
vs. secret in the military).
We really only care about the type (remember, type enforcement) and the MCS label.
Think of MCS labels as extra identifiers. In SELinux for containers, we can be very
granular about which processes can access which other processes.
These are different labels:
●
user_u:object_r:foo_t:s0:c0
●
user_u:object_r:foo_t:s0:c1
64
SELINUX
What it is, what it does, and why it matters
Type enforcement says that a process with the first label is different from the process
with the second. So policy would prevent them from interacting. Also, there is no
policy allowing a process running with those labels to access the filesystem unless it
is labeled with foo_config_t or foo_content_t or another defined label.
Neither of those processes would be able to access /etc/shadow, which has the label
shadow_t.
65
SELINUX
What it is, what it does, and why it matters
On a standalone system running Docker, all of the containers run in the same context
by default. In Red Hat's PaaS offering, OpenShift, this is not the case. Each Openshift
container runs in its own context, with labels like:
●
staff_u:system_r:openshift_t:s0:c0,c1
●
staff_u:system_r:openshift_t:s0:c2,c3
●
staff_u:system_r:openshift_t:s0:c4,c5
So, even if someone were to gain access to the docker container process on the host,
SELinux would prevent them from being able to access other containers, or the host.
66
SELINUX
What it is, what it does, and why it matters
In the following example, I emulate an exploit where someone takes over a container.
I use runcon (run in the context) to set my context to that of an Openshift container.
I attempt to access /etc/shadow (shadow_t label). I try to write to the filesystem. I try
to read the contents of a user's home directory.
67
TIPS AND TRICKS
69
TIPS AND TRICKS
What to do, and what not to do
Containers are, at the end of the day, just processes running on the host. Use
common sense.
70
TIPS AND TRICKS
What to do, and what not to do
Do:
●
Have a process in place to update your containers. Follow it.
●
Run services in the containers with the lowest privilege possible. Drop root
privileges as soon as you can.
●
Mount filesystems from the host read-only wherever possible.
●
Treat root inside the container just like you would on the host.
●
Watch your logs.
71
TIPS AND TRICKS
What to do, and what not to do
Don't:
●
Download any old container you find on the 'net.
●
Run SSH inside the container.
●
Run with root privileges.
●
Disable SELinux.
●
Roll your own containers once, and never maintain them.
●
Run production containers on unsupported platforms.
CONCLUSION
73
CONCLUSION
Go forth and contain!
Containers are incredibly cool. They make application deployment really, really easy.
They leverage some incredible capabilities within the Linux kernel. By design, they
are relatively secure, but there are some gotchas.
As with every other piece of software out there, docker tech requires some feeding
and maintenance. Well maintained, containers can make your business more agile,
less complex, and safe.
Thank you!

More Related Content

PDF
Infinit's Next Generation Key-value Store - Julien Quintard and Quentin Hocqu...
PDF
DockerCon EU 2015: Monitoring Docker
PPTX
Experiences with AWS immutable deploys and job processing
PDF
On-the-Fly Containerization of Enterprise Java & .NET Apps by Amjad Afanah
PDF
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
PDF
Highly Available Persistent Applications in Containers by Kendrick Coleman, E...
PPTX
Docker Datacenter Overview and Production Setup Slides
PDF
DockerCon EU 2015: Day 1 General Session
Infinit's Next Generation Key-value Store - Julien Quintard and Quentin Hocqu...
DockerCon EU 2015: Monitoring Docker
Experiences with AWS immutable deploys and job processing
On-the-Fly Containerization of Enterprise Java & .NET Apps by Amjad Afanah
Microservices + Events + Docker = A Perfect Trio by Docker Captain Chris Rich...
Highly Available Persistent Applications in Containers by Kendrick Coleman, E...
Docker Datacenter Overview and Production Setup Slides
DockerCon EU 2015: Day 1 General Session

What's hot (20)

PPTX
Docker Practice in Alibaba Cloud by Li Yi (Mark) & Zuhe Li (Sogo)
PPTX
Docker Roadshow 2016
PDF
Intro to docker - innovation demo 2022
PDF
Docker in Production, Look No Hands! by Scott Coulton
PPTX
DockerCon EU 2015: Nesting Containers: Real Life Observations
PDF
Securing your Containers
PDF
Docker on Docker
PDF
How to accelerate docker adoption with a simple and powerful user experience
PPTX
Docker Container Lifecycles, Problem or Opportunity? by Baruch Sadogursky, JFrog
PDF
Docker Datacenter - CaaS
PDF
Docker Online Meetup: Infrakit update and Q&A
PDF
DockerCon SF 2015: DHE/DTR
PPTX
Introduction to Docker - 2017
PPTX
DockerCon 16 General Session Day 1
PPTX
Using the SDACK Architecture on Security Event Inspection by Yu-Lun Chen and ...
PDF
Production Ready Containers from IBM and Docker
PDF
DCEU 18: Docker Enterprise Platform and Architecture
PDF
DCSF19 Container Security: Theory & Practice at Netflix
PDF
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
PPTX
Docker Meetup 08 03-2016
Docker Practice in Alibaba Cloud by Li Yi (Mark) & Zuhe Li (Sogo)
Docker Roadshow 2016
Intro to docker - innovation demo 2022
Docker in Production, Look No Hands! by Scott Coulton
DockerCon EU 2015: Nesting Containers: Real Life Observations
Securing your Containers
Docker on Docker
How to accelerate docker adoption with a simple and powerful user experience
Docker Container Lifecycles, Problem or Opportunity? by Baruch Sadogursky, JFrog
Docker Datacenter - CaaS
Docker Online Meetup: Infrakit update and Q&A
DockerCon SF 2015: DHE/DTR
Introduction to Docker - 2017
DockerCon 16 General Session Day 1
Using the SDACK Architecture on Security Event Inspection by Yu-Lun Chen and ...
Production Ready Containers from IBM and Docker
DCEU 18: Docker Enterprise Platform and Architecture
DCSF19 Container Security: Theory & Practice at Netflix
Proof of Concept: Serverless with Swarm by Nirmal Mehta, Booz Allen Hamilton
Docker Meetup 08 03-2016
Ad

Viewers also liked (20)

PDF
PPT_Compiled
PDF
History of the republic of India
PPTX
Fundamental Duties 5.1
PDF
Polity dpsp 4.3
PDF
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
PDF
Polity dpsp 4.2
PDF
Containerize All the (Multi-Platform) Things! by Phil Estes
PPTX
DockerCon EU 2015: It's in the game: the path to micro-services at Electronic...
PPTX
DockerCon SF 2015: Cultural Change using Docker
PPTX
OpenStack Boston
PDF
How to Use Your Own Private Registry
PPTX
DockerCon EU 2015: Monitoring and Managing Dynamic Docker Environments
PPTX
DockerCon SF 2015: Panel Discussion Birds of a Different Feather Soar Together
PDF
Autoscaling Docker Containers by Konstantinos Faliagkas, Docker Birthday #3 A...
PDF
Trust and Image Provenance by Derek McGowan
PDF
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
PPTX
DockerCon SF 2015: Education for a digital world
PDF
DockerCon14 Contributing to Docker by Tianon
PDF
Dockercon Swarm Updated
PPTX
Dockerfile Basics Workshop #1
PPT_Compiled
History of the republic of India
Fundamental Duties 5.1
Polity dpsp 4.3
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
Polity dpsp 4.2
Containerize All the (Multi-Platform) Things! by Phil Estes
DockerCon EU 2015: It's in the game: the path to micro-services at Electronic...
DockerCon SF 2015: Cultural Change using Docker
OpenStack Boston
How to Use Your Own Private Registry
DockerCon EU 2015: Monitoring and Managing Dynamic Docker Environments
DockerCon SF 2015: Panel Discussion Birds of a Different Feather Soar Together
Autoscaling Docker Containers by Konstantinos Faliagkas, Docker Birthday #3 A...
Trust and Image Provenance by Derek McGowan
Everything You Need to Know About Docker and Storage by Ryan Wallner, ClusterHQ
DockerCon SF 2015: Education for a digital world
DockerCon14 Contributing to Docker by Tianon
Dockercon Swarm Updated
Dockerfile Basics Workshop #1
Ad

Similar to Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat (20)

PDF
Containers & Security
PPTX
SW Docker Security
PDF
Hack the whale
PDF
5 Ways to Secure Your Containers for Docker and Beyond
PDF
How Secure Is Your Container? ContainerCon Berlin 2016
PDF
PDF
Docker_Interview_Questions__Answers.pdf
PDF
Docker London: Container Security
PDF
Containerize! Between Docker and Jube.
PDF
Introduction to docker security
PDF
Docker security: Rolling out Trust in your container
PPTX
Docker training
PPTX
Docker Security Overview
PDF
Linux Containers and Docker SHARE.ORG Seattle 2015
PDF
Reviwe(docker)
PDF
Dockers zero to hero
PPTX
Accelerate your development with Docker
PDF
Accelerate your software development with Docker
PPTX
Docker Platform and Ecosystem
PDF
Evoluation of Linux Container Virtualization
Containers & Security
SW Docker Security
Hack the whale
5 Ways to Secure Your Containers for Docker and Beyond
How Secure Is Your Container? ContainerCon Berlin 2016
Docker_Interview_Questions__Answers.pdf
Docker London: Container Security
Containerize! Between Docker and Jube.
Introduction to docker security
Docker security: Rolling out Trust in your container
Docker training
Docker Security Overview
Linux Containers and Docker SHARE.ORG Seattle 2015
Reviwe(docker)
Dockers zero to hero
Accelerate your development with Docker
Accelerate your software development with Docker
Docker Platform and Ecosystem
Evoluation of Linux Container Virtualization

More from Docker, Inc. (20)

PDF
Containerize Your Game Server for the Best Multiplayer Experience
PDF
How to Improve Your Image Builds Using Advance Docker Build
PDF
Build & Deploy Multi-Container Applications to AWS
PDF
Securing Your Containerized Applications with NGINX
PDF
How To Build and Run Node Apps with Docker and Compose
PDF
Hands-on Helm
PDF
Distributed Deep Learning with Docker at Salesforce
PDF
The First 10M Pulls: Building The Official Curl Image for Docker Hub
PDF
Monitoring in a Microservices World
PDF
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
PDF
Predicting Space Weather with Docker
PDF
Become a Docker Power User With Microsoft Visual Studio Code
PDF
How to Use Mirroring and Caching to Optimize your Container Registry
PDF
Monolithic to Microservices + Docker = SDLC on Steroids!
PDF
Kubernetes at Datadog Scale
PDF
Labels, Labels, Labels
PDF
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
PDF
Build & Deploy Multi-Container Applications to AWS
PDF
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
PDF
Developing with Docker for the Arm Architecture
Containerize Your Game Server for the Best Multiplayer Experience
How to Improve Your Image Builds Using Advance Docker Build
Build & Deploy Multi-Container Applications to AWS
Securing Your Containerized Applications with NGINX
How To Build and Run Node Apps with Docker and Compose
Hands-on Helm
Distributed Deep Learning with Docker at Salesforce
The First 10M Pulls: Building The Official Curl Image for Docker Hub
Monitoring in a Microservices World
COVID-19 in Italy: How Docker is Helping the Biggest Italian IT Company Conti...
Predicting Space Weather with Docker
Become a Docker Power User With Microsoft Visual Studio Code
How to Use Mirroring and Caching to Optimize your Container Registry
Monolithic to Microservices + Docker = SDLC on Steroids!
Kubernetes at Datadog Scale
Labels, Labels, Labels
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Build & Deploy Multi-Container Applications to AWS
From Fortran on the Desktop to Kubernetes in the Cloud: A Windows Migration S...
Developing with Docker for the Arm Architecture

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
KodekX | Application Modernization Development
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Advanced IT Governance
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
KodekX | Application Modernization Development
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Modernizing your data center with Dell and AMD
The Rise and Fall of 3GPP – Time for a Sabbatical?
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Advanced methodologies resolving dimensionality complications for autism neur...
Advanced IT Governance
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat

  • 1. Practical Container Security Mrunal Patel Principal Software Engineer Thomas Cameron Cloud Strategy Evangelist
  • 3. 3 AGENDA Containers and Security INTRODUCTION Who are we, and why should you care? What makes up container security? RED HAT AND CONTAINERS A brief history KERNEL NAMESPACES What are they? WHAT ARE CONTAINERS? How do they work? WHAT ARE CONTAINERS NOT? Mythbusting CONTAINER SECURITY
  • 4. 4 AGENDA Containers and Security CONTROL GROUPS What are they? THE DOCKER DAEMON How it works and the security it provides LINUX KERNEL CAPABILITIES libcap and how Docker deals with it SELINUX What it is, what it does, and why it matters TIPS AND TRICKS What do do, and what not to do. THE DOCKER DAEMON CONCLUSIONS Go forth and contain!
  • 6. 6 INTRODUCTION Who am I, and why should you care? My name is Thomas Cameron, and I'm the global solutions architect leader at Red Hat. ● In IT since 1993 ● I was a police officer before that, educational background is in law enforcement & security ● At Red Hat since 2005 ● Red Hat Certified Architect, Red Hat Certified Security Specialist, and other certs ● In the past, I was an MCSE, a MCT, and a CNE ● Spent a lot of time focusing on security in organizations like banks, manufacturing companies, e-commerce, etc. ● I do NOT know everything. But I have some pretty impressive scars.
  • 7. RED HAT AND CONTAINERS
  • 8. 8 RED HAT AND CONTAINERS A brief history Red Hat has been working on container technologies since before 2010 ● Makara acquisition 2010 – PaaS ● Rebranded as OpenShift ● “Cartridges” using SELinux, cgroups, kernel namespaces ● Docker came to prominence in 2013(-ish) ● Docker gained community adoption and we started participating in 2013. Meritocracy rules! ● Red Hat is a top contributor to Docker (#2 behind Docker at last check)
  • 9. 9 RED HAT AND CONTAINERS A brief history Industry adoption of Docker is incredible ● Docker has been through multiple successful venture capital rounds ● Apcera, Cisco, EMC, Fujitsu Limited, Goldman Sachs, HP, Huawei, IBM, Intel, Joyent, Mesosphere, Pivotal, Rancher Labs, Red Hat and VMware are all on board with container standardization with Docker.
  • 10. 10 RED HAT AND CONTAINERS A brief history Industry adoption of Docker is incredible ● Even Microsoft announced that they will support Docker containers!
  • 11. 11
  • 13. 13 WHAT ARE CONTAINERS? How do they work? Containerization, specifically Docker, is a technology which allows applications (web, database, app server, etc.) to be run abstracted from, and in some isolation from, the underlying operating system. The docker service can launch containers regardless of the underlying Linux distro. Containers can enable incredible application density, since you don't have the overhead of a full OS image for each app. Linux control groups also enable maximum utilization of the system. The same container can run on different versions of Linux ● Ubuntu containers on Fedora ● CentOS containers on RHEL
  • 14. 14 WHAT ARE CONTAINERS? How do they work? OK, maybe not... Containers make it really easy for application developers to build and deploy apps.
  • 16. 16 WHAT ARE CONTAINERS NOT? Mythbusting Containers are not a panacea. They are not “the cure to all that ails you!”
  • 17. 17 WHAT ARE CONTAINERS NOT? Mythbusting Containers are not a fit for every application.
  • 18. 18 WHAT ARE CONTAINERS NOT? Mythbusting They are not virtualization. You can run containers on an OS on bare metal.
  • 20. 20 CONTAINER SECURITY What makes up container security? Containers use several mechanisms for security: ● Linux kernel namespaces ● Linux Control Groups (cgroups) ● The Docker daemon ● Linux capabilities (libcap) ● Linux security mechanisms like AppArmor or SELinux
  • 22. 22 LINUX KERNEL NAMESPACES What are they? Namespaces are just a way to make a global resource appear to be unique and isolated. The namespaces that the Linux kernel can manage are: ● Mount namespaces ● PID namespaces ● UTS namespaces ● IPC namespaces ● Network namespaces ● User namespaces
  • 24. 24 LINUX KERNEL NAMESPACES What are they? Mount namespaces allow a container to “think” that a directory which is actually mounted from the host OS is exclusively the container's. When you start a container with the -v [host-path]:[container-path]:[rw|ro] argument, you can mount a directory from the host in the container. The container “sees” the directory in its own mount namespace, not knowing that it is actually on the host. So multiple containers could, for instance use the host's /var/www/html directory without having to copy content to all the containers.
  • 25. 25
  • 27. 27 LINUX KERNEL NAMESPACES What are they? PID namespaces let the container think it's a new instance of the OS. When you start a container on a host, it will get a new process ID. PID namespaces enable the container to “see” the PIDs inside the container as unique, as if the container were its own instance of an OS. In the following example, I launch a Fedora container running bash, and run “ps ax” The container only “sees” its own PID namespace, so the bash process exists within the container as PID 1. On the host, however, the docker process is PID 18557:
  • 28. 28
  • 29. 29
  • 31. 31 LINUX KERNEL NAMESPACES What are they? When you start a container, assuming you've added your user to the docker group, you start it as your user account. In the following example, I start the container as tcameron. Once the container is started, my user inside the container is root. This is an example of user namespaces.
  • 32. 32
  • 34. 34 LINUX KERNEL NAMESPACES What are they? Network namespaces allow a container to have its own IP address, independent of that of the host. These addresses are not available from outside of the host, this is private networking similar to that of virtualization. The Docker service sets up an iptables masquerading rule so that the container can get to the rest of the Internet. In the following query, I find that my Fedora instance has the address 172.17.0.7, even though the host doesn't have an address associated with the ethernet interface:
  • 35. 35
  • 37. 37 LINUX KERNEL NAMESPACES What are they? IPC namespaces do the same thing with interprocess communications. My container has no IPCs mapped, but my host has many:
  • 38. 38
  • 39. 39
  • 41. 41 LINUX KERNEL NAMESPACES What are they? UTS (UNIX Timesharing System) namespaces let the container “think” it's a separate OS, with its own hostname and domain name:
  • 42. 42
  • 43. 43
  • 45. 45 CONTROL GROUPS What are they? From the documentation at https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt: “Control Groups provide a mechanism for aggregating/partitioning sets of tasks, and all their future children, into hierarchical groups with specialized behavior.” This allows us to put various system resources into a group, and apply limits to it, like how much disk IO, CPU use, memory use, network use, namespaces, and so on. In the case of containers, the resources are those assigned to that container.
  • 46. 46 CONTROL GROUPS What are they? This ensures that, even if a container is compromised (or just spins out of control), there are limits in place which minimizes the risk of that misbehaved container impacting the host or other containers.
  • 47. 47 CONTROL GROUPS What are they? Note that when I run the command systemctl status docker.service, I get the control group and slice information:
  • 48. 48
  • 49. 49 CONTROL GROUPS What are they? You can navigate the /sys/fs/cgroup/ pseudo-directory to see what resources are allocated to your containers. There are over 8500 entries in this directory on my system, so it is not practical to talk about the details of individual cgroups, but you can get information about memory, cpu, block I/O, network I/O, and so on here.
  • 50. 50
  • 52. 52 THE DOCKER DAEMON How it works and the security it provides The docker daemon (/usr/bin/docker) is responsible for managing the control groups, orchestrating the namespaces, and so on so that docker images can be run and secured. Because of the need to manage kernel functions, Docker runs with root privileges. Be aware of this!
  • 53. 53 THE DOCKER DAEMON How it works and the security it provides There are some considerations for running Docker: ● Only allow trusted users to run docker. The Docker documentation recommends that you add users to the docker group so they can run docker commands. With this flexibility comes risk. Make sure you only delegate this ability to trusted users. Remember that they can mount the host filesystem in their container with root privileges! ● If you are using the REST API to manage your host(s), make sure you do not have vulnerabilities exposed. Ensure you have strong authentication. ● Use SSL if you are going to expose the REST API over http. Don't expose it except to secured networks or VPN.
  • 55. 55 LINUX KERNEL CAPABILITIES libcap and how Docker deals with it The root user historically had the ability to do anything, once authenticated. Linux capabilities is a set of fine grained controls which allow services or even users with root equivalence to be limited in their scope. It also allows non-root users to be granted extra privileges. A regular user, for instance, could be granted the net_bind_service capability and they could bind a service to a privileged port (below 1024).
  • 56. 56 LINUX KERNEL CAPABILITIES libcap and how Docker deals with it In containers, many of the capabilities to manage network and other services are not actually needed. SSH services, cron, services, filesystem mounts and unmounts are not needed, network management is not needed, etc. By default, Docker disallows many root capabilities, including the ability to modify logs, change networking, modify kernel memory, and the catch-all CAP_SYS_ADMIN.
  • 57. 57
  • 59. 59 SELINUX What it is, what it does, and why it matters Security Enhanced Linux (SELinux) is a mandatory access control system. Processes, files, memory, network interfaces, and so on are labeled, and there is a policy which is administratively set and fixed. That policy will determine how processes can interact with files, each other, network ports, and the like.
  • 60. 60 SELINUX What it is, what it does, and why it matters SELinux is primarily concerned with labeling and type enforcement. For a mythical service “foo,” the executable file on disk might have the label foo_exec_t. The startup scripts for foo might have the label foo_config_t. The log files for foo might have the label foo_log_t. The data for foo might have the label foo_data_t. When foo is running, the process in memory might have the label foo_t. Type enforcement is the rule set that says that when a process running in the foo_t context tries to access a file on the filesystem with the label foo_config_t or foo_data_t, that access is allowed. When the process with the label foo_t tries to write to a log file with the foo_log_t, that would be allowed, as well. Any other access, unless explicitly allowed by policy, is denied.
  • 61. 61 SELINUX What it is, what it does, and why it matters If the foo process, running in the foo_t context tries to access, for instance, the directory /home/tcameron, with the label user_home_dir_t, even if the permissions are wide open, the policy will stop that access. SELinux labels are stored as extended attributes on the filesystem, or in memory.
  • 62. 62 SELINUX What it is, what it does, and why it matters SELinux labels are stored in the format: ● selinux_user:selinux_role:selinux_type:mls:mcs So for the mythical “foo” service, the full syntax for the label of the running process might be: ● user_u:object_r:foo_t:s0:c0
  • 63. 63 SELINUX What it is, what it does, and why it matters The default policy for SELinux is “targeted.” In the targeted policy, we don't use the SELinux user or role, so we'll ignore them for today. We will also ignore the MLS (multilevel security) label, since that is only used in the MLS policy (think top secret vs. secret in the military). We really only care about the type (remember, type enforcement) and the MCS label. Think of MCS labels as extra identifiers. In SELinux for containers, we can be very granular about which processes can access which other processes. These are different labels: ● user_u:object_r:foo_t:s0:c0 ● user_u:object_r:foo_t:s0:c1
  • 64. 64 SELINUX What it is, what it does, and why it matters Type enforcement says that a process with the first label is different from the process with the second. So policy would prevent them from interacting. Also, there is no policy allowing a process running with those labels to access the filesystem unless it is labeled with foo_config_t or foo_content_t or another defined label. Neither of those processes would be able to access /etc/shadow, which has the label shadow_t.
  • 65. 65 SELINUX What it is, what it does, and why it matters On a standalone system running Docker, all of the containers run in the same context by default. In Red Hat's PaaS offering, OpenShift, this is not the case. Each Openshift container runs in its own context, with labels like: ● staff_u:system_r:openshift_t:s0:c0,c1 ● staff_u:system_r:openshift_t:s0:c2,c3 ● staff_u:system_r:openshift_t:s0:c4,c5 So, even if someone were to gain access to the docker container process on the host, SELinux would prevent them from being able to access other containers, or the host.
  • 66. 66 SELINUX What it is, what it does, and why it matters In the following example, I emulate an exploit where someone takes over a container. I use runcon (run in the context) to set my context to that of an Openshift container. I attempt to access /etc/shadow (shadow_t label). I try to write to the filesystem. I try to read the contents of a user's home directory.
  • 67. 67
  • 69. 69 TIPS AND TRICKS What to do, and what not to do Containers are, at the end of the day, just processes running on the host. Use common sense.
  • 70. 70 TIPS AND TRICKS What to do, and what not to do Do: ● Have a process in place to update your containers. Follow it. ● Run services in the containers with the lowest privilege possible. Drop root privileges as soon as you can. ● Mount filesystems from the host read-only wherever possible. ● Treat root inside the container just like you would on the host. ● Watch your logs.
  • 71. 71 TIPS AND TRICKS What to do, and what not to do Don't: ● Download any old container you find on the 'net. ● Run SSH inside the container. ● Run with root privileges. ● Disable SELinux. ● Roll your own containers once, and never maintain them. ● Run production containers on unsupported platforms.
  • 73. 73 CONCLUSION Go forth and contain! Containers are incredibly cool. They make application deployment really, really easy. They leverage some incredible capabilities within the Linux kernel. By design, they are relatively secure, but there are some gotchas. As with every other piece of software out there, docker tech requires some feeding and maintenance. Well maintained, containers can make your business more agile, less complex, and safe.