Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Accuracy w/r/t https://github.com/docker/labs/tree/master/security/capabilities #469

Open
jleadford opened this issue Aug 12, 2019 · 3 comments

Comments

@jleadford
Copy link

The noted page states:

"Docker images cannot have files with capability bits set. This reduces the risk of Docker containers using capabilities to escalate privileges. However, it is possible to mount volumes that contain files with capability bits set into containers. Therefore you should use caution if doing this."

I wanted to try this out. I spun-up an Ubuntu container on the newest version of Docker Desktop CE for macOS, which packages Docker 19.03.1, i.e. docker run -it --rm ubuntu /bin/bash

Docker retains the SETFCAP capability by default, and to use it I installed libcap2, libcap2-bin.

I was able to use setcap on a file inside my container's rootfs, but do note that the container's bounding set restricted me from using e.g. CAP_SYS_ADMIN upon executing the file with execve:

EBvkr9MVUAMueyB

In this case, execve returns EPERM (PoC behaves the same way in default Docker container, strace is just for illustration), which seems related to the following at http://man7.org/linux/man-pages/man7/capabilities.7.html, noting that a file's capabilities are masked off by the process's bounding set:

EBvpOiQU0AEnVJR

And also note the following at https://www.kernel.org/doc/ols/2008/ols2008v1-pages-163-172.pdf

EBvuK4fUwAAuqA8

Docker's inheritable set matches its bounding set (that is, the Docker default capabilities), so even if the file holds a capability in its inheritable set, it's not brought up into the permitted set for the resulting process:

EBvwOS_UwAE3DUB

So, I am not certain file capabilities are an issue for Docker, in any case.

@jleadford
Copy link
Author

Also, as moby/moby#5650 (comment) and my examples note, looks file file caps /are/ supported by at least some images (e.g. Ubuntu), so I don't think "Docker images cannot have files with capability bits set." is accurate either.

@loot-king
Copy link

🙏

@amouat
Copy link

amouat commented Aug 12, 2020

Files inside docker images can have capabilities set, so the page is wrong as it stands.

As proof, you can clone this repository https://github.com/ContainerSolutions/capabilities-blog/ and run:

$ docker build -t capblog .
...
$ docker run capblog getcap /set_ambient
/set_ambient = cap_net_bind_service+p

This may only work with some storage drivers however.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants