Forbid client piping to tty enabled container

Forbid `docker run -t` with a redirected stdin (such as `echo test |
docker run -ti busybox cat`). Forbid `docker exec -t` with a redirected
stdin. Forbid `docker attach` with a redirect stdin toward a tty enabled
container.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
Upstream-commit: 67e3ddb75ff27b8de0022e330413b4308ec5b010
Component: engine
This commit is contained in:
Arnaud Porterie
2014-12-09 14:30:49 -08:00
parent b4787aa54e
commit 1d39a69298
10 changed files with 213 additions and 88 deletions
@@ -2742,3 +2742,32 @@ func TestRunPortFromDockerRangeInUse(t *testing.T) {
logDone("run - find another port if port from autorange already bound")
}
func TestRunTtyWithPipe(t *testing.T) {
defer deleteAllContainers()
done := make(chan struct{})
go func() {
defer close(done)
cmd := exec.Command(dockerBinary, "run", "-ti", "busybox", "true")
if _, err := cmd.StdinPipe(); err != nil {
t.Fatal(err)
}
expected := "cannot enable tty mode"
if out, _, err := runCommandWithOutput(cmd); err == nil {
t.Fatal("run should have failed")
} else if !strings.Contains(out, expected) {
t.Fatal("run failed with error %q: expected %q", out, expected)
}
}()
select {
case <-done:
case <-time.After(3 * time.Second):
t.Fatal("container is running but should have failed")
}
logDone("run - forbid piped stdin with tty")
}