-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Use idtools.LookupGroup instead of parsing /etc/group file for docker.sock ownership #38126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
….sock ownership Signed-off-by: James Watkins-Harvey <jwatkins@progi-media.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,25 +6,15 @@ import ( | |||||
"fmt" | ||||||
"strconv" | ||||||
|
||||||
"github.com/opencontainers/runc/libcontainer/user" | ||||||
"github.com/pkg/errors" | ||||||
"github.com/docker/docker/pkg/idtools" | ||||||
) | ||||||
|
||||||
const defaultSocketGroup = "docker" | ||||||
|
||||||
func lookupGID(name string) (int, error) { | ||||||
groupFile, err := user.GetGroupPath() | ||||||
if err != nil { | ||||||
return -1, errors.Wrap(err, "error looking up groups") | ||||||
} | ||||||
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 | ||||||
group, err := idtools.LookupGroup(name) | ||||||
if err == nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should log the error as a warning if we both fail to find a group, and converting the (It's a bit unfortunate that "group not found", and "an error occurred looking up the group" both return an error here; moby/pkg/idtools/idtools_unix.go Line 183 in b3e9f7b
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding the specific case of moby/daemon/listeners/listeners_linux.go Line 40 in b3e9f7b
This is the only call site to As for the more general matter of error handling in Now, come to that, I have noticed that there are quite a few places in Docker's source code where By the way, I tried to retain the original behaviour as much as possible, in the hope that it would make the fix more acceptable for inclusion, essentially because it is my first contribution here. Still, I can certainly put a little more work in it if you are willing to give me some hints on what is to be done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, after some more checks, it turns out that there are almost no case left of ad-hoc parsing. I only found |
||||||
return group.Gid, nil | ||||||
} | ||||||
gid, err := strconv.Atoi(name) | ||||||
if err == nil { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah.. this broke master in combination with #38316 fix upcoming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix #38360 👍