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 <estesp@linux.vnet.ibm.com> (github: estesp)
This commit is contained in:
parent
dcb61a1e38
commit
ac445a24e8
1 changed files with 9 additions and 1 deletions
|
@ -881,9 +881,17 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
|
||||||
if !srcSt.IsDir() {
|
if !srcSt.IsDir() {
|
||||||
return archiver.CopyFileWithTar(src, dst)
|
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
|
// Create dst, copy src's content into it
|
||||||
logrus.Debugf("Creating dest directory: %s", dst)
|
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
|
return err
|
||||||
}
|
}
|
||||||
logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)
|
logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)
|
||||||
|
|
Loading…
Reference in a new issue