1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #38126 from mjameswh/fix-1715

Use idtools.LookupGroup instead of parsing /etc/group file for docker.sock ownership
This commit is contained in:
Vincent Demeester 2018-12-12 17:29:28 +01:00 committed by GitHub
commit 56cc56b0fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,25 +6,15 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"github.com/opencontainers/runc/libcontainer/user" "github.com/docker/docker/pkg/idtools"
"github.com/pkg/errors"
) )
const defaultSocketGroup = "docker" const defaultSocketGroup = "docker"
func lookupGID(name string) (int, error) { func lookupGID(name string) (int, error) {
groupFile, err := user.GetGroupPath() group, err := idtools.LookupGroup(name)
if err != nil { if err == nil {
return -1, errors.Wrap(err, "error looking up groups") return group.Gid, nil
}
groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool {
return g.Name == name || strconv.Itoa(g.Gid) == name
})
if err != nil {
return -1, errors.Wrapf(err, "error parsing groups for %s", name)
}
if len(groups) > 0 {
return groups[0].Gid, nil
} }
gid, err := strconv.Atoi(name) gid, err := strconv.Atoi(name)
if err == nil { if err == nil {