umputun / baseimage

minimalistic docker base image to build and deploy apps
MIT License
113 stars 20 forks source link

Is app user secure enough? #32

Open zonescape opened 1 day ago

zonescape commented 1 day ago

Usually processes in a container are run under unprivileged user because of security reasons. But app user belongs to the docker group. If we assume that there is a bug in the container isolation that causes the container process to execute in the host context, then the app user will have almost the same privileges as root. So what is the meaning of app user? Why not just use root user?

umputun commented 1 day ago

From what I understand being part of the Docker group inside a container has no special meaning or security implications if the Docker socket (/var/run/docker.sock) is not mounted into the container. So, having app a part of docker group by itself doesn't affect isolation, but allows users to mount host's docker.sock in case of need.

paskal commented 16 hours ago

@zonescape, could you please include this information in the Readme? This would help address this question for everyone. Your explanation would likely be more comprehensive than what we could come up with.

zonescape commented 11 hours ago

@umputun

being part of the Docker group inside a container has no special meaning or security implications if the Docker socket (/var/run/docker.sock) is not mounted into the container.

The same is valid for the root user. Unless Docker socket is mounted into the container, the root user has no special meaning due to isolation. But it becomes dangerous if there is a bug in the container isolation. In this case I don't see much difference between app and root users. Of course inside a container the root user has more privileges than the app but taking into account that all useful stuff in a container is the application data which must be accessible to whatever user running the container process so there is no much difference between any users. The difference reveal itself when there are bugs in the container isolation.

@paskal I am not a security expert, hence the question. All my colleagues run images as root, almost all Dockerfiles here, on GitHub, supposed to be run as root. Nobody cares. In that respect app user is a hardened steel security measure. But I don't know how good it is in the general case.

umputun commented 5 hours ago

I’m not a security expert either, but this is my understanding of why using a non-root user inside the container (even when added to the docker group) is preferred over running as root:

That said, I can understand the concern about having the app user as part of the docker group or even having a matching docker group inside the container. Personally, I don’t think this is a real security risk; however, if you want to eliminate it and create another flavor of the base image without this group, please feel free to submit a PR. Please note: we can't change the current image as it will break compatibility; however, nothing is preventing us from making a new one, i.e., baseimage.app-paranoid or something like this.