From 577f448993133cbaaa123471cdc49ad9458d8827 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Mon, 21 May 2018 11:20:32 -0700 Subject: [PATCH] Make sure necessary files aren't deleted for multistage builds --- pkg/constants/constants.go | 6 ++++-- pkg/util/fs_util.go | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 1c036b53a..e7ff5cb52 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -48,5 +48,7 @@ const ( NoBaseImage = "scratch" ) -// KanikoBuildFiles is the list of files required to build kaniko -var KanikoBuildFiles = []string{"/kaniko/executor", "/kaniko/ssl/certs/ca-certificates.crt"} +// KanikoFiles is the list of files that shouldn't be deleted from kaniko +var KanikoFiles = []string{"/kaniko/executor", "/kaniko/ssl/certs/ca-certificates.crt", + "/root/.docker/config.json", "/usr/local/bin/docker-credential-gcr", + "/usr/local/bin/docker-credential-ecr-login"} diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index 613a1043a..b24ca0659 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -128,6 +128,12 @@ func DeleteFilesystem() error { // ChildDirInWhitelist returns true if there is a child file or directory of the path in the whitelist func ChildDirInWhitelist(path, directory string) bool { + for _, d := range constants.KanikoFiles { + dirPath := filepath.Join(directory, d) + if HasFilepathPrefix(dirPath, path) { + return true + } + } for _, d := range whitelist { dirPath := filepath.Join(directory, d) if HasFilepathPrefix(dirPath, path) { @@ -217,7 +223,7 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { } func PathInWhitelist(path, directory string) bool { - for _, c := range constants.KanikoBuildFiles { + for _, c := range constants.KanikoFiles { if path == c { return false }