From ac445a24e8625b6cd6842ac96471e3ce0ae7acb9 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Sat, 12 Mar 2016 23:05:45 -0500 Subject: [PATCH] Fix CopyWithTar creation of new destination dir as remapped root If the destination does not exist, it needs to be created with ownership mapping to the remapped uid/gid ranges if user namespaces are enabled. This fixes ADD operations, similar to the prior fixes for COPY and WORKDIR. Docker-DCO-1.1-Signed-off-by: Phil Estes (github: estesp) --- archive/archive.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/archive/archive.go b/archive/archive.go index 358ab09..47c5638 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -881,9 +881,17 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error { if !srcSt.IsDir() { return archiver.CopyFileWithTar(src, dst) } + + // if this archiver is set up with ID mapping we need to create + // the new destination directory with the remapped root UID/GID pair + // as owner + rootUID, rootGID, err := idtools.GetRootUIDGID(archiver.UIDMaps, archiver.GIDMaps) + if err != nil { + return err + } // Create dst, copy src's content into it logrus.Debugf("Creating dest directory: %s", dst) - if err := system.MkdirAll(dst, 0755); err != nil { + if err := idtools.MkdirAllNewAs(dst, 0755, rootUID, rootGID); err != nil { return err } logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)