SlideShare a Scribd company logo
Is it safe to run applications
in Linux Containers?
Jérôme Petazzoni Docker Inc.
@jpetazzo @docker
...
Yes
/* shocker: docker PoC VMM-container breakout (C) 2014 Sebastian Krahmer
*
* Demonstrates that any given docker image someone is asking
* you to run in your docker setup can access ANY file on your host,
* e.g. dumping hosts /etc/shadow or other sensitive info, compromising
* security of the host and any other docker VM's on it.
*
* docker using container based VMM: Sebarate pid and net namespace,
* stripped caps and RO bind mounts into container's /. However
* as its only a bind-mount the fs struct from the task is shared
* with the host which allows to open files by file handles
* (open_by_handle_at()). As we thankfully have dac_override and
* dac_read_search we can do this. The handle is usually a 64bit
* string with 32bit inodenumber inside (tested with ext4).
* Inode of / is always 2, so we have a starting point to walk
* the FS path and brute force the remaining 32bit until we find the
* desired file (It's probably easier, depending on the fhandle export
* function used for the FS in question: it could be a parent inode# or
* the inode generation which can be obtained via an ioctl).
* [In practise the remaining 32bit are all 0 :]
Wait
No!
Docker has changed its security status to
It's complicated
Who am I? Why am I here?
Jérôme Petazzoni (@jpetazzo)
- Grumpy French Linux DevOps
Operated dotCloud PAAS for 3+ years
- hosts arbitrary code for arbitrary users
- each service of each app runs in a container
- no major security issue yet (fingers crossed)
Containerize all the things!
- VPN-in-Docker, KVM-in-Docker,
Xorg-in-Docker, Docker-in-Docker...
What are those “containers” ? (1/3)
Technically: ~chroot on steroids
- a container is a set of processes
(running on top of common kernel)
- isolated* from the rest of the machine
(cannot see/affect/harm host or other containers)
- using namespaces to have private view of the system
(network interfaces, PID tree, mountpoints...)
- and cgroups to have metered/limited/reserved resources
(to mitigate “bad neighbor” effect)
*Limitations may apply.
What are those “containers” ? (2/3)
From a distance: looks like a VM
- I can SSH into my container
- I can have root access in it
- I can install packages in it
- I have my own eth0 interface
- I can tweak routing table, iptables rules
- I can mount filesystems
- etc.
What are those “containers” ? (3/3)
Lightweight, fast, disposable... virtual environments
- boot in milliseconds
- just a few MB of intrinsic disk/memory usage
- bare metal performance is possible
The new way to build, ship, deploy, run your apps!
Why is this a hot topic?
Containers have been around for decades
LXC (Linux Containers) have been around for years
So, what?
Blame
Docker
Why is this a hot topic?
Containers have been around for decades
LXC (Linux Containers) have been around for years
Tools like Docker made containers very easy to use
Everybody* wants to deploy containers now
But, oops, LXC wasn't made for security
We want containers, and we want them now;
how can we do that safely?
*Okay, almost everybody. If you're not convinced yet of the general awesomeness
of Docker and containers, give them a second chance by checking my other talk
this afternoon; or the Docker meet-up tomorrow at New Relic.
Some
inspirational
quotes
“LXC is not yet secure.
If I want real security
I will use KVM.”
—Dan Berrangé
(famous LXC hacker)
This was in 2011. The Linux Kernel has changed a tiny little bit since then.
“From security point of view
lxc is terrible and may not be
consider as security solution.”
—someone on Reddit
(original spelling and grammar)
Common opinion among security experts and paranoid people.
To be fair, they have to play safe & can't take risks.
“Basically containers are not
functional as security containers at
present, in that if you have root
on a container you have root on
the whole box.”
—Gentoo Wiki
That's just plain false, or misleading, and we'll see why.
“Containers do not contain.”
—Dan Walsh
(Mr SELinux)
This was earlier this year, and this guy knows what he's talking about.
Are we in trouble?
“For the fashion of Minas Tirith was
such that it was built on seven
levels, each delved into a hill,
and about each was set a wall,
and in each wall was a gate.”
—J.R.R. Tolkien
(also quoted in VAX/VMS Internals and Data Structures, ca. 1980)
Keyword:
levels
Let's revisit one of those quotes...
“If you have root on a container you
have root on the whole box.”
Don't give root in the container in the first place
If you really have to give root, give looks-like-root
If that's not enough, give root but build another wall
Root in the host
Root in the container
Uruks (intruders)
There is more than one threat model
Regular applications
- web servers, databases, caches, message queues, ...
System services (high level)
- logging, remote access, periodic command execution, ...
System services (low level)
- manage physical devices, networking, filesystems, ...
Kernel
- security policies, drivers, ...
The special case of immutable infrastructure
Regular applications
Regular applications
Apache, Nginx, MySQL, PostgreSQL, MongoDB, Redis,
Memcached, Cassandra, Hadoop, RabbitMQ...
Virtually all your programs in any language
(services, web services, workers, everything!)
They never ever need any kind of root privilege
(except to install packages)
Don't run them as root! Ever!
Regular applications
Risk: they run arbitrary code
- vector: by definition, they are arbitrary code
- vector: security breach causes execution of malicious code
Fix: nothing
- by definition, we are willing to execute arbitrary code here
Consequence:
assume those apps can try anything to break out
Regular applications
Risk: escalate from non-root to root
- vector: vulnerabilities in SUID binaries
Fix: defang SUID binaries
- remove them
- remove suid bit
- mount filesystem with nosuid
Regular applications
Risk: execute arbitrary kernel code
- vector: bogus syscall (e.g. vmsplice* in 2008)
Fix: limit available syscalls
- seccomp-bpf = whitelist/blacklist syscalls
Fix: run stronger kernels
- GRSEC is a good idea (stable patches for 3.14 since July 4th)
- update often (i.e. have efficient way to roll out kernel upgrades)
*More details about that: http://lwn.net/Articles/268783/
Regular applications
Risk: leak to another container
- vector: bug in namespace code; filesystem leak*
Fix: user namespaces
- map UID in container to a different UID outside
- two containers run a process with UID 1000,
but it's 14298 and 15398 outside
Fix: security modules (e.g. SELinux)
- assign different security contexts to containers
- those mechanisms were designed to isolate!
*Like the one showed in the beginning of this talk!
System services
(high level)
System services (high level)
SSH, cron, syslog...
You use/need them all the time
Bad news: they typically run as root
Good news: they don't really need root
Bad news: it's hard to run them as non-root
Good news: they are not arbitrary code
System services (high level)
Risk: running arbitrary code as root
- vector: malformed data or similar
(note: risk is pretty low for syslog/cron; much higher for SSH)
Fix: isolate sensitive services
- run SSH on bastion host, or in a VM
- note: this is not container-specific
(if someone hacks into your SSH server, you'll have a bad time)
System services (high level)
Risk: messing with /dev
- vector: malicious code
Fix: “devices” control group
- whitelist/blacklist devices
- fine-grained: can allow only read, write, none, or both
- fine-grained: can specify major+minor number of device
System services (high level)
Risk: use of root calls (mount, chmod, iptables...)
- vector: malicious code
Fix: capabilities
- break down “root” into many permissions
- e.g. CAP_NET_ADMIN (network configuration)
- e.g. CAP_NET_RAW (generate and sniff traffic)
- e.g. CAP_SYS_ADMIN (big can of worms )☹
- see capabilities(7)
Interlude: CAP_SYS_ADMIN
Operations controlled by CAP_SYS_ADMIN...
 quotactl, mount, umount, swapon, swapoff
 sethostname, setdomainname
 IPC_SET, IPC_RMID on arbitrary System V IPC resources
 perform operations on trusted and security Extended Attributes
 set realtime priority
(ioprio_set + IOPRIO_CLASS_RT)
 create new namespaces
(clone and unshare + CLONE_NEWNS)
System services (high level)
Risk: messing with /proc, /sys
- vector: malicious code
Fix: prevent unauthorized access control
- Mandatory Access Control (AppArmor, SELinux)
- remount read-only, then drop CAP_SYS_ADMIN to prevent remount
Fix: wider implementation of namespaces
- some parts of procfs/sysfs are “namespace-aware”
- some aren't, but can be fixed (by writing kernel code)
System services (high level)
Risk: leaking with UID 0
- vector: malicious code
Fix: user namespaces
- already mentioned earlier
- UID 0 in the container is mapped to some random UID outside
- you break out: you're not root
- you manage to issue weird syscalls: they're done as unprivileged UID
Caveat: user namespaces are still new.
We have to see how they behave with that!
System services
(low level)
System services (low level)
Device management (keyboard, mouse, screen),
network and firewall config, filesystem mounts...
You use/need some of them all the time
But you don't need any of them in your containers
- physical device management is done by the host
- network configuration and filesystems are setup by the host
Exceptions:
- custom mounts (FUSE)
- network appliances
System services (low level)
Risk: running arbitrary code as root
- vector: malformed data or similar
Fix: isolate sensitive functions
- “one-shot” commands can be fenced in privileged context
(think “sudo” but without even requiring “sudo”)
- everything else (especially processes that are long-running, or handle
arbitrary input) runs in non-privileged context
- works well for FUSE, some VPN services
System services (low level)
Risk: run arbitrary code with full privileges
- vector: needs a process running with full privileges (rare!)
- vector: malformed data, unchecked input… classic exploit
Fix: treat it as “kernel”
- we'll see that immediately in the next section
Kernel
Kernel
Drivers
- they can talk to the hardware, so they can do pretty much anything
- except: virtualize the bus and use e.g. driver domains (Xen)
Network stacks
- this probably has to live into the kernel for good performance
- except: DPDK, OpenOnload... (networking stacks in userspace)
Security policies
- by definition, they control everything else
- except: there might be nested security contexts some day
Kernel
Risk: run arbitrary code with absolute privileges
Fix: ?
Reality check:
if you run something which by definition
needs full control over hardware or kernel,
containers are not going to make it secure.
Please stop trying to shoot yourself in the foot safely.
Reality check:
if you run something which by definition
needs full control over hardware or kernel,
containers are not going to make it secure.
Please stop trying to shoot yourself in the foot safely.
Kernel
Risk: run arbitrary code with absolute privileges
Fix: give it its own kernel and (virtual) hardware
- i.e. run it in a virtual machine
- that VM can run in a container
- that VM can hold a container
- run a privileged container in Docker in a VM in a container in Docker
https://github.com/jpetazzo/docker2docker
- inb4 xzibit meme
LXC, Docker, security: is it safe to run applications in Linux Containers?
Immutable
immutable
infrastructure
Immutable immutable infrastructure
New rule: the whole container is read-only
Compromise: if we must write, write to a noexec area
Scalability has never been easier (if totally read-only)
It's even harder for malicious users to do evil things
Recap (in no specific order!)
 don't run things as root
 drop capabilities
 enable user namespaces
 get rid of shady SUID binaries
 enable SELinux (or AppArmor)
 use seccomp-bpf
 get a GRSEC kernel
 update kernels often
 mount everything read-only
 ultimately, fence things in VMs
Thank you!
Questions?
 don't run things as root
 drop capabilities
 enable user namespaces
 get rid of shady SUID binaries
 enable SELinux (or AppArmor)
 use seccomp-bpf
 get a GRSEC kernel
 update kernels often
 mount everything read-only
 ultimately, fence things in VMs
See also:
- Docker in Production (1:40pm today)
- Office hour (10:40am tomorrow, expo hall Table A)
- Docker meet-up at New Relic (tomorrow evening)

More Related Content

What's hot (20)

PDF
Understand the iptables step by step
HungWei Chiu
 
PDF
Kvm performance optimization for ubuntu
Sim Janghoon
 
PPTX
Docker, LinuX Container
Araf Karsh Hamid
 
PDF
Kernel Recipes 2019 - XDP closer integration with network stack
Anne Nicolas
 
PDF
Blazing Performance with Flame Graphs
Brendan Gregg
 
PPTX
HSA Kernel Code (KFD v0.6)
Hann Yu-Ju Huang
 
PDF
Black Hat Europe 2017. DPAPI and DPAPI-NG: Decryption Toolkit
Paula Januszkiewicz
 
PPTX
Kali Linux
Chanchal Dabriya
 
PDF
SANS Forensics 2009 - Memory Forensics and Registry Analysis
mooyix
 
PPSX
User Administration in Linux
SAMUEL OJO
 
PDF
Deploying IPv6 on OpenStack
Vietnam Open Infrastructure User Group
 
PDF
Dongwon Kim – A Comparative Performance Evaluation of Flink
Flink Forward
 
PDF
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
Thomas Graf
 
PDF
Process Scheduler and Balancer in Linux Kernel
Haifeng Li
 
PDF
Docker Introduction
Peng Xiao
 
PPTX
Room 3 - 7 - Nguyễn Như Phúc Huy - Vitastor: a fast and simple Ceph-like bloc...
Vietnam Open Infrastructure User Group
 
PDF
A Case Study in Attacking KeePass
Will Schroeder
 
PDF
Run Qt on Linux embedded systems using Yocto
Marco Cavallini
 
PDF
eBPF Trace from Kernel to Userspace
SUSE Labs Taipei
 
PPTX
Linux Initialization Process (2)
shimosawa
 
Understand the iptables step by step
HungWei Chiu
 
Kvm performance optimization for ubuntu
Sim Janghoon
 
Docker, LinuX Container
Araf Karsh Hamid
 
Kernel Recipes 2019 - XDP closer integration with network stack
Anne Nicolas
 
Blazing Performance with Flame Graphs
Brendan Gregg
 
HSA Kernel Code (KFD v0.6)
Hann Yu-Ju Huang
 
Black Hat Europe 2017. DPAPI and DPAPI-NG: Decryption Toolkit
Paula Januszkiewicz
 
Kali Linux
Chanchal Dabriya
 
SANS Forensics 2009 - Memory Forensics and Registry Analysis
mooyix
 
User Administration in Linux
SAMUEL OJO
 
Deploying IPv6 on OpenStack
Vietnam Open Infrastructure User Group
 
Dongwon Kim – A Comparative Performance Evaluation of Flink
Flink Forward
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
Thomas Graf
 
Process Scheduler and Balancer in Linux Kernel
Haifeng Li
 
Docker Introduction
Peng Xiao
 
Room 3 - 7 - Nguyễn Như Phúc Huy - Vitastor: a fast and simple Ceph-like bloc...
Vietnam Open Infrastructure User Group
 
A Case Study in Attacking KeePass
Will Schroeder
 
Run Qt on Linux embedded systems using Yocto
Marco Cavallini
 
eBPF Trace from Kernel to Userspace
SUSE Labs Taipei
 
Linux Initialization Process (2)
shimosawa
 

Viewers also liked (20)

PDF
Docker, Linux Containers, and Security: Does It Add Up?
Jérôme Petazzoni
 
PDF
Docker Security Paradigm
Anis LARGUEM
 
PDF
Containers, docker, and security: state of the union (Bay Area Infracoders Me...
Jérôme Petazzoni
 
PDF
Linux Containers From Scratch
joshuasoundcloud
 
PPTX
Docker Security Overview
Sreenivas Makam
 
PDF
Docker London: Container Security
Phil Estes
 
PPT
Tom Purves: Designing for An Augmented Reality World
Refresh Events
 
PDF
Docker security - TASK Jan 2016
Fernando Montenegro
 
PPTX
The How and Why of Container Vulnerability Management
Black Duck by Synopsys
 
PDF
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Yandex
 
PDF
Introduzione a Docker (parte 2 - Pratica)
Cristian Consonni
 
PDF
Alla scoperta di Ubuntu Phone, lo smartphone open-source - Codemotion techmee...
Codemotion
 
PPT
Seven problems of Linux Containers
Kirill Kolyshkin
 
PPTX
Contain your risk: Deploy secure containers with trust and confidence
Black Duck by Synopsys
 
PPTX
Docker Fudamentals
mvetro
 
PDF
Docker: automation for the rest of us
Jérôme Petazzoni
 
PDF
Docker at Spotify - Dockercon14
dotCloud
 
PDF
[Impact Lab] IT инструменты для проекта
Dmitry Spodarets
 
PDF
Docker and Containers for Development and Deployment — SCALE12X
Jérôme Petazzoni
 
PPTX
Performance comparison between Linux Containers and Virtual Machines
Soheila Dehghanzadeh
 
Docker, Linux Containers, and Security: Does It Add Up?
Jérôme Petazzoni
 
Docker Security Paradigm
Anis LARGUEM
 
Containers, docker, and security: state of the union (Bay Area Infracoders Me...
Jérôme Petazzoni
 
Linux Containers From Scratch
joshuasoundcloud
 
Docker Security Overview
Sreenivas Makam
 
Docker London: Container Security
Phil Estes
 
Tom Purves: Designing for An Augmented Reality World
Refresh Events
 
Docker security - TASK Jan 2016
Fernando Montenegro
 
The How and Why of Container Vulnerability Management
Black Duck by Synopsys
 
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Yandex
 
Introduzione a Docker (parte 2 - Pratica)
Cristian Consonni
 
Alla scoperta di Ubuntu Phone, lo smartphone open-source - Codemotion techmee...
Codemotion
 
Seven problems of Linux Containers
Kirill Kolyshkin
 
Contain your risk: Deploy secure containers with trust and confidence
Black Duck by Synopsys
 
Docker Fudamentals
mvetro
 
Docker: automation for the rest of us
Jérôme Petazzoni
 
Docker at Spotify - Dockercon14
dotCloud
 
[Impact Lab] IT инструменты для проекта
Dmitry Spodarets
 
Docker and Containers for Development and Deployment — SCALE12X
Jérôme Petazzoni
 
Performance comparison between Linux Containers and Virtual Machines
Soheila Dehghanzadeh
 
Ad

Similar to LXC, Docker, security: is it safe to run applications in Linux Containers? (20)

PPTX
Docker Security
antitree
 
PDF
How Secure Is Your Container? ContainerCon Berlin 2016
Phil Estes
 
PDF
Tokyo OpenStack Summit 2015: Unraveling Docker Security
Phil Estes
 
PDF
Unraveling Docker Security: Lessons From a Production Cloud
Salman Baset
 
PPTX
Exploring Docker Security
Patrick Kleindienst
 
PDF
Docker Container: isolation and security
宇 傅
 
PDF
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
dotCloud
 
PDF
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.
 
PDF
Securing Containerized Applications: A Primer
Phil Estes
 
PDF
Containers and security
sriram_rajan
 
PDF
Securing Applications and Pipelines on a Container Platform
All Things Open
 
PDF
Container Security
Salman Baset
 
PPTX
Container security
Anthony Chow
 
PPTX
Docker Container Security
Suraj Khetani
 
PDF
Revolutionizing the cloud with container virtualization
WSO2
 
ODP
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
Docker, Inc.
 
PDF
Containers & Security
All Things Open
 
PDF
Security on a Container Platform
All Things Open
 
PDF
Docker Security - Secure Container Deployment on Linux
Michael Boelen
 
PDF
Immutable Infrastructure Security
Ricky Sanders
 
Docker Security
antitree
 
How Secure Is Your Container? ContainerCon Berlin 2016
Phil Estes
 
Tokyo OpenStack Summit 2015: Unraveling Docker Security
Phil Estes
 
Unraveling Docker Security: Lessons From a Production Cloud
Salman Baset
 
Exploring Docker Security
Patrick Kleindienst
 
Docker Container: isolation and security
宇 傅
 
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
dotCloud
 
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Docker, Inc.
 
Securing Containerized Applications: A Primer
Phil Estes
 
Containers and security
sriram_rajan
 
Securing Applications and Pipelines on a Container Platform
All Things Open
 
Container Security
Salman Baset
 
Container security
Anthony Chow
 
Docker Container Security
Suraj Khetani
 
Revolutionizing the cloud with container virtualization
WSO2
 
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
Docker, Inc.
 
Containers & Security
All Things Open
 
Security on a Container Platform
All Things Open
 
Docker Security - Secure Container Deployment on Linux
Michael Boelen
 
Immutable Infrastructure Security
Ricky Sanders
 
Ad

More from Jérôme Petazzoni (20)

PDF
Use the Source or Join the Dark Side: differences between Docker Community an...
Jérôme Petazzoni
 
PDF
Orchestration for the rest of us
Jérôme Petazzoni
 
PDF
Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...
Jérôme Petazzoni
 
PDF
Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...
Jérôme Petazzoni
 
PDF
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
PDF
How to contribute to large open source projects like Docker (LinuxCon 2015)
Jérôme Petazzoni
 
PDF
Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...
Jérôme Petazzoni
 
PDF
Microservices. Microservices everywhere! (At OSCON 2015)
Jérôme Petazzoni
 
PDF
Deploy microservices in containers with Docker and friends - KCDC2015
Jérôme Petazzoni
 
PDF
Containers: from development to production at DevNation 2015
Jérôme Petazzoni
 
PDF
Immutable infrastructure with Docker and containers (GlueCon 2015)
Jérôme Petazzoni
 
PDF
The Docker ecosystem and the future of application deployment
Jérôme Petazzoni
 
PDF
Docker Non Technical Presentation
Jérôme Petazzoni
 
PDF
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Jérôme Petazzoni
 
PDF
Introduction to Docker, December 2014 "Tour de France" Edition
Jérôme Petazzoni
 
PDF
Containers, Docker, and Microservices: the Terrific Trio
Jérôme Petazzoni
 
PDF
Containerization is more than the new Virtualization: enabling separation of ...
Jérôme Petazzoni
 
PDF
Pipework: Software-Defined Network for Containers and Docker
Jérôme Petazzoni
 
PDF
Docker Tips And Tricks at the Docker Beijing Meetup
Jérôme Petazzoni
 
PDF
Introduction to Docker at Glidewell Laboratories in Orange County
Jérôme Petazzoni
 
Use the Source or Join the Dark Side: differences between Docker Community an...
Jérôme Petazzoni
 
Orchestration for the rest of us
Jérôme Petazzoni
 
Docker : quels enjeux pour le stockage et réseau ? Paris Open Source Summit ...
Jérôme Petazzoni
 
Making DevOps Secure with Docker on Solaris (Oracle Open World, with Jesse Bu...
Jérôme Petazzoni
 
From development environments to production deployments with Docker, Compose,...
Jérôme Petazzoni
 
How to contribute to large open source projects like Docker (LinuxCon 2015)
Jérôme Petazzoni
 
Containers, Docker, and Security: State Of The Union (LinuxCon and ContainerC...
Jérôme Petazzoni
 
Microservices. Microservices everywhere! (At OSCON 2015)
Jérôme Petazzoni
 
Deploy microservices in containers with Docker and friends - KCDC2015
Jérôme Petazzoni
 
Containers: from development to production at DevNation 2015
Jérôme Petazzoni
 
Immutable infrastructure with Docker and containers (GlueCon 2015)
Jérôme Petazzoni
 
The Docker ecosystem and the future of application deployment
Jérôme Petazzoni
 
Docker Non Technical Presentation
Jérôme Petazzoni
 
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Jérôme Petazzoni
 
Introduction to Docker, December 2014 "Tour de France" Edition
Jérôme Petazzoni
 
Containers, Docker, and Microservices: the Terrific Trio
Jérôme Petazzoni
 
Containerization is more than the new Virtualization: enabling separation of ...
Jérôme Petazzoni
 
Pipework: Software-Defined Network for Containers and Docker
Jérôme Petazzoni
 
Docker Tips And Tricks at the Docker Beijing Meetup
Jérôme Petazzoni
 
Introduction to Docker at Glidewell Laboratories in Orange County
Jérôme Petazzoni
 

Recently uploaded (20)

PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Digital Circuits, important subject in CS
contactparinay1
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 

LXC, Docker, security: is it safe to run applications in Linux Containers?

  • 1. Is it safe to run applications in Linux Containers? Jérôme Petazzoni Docker Inc. @jpetazzo @docker
  • 2. ...
  • 3. Yes
  • 4. /* shocker: docker PoC VMM-container breakout (C) 2014 Sebastian Krahmer * * Demonstrates that any given docker image someone is asking * you to run in your docker setup can access ANY file on your host, * e.g. dumping hosts /etc/shadow or other sensitive info, compromising * security of the host and any other docker VM's on it. * * docker using container based VMM: Sebarate pid and net namespace, * stripped caps and RO bind mounts into container's /. However * as its only a bind-mount the fs struct from the task is shared * with the host which allows to open files by file handles * (open_by_handle_at()). As we thankfully have dac_override and * dac_read_search we can do this. The handle is usually a 64bit * string with 32bit inodenumber inside (tested with ext4). * Inode of / is always 2, so we have a starting point to walk * the FS path and brute force the remaining 32bit until we find the * desired file (It's probably easier, depending on the fhandle export * function used for the FS in question: it could be a parent inode# or * the inode generation which can be obtained via an ioctl). * [In practise the remaining 32bit are all 0 :]
  • 6. No!
  • 7. Docker has changed its security status to It's complicated
  • 8. Who am I? Why am I here? Jérôme Petazzoni (@jpetazzo) - Grumpy French Linux DevOps Operated dotCloud PAAS for 3+ years - hosts arbitrary code for arbitrary users - each service of each app runs in a container - no major security issue yet (fingers crossed) Containerize all the things! - VPN-in-Docker, KVM-in-Docker, Xorg-in-Docker, Docker-in-Docker...
  • 9. What are those “containers” ? (1/3) Technically: ~chroot on steroids - a container is a set of processes (running on top of common kernel) - isolated* from the rest of the machine (cannot see/affect/harm host or other containers) - using namespaces to have private view of the system (network interfaces, PID tree, mountpoints...) - and cgroups to have metered/limited/reserved resources (to mitigate “bad neighbor” effect) *Limitations may apply.
  • 10. What are those “containers” ? (2/3) From a distance: looks like a VM - I can SSH into my container - I can have root access in it - I can install packages in it - I have my own eth0 interface - I can tweak routing table, iptables rules - I can mount filesystems - etc.
  • 11. What are those “containers” ? (3/3) Lightweight, fast, disposable... virtual environments - boot in milliseconds - just a few MB of intrinsic disk/memory usage - bare metal performance is possible The new way to build, ship, deploy, run your apps!
  • 12. Why is this a hot topic? Containers have been around for decades LXC (Linux Containers) have been around for years So, what?
  • 14. Why is this a hot topic? Containers have been around for decades LXC (Linux Containers) have been around for years Tools like Docker made containers very easy to use Everybody* wants to deploy containers now But, oops, LXC wasn't made for security We want containers, and we want them now; how can we do that safely? *Okay, almost everybody. If you're not convinced yet of the general awesomeness of Docker and containers, give them a second chance by checking my other talk this afternoon; or the Docker meet-up tomorrow at New Relic.
  • 16. “LXC is not yet secure. If I want real security I will use KVM.” —Dan Berrangé (famous LXC hacker) This was in 2011. The Linux Kernel has changed a tiny little bit since then.
  • 17. “From security point of view lxc is terrible and may not be consider as security solution.” —someone on Reddit (original spelling and grammar) Common opinion among security experts and paranoid people. To be fair, they have to play safe & can't take risks.
  • 18. “Basically containers are not functional as security containers at present, in that if you have root on a container you have root on the whole box.” —Gentoo Wiki That's just plain false, or misleading, and we'll see why.
  • 19. “Containers do not contain.” —Dan Walsh (Mr SELinux) This was earlier this year, and this guy knows what he's talking about. Are we in trouble?
  • 20. “For the fashion of Minas Tirith was such that it was built on seven levels, each delved into a hill, and about each was set a wall, and in each wall was a gate.” —J.R.R. Tolkien (also quoted in VAX/VMS Internals and Data Structures, ca. 1980)
  • 22. Let's revisit one of those quotes... “If you have root on a container you have root on the whole box.” Don't give root in the container in the first place If you really have to give root, give looks-like-root If that's not enough, give root but build another wall
  • 23. Root in the host Root in the container Uruks (intruders)
  • 24. There is more than one threat model Regular applications - web servers, databases, caches, message queues, ... System services (high level) - logging, remote access, periodic command execution, ... System services (low level) - manage physical devices, networking, filesystems, ... Kernel - security policies, drivers, ... The special case of immutable infrastructure
  • 26. Regular applications Apache, Nginx, MySQL, PostgreSQL, MongoDB, Redis, Memcached, Cassandra, Hadoop, RabbitMQ... Virtually all your programs in any language (services, web services, workers, everything!) They never ever need any kind of root privilege (except to install packages) Don't run them as root! Ever!
  • 27. Regular applications Risk: they run arbitrary code - vector: by definition, they are arbitrary code - vector: security breach causes execution of malicious code Fix: nothing - by definition, we are willing to execute arbitrary code here Consequence: assume those apps can try anything to break out
  • 28. Regular applications Risk: escalate from non-root to root - vector: vulnerabilities in SUID binaries Fix: defang SUID binaries - remove them - remove suid bit - mount filesystem with nosuid
  • 29. Regular applications Risk: execute arbitrary kernel code - vector: bogus syscall (e.g. vmsplice* in 2008) Fix: limit available syscalls - seccomp-bpf = whitelist/blacklist syscalls Fix: run stronger kernels - GRSEC is a good idea (stable patches for 3.14 since July 4th) - update often (i.e. have efficient way to roll out kernel upgrades) *More details about that: http://lwn.net/Articles/268783/
  • 30. Regular applications Risk: leak to another container - vector: bug in namespace code; filesystem leak* Fix: user namespaces - map UID in container to a different UID outside - two containers run a process with UID 1000, but it's 14298 and 15398 outside Fix: security modules (e.g. SELinux) - assign different security contexts to containers - those mechanisms were designed to isolate! *Like the one showed in the beginning of this talk!
  • 32. System services (high level) SSH, cron, syslog... You use/need them all the time Bad news: they typically run as root Good news: they don't really need root Bad news: it's hard to run them as non-root Good news: they are not arbitrary code
  • 33. System services (high level) Risk: running arbitrary code as root - vector: malformed data or similar (note: risk is pretty low for syslog/cron; much higher for SSH) Fix: isolate sensitive services - run SSH on bastion host, or in a VM - note: this is not container-specific (if someone hacks into your SSH server, you'll have a bad time)
  • 34. System services (high level) Risk: messing with /dev - vector: malicious code Fix: “devices” control group - whitelist/blacklist devices - fine-grained: can allow only read, write, none, or both - fine-grained: can specify major+minor number of device
  • 35. System services (high level) Risk: use of root calls (mount, chmod, iptables...) - vector: malicious code Fix: capabilities - break down “root” into many permissions - e.g. CAP_NET_ADMIN (network configuration) - e.g. CAP_NET_RAW (generate and sniff traffic) - e.g. CAP_SYS_ADMIN (big can of worms )☹ - see capabilities(7)
  • 36. Interlude: CAP_SYS_ADMIN Operations controlled by CAP_SYS_ADMIN...  quotactl, mount, umount, swapon, swapoff  sethostname, setdomainname  IPC_SET, IPC_RMID on arbitrary System V IPC resources  perform operations on trusted and security Extended Attributes  set realtime priority (ioprio_set + IOPRIO_CLASS_RT)  create new namespaces (clone and unshare + CLONE_NEWNS)
  • 37. System services (high level) Risk: messing with /proc, /sys - vector: malicious code Fix: prevent unauthorized access control - Mandatory Access Control (AppArmor, SELinux) - remount read-only, then drop CAP_SYS_ADMIN to prevent remount Fix: wider implementation of namespaces - some parts of procfs/sysfs are “namespace-aware” - some aren't, but can be fixed (by writing kernel code)
  • 38. System services (high level) Risk: leaking with UID 0 - vector: malicious code Fix: user namespaces - already mentioned earlier - UID 0 in the container is mapped to some random UID outside - you break out: you're not root - you manage to issue weird syscalls: they're done as unprivileged UID Caveat: user namespaces are still new. We have to see how they behave with that!
  • 40. System services (low level) Device management (keyboard, mouse, screen), network and firewall config, filesystem mounts... You use/need some of them all the time But you don't need any of them in your containers - physical device management is done by the host - network configuration and filesystems are setup by the host Exceptions: - custom mounts (FUSE) - network appliances
  • 41. System services (low level) Risk: running arbitrary code as root - vector: malformed data or similar Fix: isolate sensitive functions - “one-shot” commands can be fenced in privileged context (think “sudo” but without even requiring “sudo”) - everything else (especially processes that are long-running, or handle arbitrary input) runs in non-privileged context - works well for FUSE, some VPN services
  • 42. System services (low level) Risk: run arbitrary code with full privileges - vector: needs a process running with full privileges (rare!) - vector: malformed data, unchecked input… classic exploit Fix: treat it as “kernel” - we'll see that immediately in the next section
  • 44. Kernel Drivers - they can talk to the hardware, so they can do pretty much anything - except: virtualize the bus and use e.g. driver domains (Xen) Network stacks - this probably has to live into the kernel for good performance - except: DPDK, OpenOnload... (networking stacks in userspace) Security policies - by definition, they control everything else - except: there might be nested security contexts some day
  • 45. Kernel Risk: run arbitrary code with absolute privileges Fix: ?
  • 46. Reality check: if you run something which by definition needs full control over hardware or kernel, containers are not going to make it secure. Please stop trying to shoot yourself in the foot safely.
  • 47. Reality check: if you run something which by definition needs full control over hardware or kernel, containers are not going to make it secure. Please stop trying to shoot yourself in the foot safely.
  • 48. Kernel Risk: run arbitrary code with absolute privileges Fix: give it its own kernel and (virtual) hardware - i.e. run it in a virtual machine - that VM can run in a container - that VM can hold a container - run a privileged container in Docker in a VM in a container in Docker https://github.com/jpetazzo/docker2docker - inb4 xzibit meme
  • 51. Immutable immutable infrastructure New rule: the whole container is read-only Compromise: if we must write, write to a noexec area Scalability has never been easier (if totally read-only) It's even harder for malicious users to do evil things
  • 52. Recap (in no specific order!)  don't run things as root  drop capabilities  enable user namespaces  get rid of shady SUID binaries  enable SELinux (or AppArmor)  use seccomp-bpf  get a GRSEC kernel  update kernels often  mount everything read-only  ultimately, fence things in VMs
  • 53. Thank you! Questions?  don't run things as root  drop capabilities  enable user namespaces  get rid of shady SUID binaries  enable SELinux (or AppArmor)  use seccomp-bpf  get a GRSEC kernel  update kernels often  mount everything read-only  ultimately, fence things in VMs See also: - Docker in Production (1:40pm today) - Office hour (10:40am tomorrow, expo hall Table A) - Docker meet-up at New Relic (tomorrow evening)