mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Forbid certain paths within docker build ADD
This commit is contained in:
parent
4af24e11a4
commit
3104fc8d33
2 changed files with 52 additions and 0 deletions
|
@ -278,6 +278,9 @@ func (b *buildFile) addContext(container *Container, orig, dest string) error {
|
||||||
if strings.HasSuffix(dest, "/") {
|
if strings.HasSuffix(dest, "/") {
|
||||||
destPath = destPath + "/"
|
destPath = destPath + "/"
|
||||||
}
|
}
|
||||||
|
if !strings.HasPrefix(origPath, b.context) {
|
||||||
|
return fmt.Errorf("Forbidden path: %s", origPath)
|
||||||
|
}
|
||||||
fi, err := os.Stat(origPath)
|
fi, err := os.Stat(origPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -423,3 +423,52 @@ func TestBuildImageWithoutCache(t *testing.T) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestForbiddenContextPath(t *testing.T) {
|
||||||
|
runtime, err := newTestRuntime()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nuke(runtime)
|
||||||
|
|
||||||
|
srv := &Server{
|
||||||
|
runtime: runtime,
|
||||||
|
pullingPool: make(map[string]struct{}),
|
||||||
|
pushingPool: make(map[string]struct{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
context := testContextTemplate{`
|
||||||
|
from {IMAGE}
|
||||||
|
maintainer dockerio
|
||||||
|
add ../../ test/
|
||||||
|
`,
|
||||||
|
[][2]string{{"test.txt", "test1"}, {"other.txt", "other"}}, nil}
|
||||||
|
|
||||||
|
httpServer, err := mkTestingFileServer(context.remoteFiles)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer httpServer.Close()
|
||||||
|
|
||||||
|
idx := strings.LastIndex(httpServer.URL, ":")
|
||||||
|
if idx < 0 {
|
||||||
|
t.Fatalf("could not get port from test http server address %s", httpServer.URL)
|
||||||
|
}
|
||||||
|
port := httpServer.URL[idx+1:]
|
||||||
|
|
||||||
|
ip := srv.runtime.networkManager.bridgeNetwork.IP
|
||||||
|
dockerfile := constructDockerfile(context.dockerfile, ip, port)
|
||||||
|
|
||||||
|
buildfile := NewBuildFile(srv, ioutil.Discard, false, true)
|
||||||
|
_, err = buildfile.Build(mkTestContext(dockerfile, context.files, t))
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Log("Error should not be nil")
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err.Error() != "Forbidden path: /" {
|
||||||
|
t.Logf("Error message is not expected: %s", err.Error())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue