diff --git a/archive/tar.go b/archive/tar.go index db27c0e90dc6..eca6316b02d0 100644 --- a/archive/tar.go +++ b/archive/tar.go @@ -19,6 +19,7 @@ package archive import ( "archive/tar" "context" + "fmt" "io" "os" "path/filepath" @@ -29,6 +30,7 @@ import ( "time" "github.com/containerd/containerd/log" + "github.com/containerd/containerd/pkg/userns" "github.com/containerd/continuity/fs" "github.com/pkg/errors" ) @@ -376,6 +378,10 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header // Lchown is not supported on Windows. if runtime.GOOS != "windows" { if err := os.Lchown(path, hdr.Uid, hdr.Gid); err != nil { + err = fmt.Errorf("failed to Lchown %q for UID %d, GID %d: %w", path, hdr.Uid, hdr.Gid, err) + if errors.Is(err, syscall.EINVAL) && userns.RunningInUserNS() { + err = fmt.Errorf("%w (Hint: try increasing the number of subordinate IDs in /etc/subuid and /etc/subgid)", err) + } return err } }