mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #21162 from estesp/copyastar-dir-create
Fix CopyWithTar creation of new destination dir as remapped root
This commit is contained in:
commit
6f2d8b411e
2 changed files with 40 additions and 6 deletions
|
@ -824,13 +824,15 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestBuildCopyToNewParentDirectory(c *check.C) {
|
// This test is mainly for user namespaces to verify that new directories
|
||||||
|
// are created as the remapped root uid/gid pair
|
||||||
|
func (s *DockerSuite) TestBuildAddToNewDestination(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux) // Linux specific test
|
testRequires(c, DaemonIsLinux) // Linux specific test
|
||||||
name := "testcopytonewdir"
|
name := "testaddtonewdest"
|
||||||
ctx, err := fakeContext(`FROM busybox
|
ctx, err := fakeContext(`FROM busybox
|
||||||
COPY test_dir /new_dir
|
ADD . /new_dir
|
||||||
RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]
|
RUN ls -l /
|
||||||
RUN ls -l /new_dir`,
|
RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"test_dir/test_file": "test file",
|
"test_dir/test_file": "test file",
|
||||||
})
|
})
|
||||||
|
@ -844,6 +846,30 @@ RUN ls -l /new_dir`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This test is mainly for user namespaces to verify that new directories
|
||||||
|
// are created as the remapped root uid/gid pair
|
||||||
|
func (s *DockerSuite) TestBuildCopyToNewParentDirectory(c *check.C) {
|
||||||
|
testRequires(c, DaemonIsLinux) // Linux specific test
|
||||||
|
name := "testcopytonewdir"
|
||||||
|
ctx, err := fakeContext(`FROM busybox
|
||||||
|
COPY test_dir /new_dir
|
||||||
|
RUN ls -l /new_dir
|
||||||
|
RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]`,
|
||||||
|
map[string]string{
|
||||||
|
"test_dir/test_file": "test file",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
defer ctx.Close()
|
||||||
|
|
||||||
|
if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test is mainly for user namespaces to verify that new directories
|
||||||
|
// are created as the remapped root uid/gid pair
|
||||||
func (s *DockerSuite) TestBuildWorkdirIsContainerRoot(c *check.C) {
|
func (s *DockerSuite) TestBuildWorkdirIsContainerRoot(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux) // Linux specific test
|
testRequires(c, DaemonIsLinux) // Linux specific test
|
||||||
name := "testworkdirownership"
|
name := "testworkdirownership"
|
||||||
|
|
|
@ -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…
Add table
Reference in a new issue