8000 daemon/listeners: use chgrp binary for docker.sock by kolyshkin · Pull Request #39605 · moby/moby · GitHub
[go: up one dir, main page]

Skip to content

Conversation

kolyshkin
Copy link
Contributor
@kolyshkin kolyshkin commented Jul 24, 2019

In case the daemon is compiled statically, it is not using glibc's
uid/gid to name resolving functions (because of osusergo build tag),
and so users who

  1. use LDAP, NIS, or similar stuff, and
  2. not relyingon systemd creating the docker.sock file

will suffer from the issue described in docker/for-linux#186.

Commit a2e3846 (PR #38126) fixed that, but not for the static build case.

So, instead of relying on golang os/user doing a lookup, let's just call
chgrp binary and have it do a group name to gid conversion.

PS Commit messages from c7c2cd4 and 169c013 helped me to
figure out why the code is the way it is.

In case the daemon is compiled statically, it is not using glibc's
uid/gid to name resolving functions (because of `osusergo` build tag),
and so users who (1) use LDAP, NIS, or similar stuff and (2) not relying
on systemd creating the docker.sock file will suffer from the issue
described in docker/for-linux#186.

Commit a2e3846 fixed that, but not for the static build case.

So, instead of relying on golang os/user doing a lookup, let's just call
chgrp binary and have it do a group name to gid conversion.

PS Commit messages from c7c2cd4 and 169c013 helped me to
figure out why the code is the way it is.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@justincormack
Copy link
Contributor

We need to add this to the list of requirements for running Docker if we are shelling out.

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Jul 25, 2019
@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "chgrp-docker-sock" git@github.com:kolyshkin/moby.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842359065288
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

Co-Authored-By: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin kolyshkin force-pushed the chgrp-docker-sock branch from a5b2354 to b576b70 Compare July 25, 2019 15:48
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Jul 25, 2019
@kolyshkin
Copy link
Contributor Author

Second patch is optional and can be removed

@kolyshkin
Copy link
Contributor Author

We need to add this to the list of requirements for running Docker if we are shelling out.

@justincormack where is this list?

@kolyshkin kolyshkin requested a review from thaJeztah July 25, 2019 15:49
return nil, errors.Wrapf(err, "can't create unix socket %s", addr)
}
if socketGroup != "" {
out, err := exec.Command("chgrp", socketGroup, addr).CombinedOutput()
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could do this only in the fallback if lookup with go implementation fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonistiigi can you please elaborate why do you want to have both implementations? In case chgrp binary is not available, or as an optimization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was asking to distinguish between the two cases because if you want an optimization (skip exec'ing chgrp if possible) I think in some cases lookupGID() might return some wrong result (say on a system with NIS or somesuch enabled), and in this case we'll end up with a wrong socket group, thereas chgrp should always be right.

If, on the other hand, you are concerned that chgrp binary might not be available, when we can amend the current code by falling back to lookupGID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...but I think a POSIX system lacking chgrp is something extremely weird, and an exit with an error seems like a proper thing to do in such case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tonistiigi. Having the Go implementation as a default when Docker isn't statically linked does seem to be a good idea. Docker already relies on some binaries being present on the systems. It doesn't seem to be a good idea to introduce new requirements. The packages would have to be adjusted as well. POSIX systems may indeed have chgrp. Containers and other such stripped down environments may not.

@thaJeztah
Copy link
Member

@kolyshkin could you have a look at @tonistiigi's comment?

@thaJeztah
Copy link
Member

ping @kolyshkin

@AkihiroSuda
Copy link
Member

Is this still on plan?

Copy link
Member
@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

@kolyshkin this needs a rebase now, because I opened the second commit as a separate PR to make this diff smaller; if it helps, I did a rebase of your branch and pushed it here; https://github.com/moby/moby/compare/master...thaJeztah:carry_39605_chgrp_docker_sock?expand=1

Comment on lines +39 to +40
gid := os.Getgid()
l, err := sockets.NewUnixSocket(addr, gid)
Copy link
Member

Choose a reason for hiding this comment

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

nit: could simplify to

Suggested change
gid := os.Getgid()
l, err := sockets.NewUnixSocket(addr, gid)
l, err := sockets.NewUnixSocket(addr, os.Getgid())

However, with the current code, it looks like we'll be creating the socket to have the root group, not the docker group, correct? (I expect the process to be running as root:root, and not docker to be the primary group), and then do a chown after, so we'll always be chown-ing twice

Note that more recent versions of the go-connections package have a NewUnixSocketWithOpts, which could possibly avoid that; https://github.com/docker/go-connections/blob/09f47925228a97335b2462178c79669712efe44e/sockets/unix_socket.go#L81

With that one, we could pass a custom functional argument that does the chown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the file UID doesn't matter much. What I mean is, whether it's root or docker, it's fine either way.

What matters is GID.

@kolyshkin
Copy link
Contributor Author

@kolyshkin this needs a rebase now, because I opened the second commit as a separate PR to make this diff smaller; if it helps, I did a rebase of your branch and pushed it here; https://github.com/moby/moby/compare/master...thaJeztah:carry_39605_chgrp_docker_sock?expand=1

this LGTM; can you please carry this?

@thaJeztah
Copy link
Member

closing this one per #42879 (comment) (should probably be fixed by #38126)

@thaJeztah thaJeztah closed this Sep 27, 2021
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.

8 participants
0