9 ms·
Understanding Docker Container Escapes
- oso2k 7y agoThe title ought to be updated to specify the container types in question are privileged containers. Even if the original blog post doesn’t. A privileged container is quite like running a process with a user that has sudo permission. Being surprised that such a container can do bad things seems disingenuous. It’s like saying, “When you give me the keys to your house, I can rob you blind. I just need to figure out which key is for the front door.”
- tptacek 7y agoThe post says, over and over, almost ad nauseam, that you shouldn't be using --privileged and that the original tweet depends on --privileged; moreover, it presents an alternate version of the escape that doesn't depend on --privileged (but does depend on other elevated privileges). The title should not in this case be editorialized; relative to the topic, it's about as boring as titles come.
- lawnchair_larry 7y agoI think the title is a bit clickbaity, perhaps unintentionally. I think parent’s point is that this post isn’t really going to teach you anything at all about docker container escapes, but rather, it teaches you about escaping containers that an admin took several deliberate uncommon and non-default steps to basically escape the container for you. If one clicked it to learn about real world container escapes, they left disappointed.
- zeroxfe 7y agoThis is a weird kinda escape. The only time I use --privileged is when I'm debugging, _because_ it lets me easily elevate access. Does anyone actually run privileged containers for production workloads?
- wearsaredhat 7y agoContainer security products like Twistlock require privileged access. I’m sure there are other use cases.
- rtempaccount1 7y agoThere's some cases where it's use in Kubernetes. Some of the system pods will run privileged and also some CNI pods will too.
- ianamartin 7y agoIf a thing can be done, some nontrivial number of people do it in production. The number of people who do it in production is correlated with the complexity of the thing they are trying to do and how much the "fuck it, just do <some terrible idea>" relieves that complexity.
- Xylakant 7y agoElasticsearch requires some sysctls set on the node and some of the helm charts around use a privileged init container to set those. A solution that’s obviously more or less accepted, though one I personally dislike.
- tln 7y agoNot sure about production workloads but its not just privileged containers you start that should be a concern.. anyone who can access /var/run/docker.sock can run a privileged container, so this can be a privilege escalation. Because of this escape, giving access to /var/run/docker.sock to regular users is the same as giving them root access. Also as the article says mounting /var/run/docker.sock is (now, because of this escape) the same as giving that container access to the host system.
- based2 7y agohttps://www.reddit.com/r/netsec/comments/cfh7rk/understanding_docker_container_escapes/ https://www.reddit.com/r/netsec/comments/cfh7rk/understandin...
- rtempaccount1 7y agoWhilst from an overall security perspective, this may not be that meaningful (the pre-req's are CAP_SYS_ADMIN or --privileged), it's still a really neat hack. Also a good demonstration of how runc container security is really just Linux security, and the isolation provided by that type of container, is dependent on underlying Linux features. I could see circumstances where this would be of practical use, where you've landed in a privileged container and are looking for a relatively easy/universal breakout to the underlying node. The ToB breakdown is cool too as the initial tweet was a bit hard to parse, unless your Bashfu is good. (ofc the post from ToB I'm really looking forward to hasn't been released yet, which is what they found in the Kubernetes audit)
- panpanna 7y agoTwo minor remarks: 1. Docker is not synonymous with Linux containers. LXC for example has always had much better security than Docker despite using the same infrastructure. 2. You don't need to interface the kennel directly. There is for example a Google project (gvisor?) that acts as a syscall proxy in userland to combat these types of problems.
- rtempaccount1 7y agoOut of curiosity, what makes you say that LXC has better security than Docker? What aspects of LXCs design or implementation provide additional security controls over those of Docker?
- panpanna 7y agoFor example LXC containers are unprivileged by default. If you escape the container you end up as a normal user on host, not root. LXC main dev is on HN. I'm sure he can explain this much better.
- rtempaccount1 7y agoI'm not sure I follow you here. The Docker daemon runs as root (which is kind of inevitable, if you don't then you end up needing hacks like slirp4netns to hook up networking) However, there's nothing innately inside Docker that requires contained processes to run as root. Indeed it's a standard part of recommended Docker security guidance not to run your contained processes as the root user. Docker also provide the facility to enable user namespaces at the daemon level, so that root inside the container != root on the host.
- OJFord 7y agoObviously CAP_SYS_ADMIN and root-running containers should be avoided. But on the occasion that they're necessary, isolating from other pods with a network policy and having no public ingress is enough right? Assuming of course that you trust the container process(es) - or is that the issue?
- rtempaccount1 7y agoI'd say "that depends" For example if you're running Kubernetes, then if you have a user who has RBAC rights to exec into a privileged pod, but doesn't have rights to create new privileged pods, then this could be a privesc risk, as they can use something like this to escalate to the underlying node after exec'ing into the privileged pod. It (as with all things security) depends on your threat model :)
- OJFord 7y agoGood point - I was thinking that 'operators' were trusted though, potential threat is the (ab)users of the running software. As far as I can tell, as long as there is no service/ingress on the privileged container, and a netpol blocks those that do from accessing it, it's less than ideal but 'ok' that this privileged container is running behind the scenes.
- the8472 7y agoLateral movement of an attacker within your cluster would also be a problem.
- paulddraper 7y agoAFAIK, that's the only what to run Chrome unless you disable Chrome's sandboxing.
- king_phil 7y agoFunny thing about docker container security, bug that has not been fixed for ages: a custom AppArmor profile is only applied on the first container start, but for no later restart. Yes, the container runs in the "unconfined" profile after a restart. https://github.com/moby/moby/issues/38075 https://github.com/moby/moby/issues/38075
- zapita 7y agoThat’s disingenuous. In this issue, the maintainers clearly explain that running your container as privileged is supposed to disable all confinement by apparmor. The bug is that the custom apparmor profile is sometimes applied, when it should never be. This is not a security issue in any way since the container is already privileged.
- king_phil 7y agoBut in a privileged container you could still take away capabilites and/or permissions with an apparmor profile. Sometimes that happens, sometimes it does not. And when it does not, you have no way of knowing.
- zapita 7y ago> But in a privileged container you could still take away capabilites and/or permissions with an apparmor profile. Right, what you want is “privileged except for XYZ”, which is not supported by Docker. That’s a missing feature which is not the same as a bug. Calling it a security bug is even more misleading. > Sometimes that happens, sometimes it does not. And when it does not, you have no way of knowing. Right, it should fail every time. That is a bug. But it’s not security bug, and fixing that bug won’t give you the feature you want, it will just make it clearer that the feature is not supported.
- awinter-py 7y ago> use official docker images (as a mitigation) okay, but even for official images, figuring out the provenance of a build on docker hub is totally impossible I challenge you to start with an image sha and tell me what git version (or even what repo) was used to create it docker needs to get better at supply chain
- mychael 7y agoThe author is presenting this as if they found a serious security flaw in Docker. They're starting a container in privileged mode, what exactly did they expect? This is like acting surprised that a Linux root user can do immeasurable harm to the underlying OS.