diff --git a/vendor.conf b/vendor.conf index 611fb8348f..7748180297 100644 --- a/vendor.conf +++ b/vendor.conf @@ -27,7 +27,7 @@ github.com/imdario/mergo 7c29201646fa3de8506f70121347 golang.org/x/sync e225da77a7e68af35c70ccbf71af2b83e6acac3c # buildkit -github.com/moby/buildkit 1f89ec125f84c097bdf3a063be622c4238dba5f8 +github.com/moby/buildkit c24275065aca6605bd83c57c6735510f4ebeb6d9 github.com/tonistiigi/fsutil 3bbb99cdbd76619ab717299830c60f6f2a533a6b github.com/grpc-ecosystem/grpc-opentracing 8e809c8a86450a29b90dcc9efbf062d0fe6d9746 github.com/opentracing/opentracing-go 1361b9cd60be79c4c3a7fa9841b3c132e40066a7 diff --git a/vendor/github.com/moby/buildkit/executor/oci/hosts.go b/vendor/github.com/moby/buildkit/executor/oci/hosts.go index c350a6de27..3b3f86db79 100644 --- a/vendor/github.com/moby/buildkit/executor/oci/hosts.go +++ b/vendor/github.com/moby/buildkit/executor/oci/hosts.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" + "github.com/docker/docker/pkg/idtools" "github.com/moby/buildkit/executor" "github.com/moby/buildkit/identity" ) @@ -17,10 +18,10 @@ const hostsContent = ` ::1 localhost ip6-localhost ip6-loopback ` -func GetHostsFile(ctx context.Context, stateDir string, extraHosts []executor.HostIP) (string, func(), error) { +func GetHostsFile(ctx context.Context, stateDir string, extraHosts []executor.HostIP, idmap *idtools.IdentityMapping) (string, func(), error) { if len(extraHosts) == 0 { _, err := g.Do(ctx, stateDir, func(ctx context.Context) (interface{}, error) { - _, _, err := makeHostsFile(stateDir, nil) + _, _, err := makeHostsFile(stateDir, nil, idmap) return nil, err }) if err != nil { @@ -28,10 +29,10 @@ func GetHostsFile(ctx context.Context, stateDir string, extraHosts []executor.Ho } return filepath.Join(stateDir, "hosts"), func() {}, nil } - return makeHostsFile(stateDir, extraHosts) + return makeHostsFile(stateDir, extraHosts, idmap) } -func makeHostsFile(stateDir string, extraHosts []executor.HostIP) (string, func(), error) { +func makeHostsFile(stateDir string, extraHosts []executor.HostIP, idmap *idtools.IdentityMapping) (string, func(), error) { p := filepath.Join(stateDir, "hosts") if len(extraHosts) != 0 { p += "." + identity.NewID() @@ -56,11 +57,19 @@ func makeHostsFile(stateDir string, extraHosts []executor.HostIP) (string, func( } } - if err := ioutil.WriteFile(p+".tmp", b.Bytes(), 0644); err != nil { + tmpPath := p + ".tmp" + if err := ioutil.WriteFile(tmpPath, b.Bytes(), 0644); err != nil { return "", nil, err } - if err := os.Rename(p+".tmp", p); err != nil { + if idmap != nil { + root := idmap.RootPair() + if err := os.Chown(tmpPath, root.UID, root.GID); err != nil { + return "", nil, err + } + } + + if err := os.Rename(tmpPath, p); err != nil { return "", nil, err } return p, func() { diff --git a/vendor/github.com/moby/buildkit/executor/oci/resolvconf.go b/vendor/github.com/moby/buildkit/executor/oci/resolvconf.go index a65f2ddecf..422f1ab962 100644 --- a/vendor/github.com/moby/buildkit/executor/oci/resolvconf.go +++ b/vendor/github.com/moby/buildkit/executor/oci/resolvconf.go @@ -6,6 +6,7 @@ import ( "os" "path/filepath" + "github.com/docker/docker/pkg/idtools" "github.com/docker/libnetwork/resolvconf" "github.com/moby/buildkit/util/flightcontrol" ) @@ -14,7 +15,7 @@ var g flightcontrol.Group var notFirstRun bool var lastNotEmpty bool -func GetResolvConf(ctx context.Context, stateDir string) (string, error) { +func GetResolvConf(ctx context.Context, stateDir string, idmap *idtools.IdentityMapping) (string, error) { p := filepath.Join(stateDir, "resolv.conf") _, err := g.Do(ctx, stateDir, func(ctx context.Context) (interface{}, error) { generate := !notFirstRun @@ -65,11 +66,19 @@ func GetResolvConf(ctx context.Context, stateDir string) (string, error) { return "", err } - if err := ioutil.WriteFile(p+".tmp", f.Content, 0644); err != nil { + tmpPath := p + ".tmp" + if err := ioutil.WriteFile(tmpPath, f.Content, 0644); err != nil { return "", err } - if err := os.Rename(p+".tmp", p); err != nil { + if idmap != nil { + root := idmap.RootPair() + if err := os.Chown(tmpPath, root.UID, root.GID); err != nil { + return "", err + } + } + + if err := os.Rename(tmpPath, p); err != nil { return "", err } return "", nil diff --git a/vendor/github.com/moby/buildkit/executor/runcexecutor/executor.go b/vendor/github.com/moby/buildkit/executor/runcexecutor/executor.go index ceca9d8bec..680bc7b346 100644 --- a/vendor/github.com/moby/buildkit/executor/runcexecutor/executor.go +++ b/vendor/github.com/moby/buildkit/executor/runcexecutor/executor.go @@ -79,7 +79,7 @@ func New(opt Opt, networkProviders map[pb.NetMode]network.Provider) (executor.Ex root := opt.Root - if err := os.MkdirAll(root, 0700); err != nil { + if err := os.MkdirAll(root, 0711); err != nil { return nil, errors.Wrapf(err, "failed to create %s", root) } @@ -134,12 +134,12 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache. logrus.Info("enabling HostNetworking") } - resolvConf, err := oci.GetResolvConf(ctx, w.root) + resolvConf, err := oci.GetResolvConf(ctx, w.root, w.idmap) if err != nil { return err } - hostsFile, clean, err := oci.GetHostsFile(ctx, w.root, meta.ExtraHosts) + hostsFile, clean, err := oci.GetHostsFile(ctx, w.root, meta.ExtraHosts, w.idmap) if err != nil { return err } @@ -161,7 +161,7 @@ func (w *runcExecutor) Exec(ctx context.Context, meta executor.Meta, root cache. id := identity.NewID() bundle := filepath.Join(w.root, id) - if err := os.Mkdir(bundle, 0700); err != nil { + if err := os.Mkdir(bundle, 0711); err != nil { return err } defer os.RemoveAll(bundle) diff --git a/vendor/github.com/moby/buildkit/solver/llbsolver/file/backend.go b/vendor/github.com/moby/buildkit/solver/llbsolver/file/backend.go index 45d66d713e..07044691f2 100644 --- a/vendor/github.com/moby/buildkit/solver/llbsolver/file/backend.go +++ b/vendor/github.com/moby/buildkit/solver/llbsolver/file/backend.go @@ -27,13 +27,9 @@ func timestampToTime(ts int64) *time.Time { } func mapUser(user *copy.ChownOpt, idmap *idtools.IdentityMapping) (*copy.ChownOpt, error) { - if idmap == nil { + if idmap == nil || user == nil { return user, nil } - if user == nil { - identity := idmap.RootPair() - return ©.ChownOpt{Uid: identity.UID, Gid: identity.GID}, nil - } identity, err := idmap.ToHost(idtools.Identity{ UID: user.Uid, GID: user.Gid, @@ -138,7 +134,6 @@ func docopy(ctx context.Context, src, dest string, action pb.FileActionCopy, u * return nil } - // TODO(tonistiigi): this is wrong. fsutil.Copy can't handle non-forced user u, err := mapUser(u, idmap) if err != nil { return err