mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 13:41:36 +00:00
Fix .dockerignore when ignoring unreadable dirs
The initial `ValidateContextDirectory` implementation fails loudly when a file lacks read permissions in the current context. However that situation is valid if the file is included in the `.dockerignore` patterns. Docker-DCO-1.1-Signed-off-by: Bruno Renié <brutasse@gmail.com> (github: brutasse)
This commit is contained in:
committed by
Michael Crosby
parent
54b287bbc8
commit
27cca4c70c
@@ -474,10 +474,33 @@ func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
|
||||
|
||||
deleteImages("testlinksok")
|
||||
|
||||
}
|
||||
{
|
||||
// This is used to ensure we don't try to add inaccessible files when they are ignored by a .dockerignore pattern
|
||||
pathToInaccessibleDirectoryBuildDirectory := filepath.Join(buildDirectory, "ignoredinaccessible")
|
||||
pathToDirectoryWithoutReadAccess := filepath.Join(pathToInaccessibleDirectoryBuildDirectory, "directoryWeCantStat")
|
||||
pathToFileInDirectoryWithoutReadAccess := filepath.Join(pathToDirectoryWithoutReadAccess, "bar")
|
||||
err := os.Chown(pathToDirectoryWithoutReadAccess, 0, 0)
|
||||
errorOut(err, t, fmt.Sprintf("failed to chown directory to root: %s", err))
|
||||
err = os.Chmod(pathToDirectoryWithoutReadAccess, 0444)
|
||||
errorOut(err, t, fmt.Sprintf("failed to chmod directory to 755: %s", err))
|
||||
err = os.Chmod(pathToFileInDirectoryWithoutReadAccess, 0700)
|
||||
errorOut(err, t, fmt.Sprintf("failed to chmod file to 444: %s", err))
|
||||
|
||||
buildCommandStatement := fmt.Sprintf("%s build -t ignoredinaccessible .", dockerBinary)
|
||||
buildCmd := exec.Command("su", "unprivilegeduser", "-c", buildCommandStatement)
|
||||
buildCmd.Dir = pathToInaccessibleDirectoryBuildDirectory
|
||||
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
t.Fatalf("build should have worked: %s %s", err, out)
|
||||
}
|
||||
deleteImages("ignoredinaccessible")
|
||||
|
||||
}
|
||||
deleteImages("inaccessiblefiles")
|
||||
logDone("build - ADD from context with inaccessible files must fail")
|
||||
logDone("build - ADD from context with accessible links must work")
|
||||
logDone("build - ADD from context with ignored inaccessible files must work")
|
||||
}
|
||||
|
||||
func TestBuildForceRm(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user