-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement readUser on Windows #3518
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8c7bd5
Implement readUser on Windows
gabriel-samfira 8a369a9
Remove the need for an exported Executor field
gabriel-samfira fe3ca93
Move readUser code outside of the file package
gabriel-samfira 2f3bda8
Use snapshot.Mountable as an argument type to readUser
gabriel-samfira 2585dd9
Fix linting issue
gabriel-samfira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package file | ||
|
||
import ( | ||
"github.com/docker/docker/pkg/idtools" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func mapUserToChowner(user *copy.User, idmap *idtools.IdentityMapping) (copy.Chowner, error) { | ||
if user == nil { | ||
return func(old *copy.User) (*copy.User, error) { | ||
if old == nil { | ||
if idmap == nil { | ||
return nil, nil | ||
} | ||
old = ©.User{} // root | ||
// non-nil old is already mapped | ||
if idmap != nil { | ||
identity, err := idmap.ToHost(idtools.Identity{ | ||
UID: old.UID, | ||
GID: old.GID, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ©.User{UID: identity.UID, GID: identity.GID}, nil | ||
} | ||
} | ||
return old, nil | ||
}, nil | ||
} | ||
u := *user | ||
if idmap != nil { | ||
identity, err := idmap.ToHost(idtools.Identity{ | ||
UID: user.UID, | ||
GID: user.GID, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
u.UID = identity.UID | ||
u.GID = identity.GID | ||
} | ||
return func(*copy.User) (*copy.User, error) { | ||
return &u, nil | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package file | ||
|
||
import ( | ||
"github.com/docker/docker/pkg/idtools" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func mapUserToChowner(user *copy.User, idmap *idtools.IdentityMapping) (copy.Chowner, error) { | ||
if user == nil || user.SID == "" { | ||
return func(old *copy.User) (*copy.User, error) { | ||
if old == nil || old.SID == "" { | ||
old = ©.User{ | ||
SID: idtools.ContainerAdministratorSidString, | ||
} | ||
} | ||
return old, nil | ||
}, nil | ||
} | ||
return func(*copy.User) (*copy.User, error) { | ||
return user, nil | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//go:build !linux && !windows | ||
// +build !linux,!windows | ||
|
||
package ops | ||
|
||
import ( | ||
"github.com/moby/buildkit/snapshot" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/moby/buildkit/worker" | ||
"github.com/pkg/errors" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func getReadUserFn(worker worker.Worker) func(chopt *pb.ChownOpt, mu, mg snapshot.Mountable) (*copy.User, error) { | ||
return readUser | ||
} | ||
|
||
func readUser(chopt *pb.ChownOpt, mu, mg snapshot.Mountable) (*copy.User, error) { | ||
if chopt == nil { | ||
return nil, nil | ||
} | ||
return nil, errors.New("only implemented in linux and windows") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ops | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/docker/docker/pkg/idtools" | ||
"github.com/moby/buildkit/snapshot" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/moby/buildkit/util/windows" | ||
"github.com/moby/buildkit/worker" | ||
"github.com/pkg/errors" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func getReadUserFn(worker worker.Worker) func(chopt *pb.ChownOpt, mu, mg snapshot.Mountable) (*copy.User, error) { | ||
return func(chopt *pb.ChownOpt, mu, mg snapshot.Mountable) (*copy.User, error) { | ||
return readUser(chopt, mu, mg, worker) | ||
} | ||
} | ||
|
||
func readUser(chopt *pb.ChownOpt, mu, mg snapshot.Mountable, worker worker.Worker) (*copy.User, error) { | ||
if chopt == nil { | ||
return nil, nil | ||
} | ||
|
||
if chopt.User != nil { | ||
switch u := chopt.User.User.(type) { | ||
case *pb.UserOpt_ByName: | ||
if mu == nil { | ||
return nil, errors.Errorf("invalid missing user mount") | ||
} | ||
|
||
rootMounts, release, err := mu.Mount() | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer release() | ||
ident, err := windows.ResolveUsernameToSID(context.Background(), worker.Executor(), rootMounts, u.ByName.Name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ©.User{SID: ident.SID}, nil | ||
default: | ||
return ©.User{SID: idtools.ContainerAdministratorSidString}, nil | ||
} | ||
} | ||
return ©.User{SID: idtools.ContainerAdministratorSidString}, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is still something iffy about these type casts but looks like the previous code had a similar problem, so no update is needed with this PR.
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.
I agree. There are a few architectural boundaries being broken here which could do with some refactor, but it will require touching a lot of code. This pattern is present in a number of places and should probably be tackled at some point as part of a broader cleanup.
Thanks for the review and the merge!