moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.18k stars 1.16k forks source link

Proposal: document Dockerfile building security promises #4822

Open nakedible opened 8 years ago

nakedible commented 8 years ago

Currently it seems very hard to find any documentation on what kind of security is promised by Dockerfile execution, especially if building Dockerfiles from untrusted sources.

As far as I can gather, the security is as follows:

This means that if these limitations are acceptable, it is possible to allow building Dockerfiles from untrusted sources without creating a separate VM or similar to contain the build.

I assume something like this is already done by Docker Hub when builds are submitted to it, as it probably does not use a separate VM for each build, so the priviledge separation probably has been tested quite rigorously.

Is my assessment correct? Should this be explicitly documented somewhere?

thaJeztah commented 8 years ago

Is my assessment correct? Should this be explicitly documented somewhere?

I think that documenting it would indeed be a nice addition; I don't think we currently mention this

I assume something like this is already done by Docker Hub when builds are submitted to it, as it probably does not use a separate VM for each build, so the priviledge separation probably has been tested quite rigorously.

Actually, Docker Hub uses dedicated nodes for each account/build, but the main reason here was performance, and security from a different perspective; so that Docker Hub can guarantee no build artifacts are left on the machine that your automated build is executed on. See the blog announcement here; https://blog.docker.com/2015/11/upgraded-autobuild-docker-hub/

With our new infrastructure, each user has their own private build queue This way your builds will start quickly and in a predictable manner.

In addition, builds are now more secure. The build system spins up a new build node for each build request. This guarantees that private build artifacts that may be left over from one build cannot be retrieved by a malicious user.

ping @NathanMcCauley @diogomonica @tiborvass I think the above description is correct, but is there anything I overlooked?

thaJeztah commented 8 years ago

Thinking a bit more; one possible resource exhaustion is disk space; disk space is not limited, so docker build could use up available disk space on the host (either through the container's filesystem, or if a VOLUME is present in the Dockerfile)

nakedible commented 8 years ago

Right, disk space needs to be mentioned also as a limitation, although that's probably acceptable to most as well and could be controlled by quotas/whatever.

collimarco commented 3 years ago

I asked a similar question a few days ago: https://stackoverflow.com/questions/65647751/building-docker-images-provided-by-untrusted-users-in-a-saas

For now the only solution that I have found is to create/destroy a VM for every build... But that is not straightforward.

Are there any updates on this? Have you found any solution to safely build an untrusted Dockerfile inside a multi-tenant environment?

thaJeztah commented 3 years ago

For now the only solution that I have found is to create/destroy a VM for every build... But that is not straightforward.

Running a "per user" rootless daemon could help to some extend, but overall, this would still be my recommendation when dealing with fully untrusted loads.

Also things to add to the list;

cpuguy83 commented 3 years ago

It may be worthwhile, at least for docker build for us to supply a custom procfs as lxc does. And disable CAP_NET_RAW if it is not already.

bain3 commented 1 year ago

Hi! Any updates? I'd like to know how building an image compares to running a container. Unfortunately I haven't found any documentation around build security so far...

thaJeztah commented 7 months ago

Let me transfer this to the buildkit repository, as that's where the builder is now maintained (we should indeed look at spending some time documenting more of this)

jedevc commented 7 months ago

Buildkit's security boundary is documented here: https://github.com/moby/buildkit/blob/master/PROJECT.md#security-boundary

There's obviously the potential to improve it, but we do have something already existing there.

thaJeztah commented 7 months ago

Ah, yes, we were going through some old tickets in moby/moby, and stumbled on this one. Let me /cc @dvdksn as well to see if there's things to improve (and / or move / copy to relevant sections in the docs)