-
Notifications
You must be signed in to change notification settings - Fork 2.1k
connhelper: use ssh multiplexing #2132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,10 @@ import ( | |
| "context" | ||
| "net" | ||
| "net/url" | ||
| "os" | ||
| "strconv" | ||
|
|
||
| "github.com/docker/cli/cli/config" | ||
| "github.com/docker/cli/cli/connhelper/commandconn" | ||
| "github.com/docker/cli/cli/connhelper/ssh" | ||
| "github.com/pkg/errors" | ||
|
|
@@ -34,7 +37,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) { | |
| } | ||
| return &ConnectionHelper{ | ||
| Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) { | ||
| return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...) | ||
| return commandconn.New(ctx, "ssh", append(multiplexingArgs(), append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)...) | ||
| }, | ||
| Host: "http://docker", | ||
| }, nil | ||
|
|
@@ -53,3 +56,19 @@ func GetCommandConnectionHelper(cmd string, flags ...string) (*ConnectionHelper, | |
| Host: "http://docker", | ||
| }, nil | ||
| } | ||
|
|
||
| func multiplexingArgs() []string { | ||
| if v := os.Getenv("DOCKER_SSH_NO_MUX"); v != "" { | ||
| if b, err := strconv.ParseBool(v); err == nil && b { | ||
| return nil | ||
| } | ||
| } | ||
| if err := os.MkdirAll(config.Dir(), 0700); err != nil { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we should create a new directory, because when But it is more likely to hit
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we can let
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The socket itself is created with |
||
| return nil | ||
| } | ||
| args := []string{"-o", "ControlMaster=auto", "-o", "ControlPath=" + config.Dir() + "/%r@%h:%p"} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if .ssh/config already has this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It overwrites afaik. This is the main reason I left a way to opt-out. If we want to be conservative about it, one way would be to use a different helper prefix. |
||
| if v := os.Getenv("DOCKER_SSH_MUX_PERSIST"); v != "" { | ||
| args = append(args, "-o", "ControlPersist="+v) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to have a Docker config option for this as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you would ever set them they would probably be more dependent on the actual
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @justincormack pal ^ |
||
| } | ||
| return args | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you document the new environment variables in https://github.com/docker/cli/blob/master/docs/reference/commandline/cli.md#environment-variables ?