-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support USER in Dockerfile - when container starts up non-root #19
Comments
Or document the directories which require write access. Then child Dockerfiles can just chown or chmod +w those folders. |
@pikeas That is a good idea too :) Just to re-clarify what you said -
FROM ubuntu-debootstrap:14.04
ENV _clean="rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*"
# Install s6-overlay
ADD https://github.com/just-containers/s6-overlay-builder/releases/download/v1.8.3/s6-overlay-linux-amd64.tar.gz /tmp/
RUN tar zxf /tmp/s6-overlay-linux-amd64.tar.gz -C / && $_clean
# Create user (if not exist already)
RUN useradd mike
# Chown folders
RUN chown -R mike:mike /whichever-s6-folders
# Drop privilege
USER mike
# Run s6 overlay as user 'mike', and PID=1
ENTRTYPOINT ['/init']
|
Pretty much exactly what you've described. So long as the overlay permissions are initially correct, there's no need to double-check them on container start, so that can be removed. |
Hi @dreamcat4, @pikeas, Can someone give me some use cases in order to identify why should I implement USER support in the overlay? I've been using it these months and I feel comfortable having root privileges in the boot process, and dropping them when I need to execute my custom services. |
Just for general case, for best compatibility when auser wants to use the |
Of course, this requirement should be part of the documentation. I'll try to complete the readme this month, at least the most important parts of the overlay. |
Closing this due to: #79. |
This issue is about implementing USER support, and/or adding a workaround (list of directories/files which need to be writeable). Linked PR only says USER is unsupported. Re-open until docs are updated or USER support is added? |
I'm not going to re-open this mainly because (sorted by importance):
|
Here is the workaround that I am using ATM. If you do sudo -E su "$user" << EOF
# start your daemon here
EOF |
Why not this instead of depending in another utility?
|
Sure if it works from a regular bash / shell script. Sorry I am not aware of these things. |
Ah I see. The |
Wrapped by sh
Without any dependency, this would execute one
Hope it helps ;) |
How do you guys deal with redirecting output when dropping priviliges with s6? For example, I now run with
Because I have this in a config to get I tracked it down a bit to docker-library/nginx#4 which points to moby/moby#6880 and apparently says it is fixed in Docker 1.9 or higher when using I'm ok with not being able to do |
It seems in this PR they fixed it by really looking at |
@CumpsD unfortunately, still not fixed when not using the USER directive: moby/moby#31243 |
Why this is closed? If not yet implemented, it's not supposed to be closed. To implement such a thing, though, we need to use |
I made one example here: https://github.com/felipecrs/fixdockergid |
As of version
Right now, the solution I have is to install a new, small binary with the For other parts, it comes down to 1) how important is it to work with the Having to create a lot of these small utilities may not be super maintainable, but I don't want to take any approach that runs large chunks of |
Closing since as of version |
So to recap. The Docker
USER
directive in Dockerfile. It is a part of the official Docker feature set. The directive provides a simple way to allow people to run their apps with better security by not being the root user. There are other ways people can write containers to achieve the same thing. By starting asroot
then dropping privileges to the target user before running their program. Or have the program do that itself when it starts up.However it would provide best and most complete support for Docker community - if we can support
USER
directive. Not sure how much messing about is required to do that.The problem presented isn't just about modifying our scripts to avoid doing the [env]setuidgid on processes. But rather it may be difficult to some of these helper processes (logging and such) to be permitted to write to certain directories, when beforehand the overlay tarball does not know which the process UID will be.
Another possible solution might be to assign a single fixed PID number (we choose in the 32000 range again). And tell users they must configure their docker
USER
to be only that particular fixeduid:gid
. Which means we can know it beforehand, and (again) hard-code directories to be owned by that single pre-determined UID number.The text was updated successfully, but these errors were encountered: