Skip to content
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

Really run as non-root user in docker container #5048

Merged
merged 1 commit into from
Dec 11, 2018
Merged

Really run as non-root user in docker container #5048

merged 1 commit into from
Dec 11, 2018

Conversation

manandbytes
Copy link
Contributor

@manandbytes manandbytes commented May 30, 2018

As of now,

$ docker pull ipfs/go-ipfs
Using default tag: latest
latest: Pulling from ipfs/go-ipfs
Digest: sha256:31cc5713ef3e3e81bf868cbb56c19de2d15d661743d8b6077804dee26e929ac5
Status: Image is up to date for ipfs/go-ipfs:latest

ipfs daemon will start as root user:

$ docker run --rm --entrypoint=/bin/sh ipfs/go-ipfs -c whoami
root

but later on will drop priviledges:

$ docker logs ipfs/go-ipfs |head -n 1
Changing user to ipfs

With this change applied, ipfs daemon starts as ipfs user right from
the begining:

$ docker run --rm --entrypoint=/bin/sh ipfs/go-ipfs -c whoami
ipfs

License: MIT
Signed-off-by: Mykola Nikishov mn@mn.com.ua

@manandbytes manandbytes requested a review from Kubuxu as a code owner May 30, 2018 12:55
@whyrusleeping whyrusleeping requested a review from a user May 31, 2018 05:46
@whyrusleeping
Copy link
Member

@lgierth when youre back, would be great to get your review on this

@manandbytes
Copy link
Contributor Author

@lgierth @Kubuxu any progress?

@ghost
Copy link

ghost commented Jul 29, 2018

Why is it better to run as non-root right away?

The advantage of starting as root and then dropping privileges, is that it makes mounting an IPFS_PATH directory easier - no need to fiddle with permissions manually, we can chown in the container if neccessary.

@manandbytes
Copy link
Contributor Author

Why is it better to run as non-root right away?

As a user of (any) external Docker image, I want to reduce an attack surface. USER ipfs clearly communicates, just by looking at the Dockerfile, that there is n-1 problems ahead. OTOH, for the user, it is unclear if IPFS daemon actually drops privilidges, if it doing it right, ath the right time etc.

@Stebalien
Copy link
Member

The advantage of starting as root and then dropping privileges, is that it makes mounting an IPFS_PATH directory easier - no need to fiddle with permissions manually, we can chown in the container if neccessary.

As far as I can tell, this patch doesn't prevent that. It only drops to the ipfs user right before launching the daemon. Note: this would also allow us to drop the su-exec dependency. Am I missing something?

@Stebalien Stebalien added the need/review Needs a review label Aug 20, 2018
@manandbytes
Copy link
Contributor Author

@lgierth @Kubuxu any progress?

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work. However, I think we should leave the current su-exec calls in container_daemon for now in case any users are manually calling start_ipfs as root.

We shouldn't need the chmod $IPFS_PATH call in container_daemon as we:

  1. chmod the directory in the Dockerfile.
  2. Use a volume.

@Stebalien
Copy link
Member

(going to rebase to give this another test)

As of now,

    $ docker pull ipfs/go-ipfs
    Using default tag: latest
    latest: Pulling from ipfs/go-ipfs
    Digest: sha256:31cc5713ef3e3e81bf868cbb56c19de2d15d661743d8b6077804dee26e929ac5
    Status: Image is up to date for ipfs/go-ipfs:latest

ipfs daemon will start as root user:

    $ docker run --rm --entrypoint=/bin/sh ipfs/go-ipfs -c whoami
    root

but later on will drop priviledges:

    $ docker logs ipfs/go-ipfs |head -n 1
    Changing user to ipfs

With this change applied, ipfs daemon starts as ipfs user right from
the begining:

    $ docker run --rm --entrypoint=/bin/sh ipfs/go-ipfs -c whoami
    ipfs

License: MIT
Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
@ghost ghost assigned Stebalien Dec 11, 2018
@ghost ghost added the status/in-progress In progress label Dec 11, 2018
@Stebalien Stebalien removed the need/review Needs a review label Dec 11, 2018
@Stebalien Stebalien merged commit 2464b20 into ipfs:master Dec 11, 2018
@ghost ghost removed the status/in-progress In progress label Dec 11, 2018
@manandbytes manandbytes deleted the docker-non-root branch December 11, 2018 11:05
@hsanjuan
Copy link
Contributor

hsanjuan commented Mar 3, 2019

Hi,

this broke my current integrations but I've only noticed after a new release has been tagged. The default entrypoint changed the user after it has chmod'ed the configuration folder.

docker run -v myfolder:/data/ipfs ipfs/go-ipfs:v0.4.19
ipfs version 0.4.19
initializing IPFS node at /data/ipfs
Error: /data/ipfs is not writeable by the current user
[16:02:31] ~/g/s/g/i/ipfs-cluster (master|…) $ 
docker run -v myfolder:/data/ipfs ipfs/go-ipfs:v0.4.18
Changing user to ipfs
ipfs version 0.4.18
initializing IPFS node at /data/ipfs

As pointed by @lgierth, myfolder does not exist, but is created by docker with root permissions. Before it was correctly chowned, but not anymore. It is not pretty to create a folder specifically with write permissions for the ipfs user because the ipfs user is an arbitrary user with an arbitrary uid inside the container. It made total sense that the cointainer figures out the right permissions for the volume according to whatever user it wants to run with.

I would revert this change. It added zero security while breaking things. In fact, users are now forced to pre-create and relax permissions in the provided volumes, so it probably makes things worse.

hsanjuan added a commit to ipfs-cluster/ipfs-cluster that referenced this pull request Mar 3, 2019
We need to pre-create configuration folders and set write permissions
because ipfs/kubo#5048

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
hsanjuan added a commit to ipfs-cluster/ipfs-cluster that referenced this pull request Mar 3, 2019
We need to pre-create configuration folders and set write permissions
because ipfs/kubo#5048

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
hsanjuan added a commit to ipfs-cluster/ipfs-cluster that referenced this pull request Mar 3, 2019
We need to pre-create configuration folders and set write permissions
because ipfs/kubo#5048

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
geigerzaehler pushed a commit to oscoin/ipfs-test-network-container that referenced this pull request Mar 15, 2019
Since the container uses volumes the user the container is running under
needs write access to these volumes. This must be configured from the
outside and maybe complicated.

See ipfs/kubo#6040 and ipfs/kubo#5048
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants