Fix parsing of user/group during copy operation#34143
Conversation
There was a problem hiding this comment.
ah, yes, perhaps I should change that; I started writing for this PR, but found
Lines 941 to 951 in c8a2596
I'm not sure what approach should be taken though if the user needs to come from within the container (where getent may not be available, such as in a busybox container) - that's why I kept it as "WIP"
bd967ec to
1996def
Compare
|
@AkihiroSuda, does this look good now? |
|
getent - > typically getent? (Sorry for going back and forth) |
|
Is this still WIP? |
|
let me remove "WIP", code itself should be generally ok (not sure how to test this, without the test becoming dependent on the host) I think I made this
Oh, can you be more specific; happy to update but wasn't sure what you meant / where you wanted to have that updated 😄 |
There was a problem hiding this comment.
oh, need to remove this one as that's part of #34099, so don't merge as-is
1996def to
e4a5d45
Compare
|
any update on this? |
e4a5d45 to
cbc2bbc
Compare
|
@thaJeztah this one needs to be rebased |
cbc2bbc to
1aa8d22
Compare
|
Rebased @tonistiigi @AkihiroSuda PTAL |
1aa8d22 to
dabb29a
Compare
Codecov Report
@@ Coverage Diff @@
## master #34143 +/- ##
=========================================
Coverage ? 36.52%
=========================================
Files ? 608
Lines ? 45060
Branches ? 0
=========================================
Hits ? 16459
Misses ? 26321
Partials ? 2280 |
2c69e04 to
bab4e16
Compare
bab4e16 to
5bd409e
Compare
|
|
||
| usr, err := lookupUser(ctr, userNameOrID) | ||
| if err != nil { | ||
| return 0, 0, errors.Wrapf(err, "failed to look up user %q in container: %w", userNameOrID) |
There was a problem hiding this comment.
Ah, forgot to remove the %w when I swapped to errors.Wrapf;
daemon/archive_tarcopyoptions_unix.go:64:16: github.com/docker/docker/vendor/github.com/pkg/errors.Wrapf format %w reads arg #2, but call has 1 arg
daemon/archive_tarcopyoptions_unix.go:73:16: github.com/docker/docker/vendor/github.com/pkg/errors.Wrapf format %w reads arg #2, but call has 1 arg
5bd409e to
29b709c
Compare
| if uid, err := strconv.ParseUint(nameOrID, 10, 32); err == nil && uid <= math.MaxInt32 { | ||
| // uid provided | ||
| return int(uid), "" | ||
| } |
There was a problem hiding this comment.
Wondering if this is too strict, and if we should just use something like
moby/vendor/github.com/moby/sys/user/lookup_unix.go
Lines 137 to 139 in 079b6e6
| if userName == "" && hasGroup && groupName == "" { | ||
| // UID/GID passed; nothing to look up. | ||
| return userID, groupID, nil | ||
| } | ||
|
|
||
| usr, err := lookupUser(ctr, userNameOrID) | ||
| if err != nil { | ||
| return 0, 0, errors.Wrapf(err, "failed to look up user %q in container", userNameOrID) | ||
| } |
There was a problem hiding this comment.
That said.. with the logic in this PR, we'd be able to skip lookup if a numeric UID/GID is passed; that means we're also able to work with a container that doesn't have /etc/passwd / etc/group.
29b709c to
63675e9
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
63675e9 to
046c40e
Compare
1eff567 to
ee025b2
Compare
If a container was started with - a numeric uid - both a user and group (username:groupname) - uid and gid (uid:gid) The copy action failed, because the "username:groupname" was looked up using getent. This patch; - splits `user` and `group` before looking up - if numeric `uid` or `gid` is used and lookup fails, the `uid` / `gid` is used as-is The code also looked up the user and group on the host instead of in the container when using getent; this patch fixes the lookup to only use the container's /etc/passwd and /etc/group instead. Signed-off-by: Sebastiaan van Stijn <[email protected]>
ee025b2 to
f658ea3
Compare
|
Let me bring this one in; thx! |
relates to
docker cp, etc) uid/gid handling #28923If a container was started with
The copy action failed, because the "username:groupname"
was looked up using getent.
This patch;
userandgroupbefore looking upuidorgidis used and lookup fails,the
uid/gidis used as-is