mirror of
https://github.com/moby/buildkit.git
synced 2026-08-04 14:50:21 +00:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
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, _ 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
|
|
}
|