What are the potential security problems running untrusted code in a Docker container as a non-root user?

醉酒当歌 提交于 2020-12-25 00:54:43

问题


I've seen plenty of ink spilled by now about how Docker is not sufficiently isolated to allow arbitrary containers to be run in a multi-tenant environment, and that makes sense. "If it's root in Docker, consider it root in the host machine." What about non-root though?

If I want to take some untrusted code and run it in a container, can it be done safely so long as the container is running as a non-root non-sudo user? What are the potential security pitfalls of doing something like that?

I'm fairly sure there are production applications doing this today (CI systems, runnable pastebins), but are they just lucky not to have had a determined attacker or is this a reasonable thing to do in a production system?


回答1:


As of Docker v1.12, if one runs a container as a non-root user with user namespaces enabled, there are two levels of privilege escalation a malicious actor needs to perform in order to become root on host:

  1. Escalate from non-root to root user inside container
  2. Escalate to root user in container to root user on the host

So in case untrusted code is run inside a Docker container as non-root user, it will be slightly more difficult for an attacker to become root on host, since we add an extra step of becoming root inside container. That's the only advantage in terms of security compared to running containers with root privileges.

In case of privilege escalation through both layers of security, following should help restrict the attack surface:

  1. Workloads(more specifically docker containers, in this context) with different trust levels should be isolated from each other by use of overlay networks following least privilege principle.
  2. Enabling available Linux security module in enforcement mode(e.g. SELinux, AppArmor)

References:

  • Running with non-root privileges inside containers: https://groups.google.com/forum/#!msg/docker-user/e9RkC4y-21E/JOZF8H-PfYsJ
  • Overlay networks: https://docs.docker.com/engine/userguide/networking/get-started-overlay/
  • User namespaces: https://docs.docker.com/engine/security/security/#/other-kernel-security-features



回答2:


All containers share the same kernel. In case your un-trusted code manages to perform a kernel exploit, it can do whatever it wants on the host and/or any other running container.



来源:https://stackoverflow.com/questions/32257830/what-are-the-potential-security-problems-running-untrusted-code-in-a-docker-cont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!