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

Merge fixdockergid with fixuid #29

Open
felipecrs opened this issue Aug 13, 2020 · 7 comments
Open

Merge fixdockergid with fixuid #29

felipecrs opened this issue Aug 13, 2020 · 7 comments

Comments

@felipecrs
Copy link

felipecrs commented Aug 13, 2020

I made fixdockergid to prove that #19 is a valid use case.

However, it would be so cool to have this functionality in fixuid instead, so we would not have to deal with this twice. fixdockergid depends on fixuid being installed.

This problem happens when you mount the docker.sock from the host machine on the container, and you try to access it using a non-root user. Then, the docker group id on the host can mismatch with the docker group id from the container, thus causing the non-root users to receive permission denied errors when trying to run docker commands. Microsoft solved it by using socat: https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-from-docker#enabling-non-root-access-to-docker-in-the-container

But I consider this approach much better, less intrusive, and less expensive.

@caleblloyd
Copy link
Collaborator

We could consider adding another configuration option, such as:

secondaryGroups:
  - name: docker
    gidFromPath: /var/run/docker.sock

The following rules would apply:

  1. If the path does not exist, log an error and skip the path
  2. If the GID from the path already exists in /etc/groups, do not change the group name, but still add the user to the group (and log a message)

@felipecrs
Copy link
Author

felipecrs commented Jul 19, 2021

Actually, ensuring the group name is docker inside of the container is important, as it allows to use in detached + exec mode:

$ docker run --detach --name=fixdockergid --volume=/var/run/docker.sock:/var/run/docker.sock --user=$(id -u):$(id -g) --group-add=docker felipecrs/fixdockergid sleep infinity
$ docker exec fixdockergid docker version

If the group within the container is not named docker, the --group-add=docker would not be mapping directly to the group which got fixed by fixdockergid, and when running docker exec fixdockergid docker version it would throw a permission denied error.

This use case matters because this is how Jenkins handle pipelines running inside of containers.

@aigarius
Copy link

Does fix of #30 actually address this issue as well?

@caleblloyd
Copy link
Collaborator

caleblloyd commented Aug 18, 2023

I think this could be achieved by adding the GID of the group, computed on the host like this:

docker run ... \
  --volume=/var/run/docker.sock:/var/run/docker.sock \
  --group-add "$(getent group "$(ls -lh /var/run/docker.sock | awk '{ print $4}')" | cut -d':' -f3)"

There may be no named group that matches inside the container, but the container will have access to the socket on the host

@felipecrs
Copy link
Author

I think this could be achieved by adding the GID of the group, computed on the host like this:

docker run ... \
  --volume=/var/run/docker.sock:/var/run/docker.sock \
  --group-add "$(getent group "$(ls -lh /var/run/docker.sock | awk '{ print $4}')" | cut -d':' -f3)"

There may be no named group that matches inside the container, but the container will have access to the socket on the host

Yes, this works. But not for the use case I mentioned... Jenkins.

There, I can pass a list of arguments that should be added to the docker run, but I cannot add a Bash command expansion like this, only static args.

Maybe:

# /etc/fixuid.yml

secondaryGroups:
  - name: docker
    gidFromPath: /var/run/docker.sock
    ensureGroupName: true

@felipecrs
Copy link
Author

If ensureGroupName is enabled, fixuid will not only ensure the user has a group with such GID, but will also rename the group that points to that GID to name:, if one already exists.

@felipecrs
Copy link
Author

Not to mention that we still need the basic functionality of ensuring secondary groups as proposed by @caleblloyd:

secondaryGroups:
  - name: docker
    gidFromPath: /var/run/docker.sock

BTW, I added some tests in fixdockergid to confirm the usefulness of ensureGroupName that I mentioned above:

felipecrs/fixdockergid@2fe4cce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants