-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds the ability to resolve usernames to SIDs in the FileOpSolver. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
- Loading branch information
1 parent
c3eddbf
commit 508b7fb
Showing
8 changed files
with
139 additions
and
63 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build !linux && !windows | ||
// +build !linux,!windows | ||
|
||
package file | ||
|
||
import ( | ||
"github.com/moby/buildkit/executor" | ||
"github.com/moby/buildkit/solver/llbsolver/ops/fileoptypes" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/pkg/errors" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func readUser(chopt *pb.ChownOpt, mu, mg fileoptypes.Mount, exec executor.Executor) (*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,41 @@ | ||
package file | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/docker/docker/pkg/idtools" | ||
"github.com/moby/buildkit/executor" | ||
"github.com/moby/buildkit/solver/llbsolver/ops/fileoptypes" | ||
"github.com/moby/buildkit/solver/pb" | ||
"github.com/moby/buildkit/util/windows" | ||
"github.com/pkg/errors" | ||
copy "github.com/tonistiigi/fsutil/copy" | ||
) | ||
|
||
func readUser(chopt *pb.ChownOpt, mu, mg fileoptypes.Mount, exec executor.Executor) (*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") | ||
} | ||
mmu, ok := mu.(*Mount) | ||
if !ok { | ||
return nil, errors.Errorf("invalid mount type %T", mu) | ||
} | ||
|
||
ident, err := windows.ResolveUsernameToSID(context.Background(), exec, mmu.m, 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 | ||
} |
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