From 62a15c16fc0b23ee0ea8f926b9aaa414e2e525ed Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Tue, 5 Mar 2019 15:56:50 +0900 Subject: [PATCH] commandconn: set SysProcAttr.Setsid Setting `Setsid` is needed for SSH connection helper with `ProxyCommand` config, so as to detach TTY. e.g. $ cat ~/.ssh/config Host foo Hostname foo ProxyCommand ssh -W %h:%p bastion $ DOCKER_HOST=ssh://foo docker run -it --rm alpine / # Fix #1707 Signed-off-by: Akihiro Suda --- cli/connhelper/commandconn/commandconn.go | 2 ++ .../{commandconn_linux.go => pdeathsig_linux.go} | 4 +--- ...{commandconn_nolinux.go => pdeathsig_nolinux.go} | 0 cli/connhelper/commandconn/session_unix.go | 13 +++++++++++++ cli/connhelper/commandconn/session_windows.go | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) rename cli/connhelper/commandconn/{commandconn_linux.go => pdeathsig_linux.go} (55%) rename cli/connhelper/commandconn/{commandconn_nolinux.go => pdeathsig_nolinux.go} (100%) create mode 100644 cli/connhelper/commandconn/session_unix.go create mode 100644 cli/connhelper/commandconn/session_windows.go diff --git a/cli/connhelper/commandconn/commandconn.go b/cli/connhelper/commandconn/commandconn.go index 7e03741fad..4c5783fb3b 100644 --- a/cli/connhelper/commandconn/commandconn.go +++ b/cli/connhelper/commandconn/commandconn.go @@ -41,7 +41,9 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) { // we assume that args never contains sensitive information logrus.Debugf("commandconn: starting %s with %v", cmd, args) c.cmd.Env = os.Environ() + c.cmd.SysProcAttr = &syscall.SysProcAttr{} setPdeathsig(c.cmd) + createSession(c.cmd) c.stdin, err = c.cmd.StdinPipe() if err != nil { return nil, err diff --git a/cli/connhelper/commandconn/commandconn_linux.go b/cli/connhelper/commandconn/pdeathsig_linux.go similarity index 55% rename from cli/connhelper/commandconn/commandconn_linux.go rename to cli/connhelper/commandconn/pdeathsig_linux.go index 7d8b122e32..1cdd788cc0 100644 --- a/cli/connhelper/commandconn/commandconn_linux.go +++ b/cli/connhelper/commandconn/pdeathsig_linux.go @@ -6,7 +6,5 @@ import ( ) func setPdeathsig(cmd *exec.Cmd) { - cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGKILL, - } + cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL } diff --git a/cli/connhelper/commandconn/commandconn_nolinux.go b/cli/connhelper/commandconn/pdeathsig_nolinux.go similarity index 100% rename from cli/connhelper/commandconn/commandconn_nolinux.go rename to cli/connhelper/commandconn/pdeathsig_nolinux.go diff --git a/cli/connhelper/commandconn/session_unix.go b/cli/connhelper/commandconn/session_unix.go new file mode 100644 index 0000000000..6448500d63 --- /dev/null +++ b/cli/connhelper/commandconn/session_unix.go @@ -0,0 +1,13 @@ +// +build !windows + +package commandconn + +import ( + "os/exec" +) + +func createSession(cmd *exec.Cmd) { + // for supporting ssh connection helper with ProxyCommand + // https://github.com/docker/cli/issues/1707 + cmd.SysProcAttr.Setsid = true +} diff --git a/cli/connhelper/commandconn/session_windows.go b/cli/connhelper/commandconn/session_windows.go new file mode 100644 index 0000000000..b926074500 --- /dev/null +++ b/cli/connhelper/commandconn/session_windows.go @@ -0,0 +1,8 @@ +package commandconn + +import ( + "os/exec" +) + +func createSession(cmd *exec.Cmd) { +}