Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions integration/dockerfiles/Dockerfile_test_root
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM debian

RUN chmod 700 /
RUN chmod 755 /
RUN chown 1000:1000 /
RUN chown root:root /
2 changes: 2 additions & 0 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ var diffArgsMap = map[string][]string{
"TestRun/test_Dockerfile_test_multistage": {"--extra-ignore-files=new"},
// when we untar we overwrite the parent directory, buildkit doesnt
"TestRun/test_Dockerfile_test_add": {"--extra-ignore-file-permissions"},
// Verify we don't store root directory
"TestRun/test_Dockerfile_test_root": {"--extra-ignore-layer-length-mismatch=false"},
// FROM scratch we start with root, buildkit doesnt
"TestRun/test_Dockerfile_test_workdir_with_user": {"--extra-ignore-file-permissions"},
// We don't handle user nobody=-1 nogroup=-1 correctly
Expand Down
4 changes: 4 additions & 0 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func writeToTar(t util.Tar, files, whiteouts []string) error {

// Now create the tar.
addedPaths := make(map[string]bool)
addedPaths[config.RootDir] = true

for _, path := range whiteouts {
skipWhiteout, err := parentPathIncludesNonDirectory(path)
Expand Down Expand Up @@ -294,6 +295,9 @@ func parentPathIncludesNonDirectory(path string) (bool, error) {

func addParentDirectories(t util.Tar, addedPaths map[string]bool, path string) error {
for _, parentPath := range util.ParentDirectories(path) {
if parentPath == config.RootDir {
continue
}
if _, pathAdded := addedPaths[parentPath]; pathAdded {
continue
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func TestSnapshotFSFileChange(t *testing.T) {
batPath: "baz",
}
for _, path := range util.ParentDirectoriesWithoutLeadingSlash(batPath) {
if path == "/" {
snapshotFiles["/"] = ""
if path == config.RootDir {
continue
}
snapshotFiles[path+"/"] = ""
Expand Down Expand Up @@ -155,8 +154,7 @@ func TestSnapshotFSChangePermissions(t *testing.T) {
batPathWithoutLeadingSlash: "baz2",
}
for _, path := range util.ParentDirectoriesWithoutLeadingSlash(batPathWithoutLeadingSlash) {
if path == "/" {
snapshotFiles["/"] = ""
if path == config.RootDir {
continue
}
snapshotFiles[path+"/"] = ""
Expand Down Expand Up @@ -225,6 +223,9 @@ func TestSnapshotFSReplaceDirWithLink(t *testing.T) {
filepath.Join(testDirWithoutLeadingSlash, "foo"),
}
for _, path := range util.ParentDirectoriesWithoutLeadingSlash(filepath.Join(testDir, "foo")) {
if path == config.RootDir {
continue
}
expectedFiles = append(expectedFiles, strings.TrimRight(path, "/")+"/")
}

Expand Down Expand Up @@ -260,6 +261,9 @@ func TestSnapshotFiles(t *testing.T) {
filepath.Join(testDirWithoutLeadingSlash, "foo"),
}
for _, path := range util.ParentDirectoriesWithoutLeadingSlash(filepath.Join(testDir, "foo")) {
if path == config.RootDir {
continue
}
expectedFiles = append(expectedFiles, strings.TrimRight(path, "/")+"/")
}

Expand Down Expand Up @@ -456,7 +460,6 @@ func TestSnapshotIncludesParentDirBeforeWhiteoutFile(t *testing.T) {
filepath.Join(testDirWithoutLeadingSlash, "kaniko/.wh.file"),
filepath.Join(testDirWithoutLeadingSlash, "kaniko/new-file"),
filepath.Join(testDirWithoutLeadingSlash, ".wh.bar"),
"/",
}
for parentDir := filepath.Dir(expectedFiles[0]); parentDir != "."; parentDir = filepath.Dir(parentDir) {
expectedFiles = append(expectedFiles, parentDir+"/")
Expand Down
12 changes: 6 additions & 6 deletions pkg/util/tar_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func (t *Tar) AddFileToTar(p string) error {
}

if p == config.RootDir {
// allow entry for / to preserve permission changes etc. (currently ignored anyway by Docker runtime)
hdr.Name = "/"
} else {
// Docker uses no leading / in the tarball
hdr.Name = strings.TrimPrefix(p, config.RootDir)
hdr.Name = strings.TrimLeft(hdr.Name, "/")
logrus.Panic("Unreachable Code: We should no longer snapshot '/' as it will be ignored by docker anyways")
}

// Docker uses no leading / in the tarball
hdr.Name = strings.TrimPrefix(p, config.RootDir)
hdr.Name = strings.TrimLeft(hdr.Name, "/")

if hdr.Typeflag == tar.TypeDir && !strings.HasSuffix(hdr.Name, "/") {
hdr.Name = hdr.Name + "/"
}
Expand Down
Loading