Sfoglia il codice sorgente

archive: add human-readable hint to Lchown error

Before:
```
$ docker pull gcr.io/kubeflow-images-public/tensorflow-1.14.0-notebook-cpu:v0.7.0
failed to register layer: ApplyLayer exit status 1 stdout:  stderr: lchown /usr/local/bin/docker-credential-gcr: invalid argument
```

After:
```
$ docker pull gcr.io/kubeflow-images-public/tensorflow-1.14.0-notebook-cpu:v0.7.0
failed to register layer: ApplyLayer exit status 1 stdout:  stderr: failed to Lchown "/usr/local/bin/docker-credential-gcr" for UID 205001, GID 5000:
lchown /usr/local/bin/docker-credential-gcr: invalid argument (try increasing the number of subordinate IDs in /etc/subuid and /etc/subgid)
```

For issue 43576

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Akihiro Suda 3 anni fa
parent
commit
0afc71fc90
1 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 7 1
      pkg/archive/archive.go

+ 7 - 1
pkg/archive/archive.go

@@ -18,12 +18,14 @@ import (
 	"syscall"
 	"syscall"
 	"time"
 	"time"
 
 
+	"github.com/containerd/containerd/pkg/userns"
 	"github.com/docker/docker/pkg/fileutils"
 	"github.com/docker/docker/pkg/fileutils"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/ioutils"
 	"github.com/docker/docker/pkg/pools"
 	"github.com/docker/docker/pkg/pools"
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/pkg/system"
 	"github.com/klauspost/compress/zstd"
 	"github.com/klauspost/compress/zstd"
+	"github.com/pkg/errors"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 	exec "golang.org/x/sys/execabs"
 	exec "golang.org/x/sys/execabs"
 )
 )
@@ -766,7 +768,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
 			chownOpts = &idtools.Identity{UID: hdr.Uid, GID: hdr.Gid}
 			chownOpts = &idtools.Identity{UID: hdr.Uid, GID: hdr.Gid}
 		}
 		}
 		if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil {
 		if err := os.Lchown(path, chownOpts.UID, chownOpts.GID); err != nil {
-			return err
+			msg := "failed to Lchown %q for UID %d, GID %d"
+			if errors.Is(err, syscall.EINVAL) && userns.RunningInUserNS() {
+				msg += " (try increasing the number of subordinate IDs in /etc/subuid and /etc/subgid)"
+			}
+			return errors.Wrapf(err, msg, path, hdr.Uid, hdr.Gid)
 		}
 		}
 	}
 	}