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:
commit
56cc56b0fa
1 changed files with 4 additions and 14 deletions
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue