Skip to content

Commit c04dd6e

Browse files
committed
connhelper: add ssh multiplexing
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent af097b2 commit c04dd6e

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

cli/connhelper/connhelper.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
"context"
66
"net"
77
"net/url"
8+
"os"
9+
"strconv"
810

11+
"github.com/docker/cli/cli/config"
912
"github.com/docker/cli/cli/connhelper/commandconn"
1013
"github.com/docker/cli/cli/connhelper/ssh"
1114
"github.com/pkg/errors"
@@ -34,7 +37,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
3437
}
3538
return &ConnectionHelper{
3639
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
37-
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)
40+
return commandconn.New(ctx, "ssh", append(multiplexingArgs(), append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)...)
3841
},
3942
Host: "http://docker",
4043
}, nil
@@ -53,3 +56,19 @@ func GetCommandConnectionHelper(cmd string, flags ...string) (*ConnectionHelper,
5356
Host: "http://docker",
5457
}, nil
5558
}
59+
60+
func multiplexingArgs() []string {
61+
if v := os.Getenv("DOCKER_SSH_NO_MUX"); v != "" {
62+
if b, err := strconv.ParseBool(v); err == nil && b {
63+
return nil
64+
}
65+
}
66+
if err := os.MkdirAll(config.Dir(), 0700); err != nil {
67+
return nil
68+
}
69+
args := []string{"-o", "ControlMaster=auto", "-o", "ControlPath=" + config.Dir() + "/%r@%h:%p"}
70+
if v := os.Getenv("DOCKER_SSH_MUX_PERSIST"); v != "" {
71+
args = append(args, "-o", "ControlPersist="+v)
72+
}
73+
return args
74+
}

0 commit comments

Comments
 (0)