Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPrometheus docker container shouldn't run as user nobody #3441
Comments
This comment has been minimized.
This comment has been minimized.
For what reasons? |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
|
Sounds good to me. If it's the best practice to give the option to change the UID in order to have control over file owners, wanna send a PR for that? |
This comment has been minimized.
This comment has been minimized.
nrvnrvn
commented
Nov 19, 2017
|
It is a curious question. So:
BUT Containers are somewhat different beasts... See:
Basically this instruction does not bind to the specific user but to the specific UID. And you always can easily override it in docker/kubernetes. $ docker run --user 1234:5678 --rm -ti busybox
/ $ id
uid=1234 gid=5678
/ $ So unless you f*cked up somewhere else I find it pretty safe to run a single process container under any Any objections to the above are welcome :) P.S. From what I've seen so far from various vendors people follow both paths (either creating a separate user or using 65534[debian-based/alpine] or 99[centos-based]) |
This comment has been minimized.
This comment has been minimized.
|
Kubernetes does not (at least not yet) allow you to change the primary GID of a pod/container. There are some patches making their way through the process but AFAIK they are not part of any released version of Kubernetes. Also, "just" changing the UID/GID that the primary process runs as isn't always sufficient. Depending on the security model, changing the ownership of some files may be necessary as part of the startup process. In any case, choosing 99 as the default UID/GID isn't the best idea since it's likely that a low number may be in use by other things in the overall system. If we're going to stick with a fixed UID/GID it'd be better to use something semi-random like 9090. |
This comment has been minimized.
This comment has been minimized.
nrvnrvn
commented
Nov 21, 2017
•
|
Let's assume we have two containers running in the system (single or multi-host, no matter), with volumes attached and both of them use the same pair of uid:gids (say 5555:5555). Hence the attached volumes' files are recursively owned by 5555:5555. What are the possible implications in this case? |
This comment has been minimized.
This comment has been minimized.
2color
commented
Dec 5, 2017
I think the correct UID would be
UID 99 is the default nobody in Centos |
brian-brazil
added
the
priority/Pmaybe
label
Dec 8, 2017
This comment has been minimized.
This comment has been minimized.
|
In our docker compose, I was able to use ":user 1234:5678" concept as mentioned above along with our Ansible deploy play to set the directory permissions on anything volume mounted. Container runs perfectly |
This comment has been minimized.
This comment has been minimized.
nemo83
commented
Apr 13, 2018
|
@silentpete do you have an example of the docker-compose with the user uid/gid configuration? I can set the |
This comment has been minimized.
This comment has been minimized.
|
Hello @nemo83 ,
Can see the user in the container with
which I copied out of: https://github.com/silentpete/pg-h.io/blob/master/docker-compose.yml Hope this helps, PS, I created a 9090:9090 (user and group) on my host, then set the volume mounted in directory to have the correct permissions for the data being saved out of the container. |
idavidmcdonald
referenced this issue
May 29, 2018
Merged
Change user permissions on instance user data template #19
This comment has been minimized.
This comment has been minimized.
|
The main problem w/ running containers as non-root is K8s. How do you guys solve the fact that k8s persistent volumes are generally mounted as root-writeable only? It seems to me that the general trend is to let users specify their UIDs, either via remapping in docker, or |
This comment has been minimized.
This comment has been minimized.
nrvnrvn
commented
Nov 6, 2018
|
Setting Can't say anything for openshift though. I hope they have got some solution for that anyway. |
This comment has been minimized.
This comment has been minimized.
|
Another issue with fsGroup is that it operates at pod level only, so it forces all mounts to that gid which may not be ideal. Openshift manages UID/GID itself - it has an admission controller I believe which overrides runAsUser / fsGroup. But unfort. it will forbid your pod entirely if you set those values, so building a single pod definition to work across different k8s flavors isn't possible w/ non-root users (as far as I can tell). |
This comment has been minimized.
This comment has been minimized.
|
The solution that I've seen/used is to use an init container. Perhaps not ideal but it works.
|
jcollie commentedNov 8, 2017
With the update to 2.0, the Docker container was modified so that Prometheus runs as the user "nobody" (UID/GID 99/99) (#2859). While it's good that Prometheus is no longer running as root, it's not the best idea either to run as "nobody". There are many examples of Docker containers out there that allow changing the UID/GID at runtime that could be borrowed from. At a minimum a different static UID/GID should be used.