-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
docker: Automatically fix permissions #3744
Conversation
This patch is delaying the point where permissions are dropped into the `start_ipfs` script. This way, instead of exiting on permission issues, we can fix them on our own inside the script, then drop privileges and continue doing ipfs specific stuff with the correct user. I've removed the `chmod 0777` step from the readme since it's not needed anymore. License: MIT Signed-off-by: kpcyrd <git@rxv.cc>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: scratch that, I thought Docker used user namespaces by default (LXC does). EDIT2: Then it creates possible security hole. We hardcode UID 1000 as our UID. This means that the volume will be |
@Kubuxu hrm... shouldnt it fail if the user running the docker commands doesnt have access to the data? If not then i can use docker to access any files on a system that i have docker rights on |
No, they have to be passed as volume and as by default docker container runs as root, anything that is passed as volume is accessible from docker. In this case the situation is: the docker container start as root with volume passed, the volume is owned by Alice, the container runs chown with UID 1000 (user ipfs UID in container). Outside of the container UID 1000 is assigned to Eve, now Eve has access to all the data. |
This is why user namespace was introduced into docker but AFAIK it is not default. |
IMO we should have env variable that allows to pass GID when starting the container. This way user can chown the to be volume to given group and then we can use that group. @lgierth can you look at the discussion here. |
I'm not sure about the security hole.
gives you a root shell with the host filesystem mounted at It's also how mongodb and mysql do it: I'm not using docker internal volumes, I'm using ipfs with bindmounts ( If you use docker internal volumes, the permissions are fine, currently with bindmounts it looks like this:
That's also the reason why the readme suggested chmod'ing the folder to 777, which is probably worse. If you're worried that you have a legitimate uid=1000 who is then able to access the data (which is currently the case as well), you have to create a folder that is owned by root:root with permissions The container has permissions to access it, but a local uid=1000 can't access it's parent directory. |
@lgierth thoughts here? |
Besides the discussion about security, is there anything else that needs attention? |
I think this LGTM, but I'll test-deploy it just to make sure. Thanks for getting us rid of the |
Works nicely! 👍 The infra scripts first broke on: > docker run -i -v "$repo:/data/ipfs" --entrypoint /bin/sh "ipfs:$ref" -c 'ipfs init --bits 2048'` but then I noticed I could now shorten that to: docker run -i -v "$repo:/data/ipfs" "ipfs:$ref" init --bits 2048 Thanks! |
Ah nevermind :D |
Anyhow, I added |
This patch is delaying the point where permissions are dropped into the
start_ipfs
script. This way, instead of exiting on permission issues, we can fix them on our own inside the script, then drop privileges and continue doing ipfs specific stuff with the correct user.I've removed the
chmod 0777
step from the readme since it's not needed anymore.License: MIT
Signed-off-by: kpcyrd git@rxv.cc