Skip to content

new feature: docker -H ssh://host#33566

Closed
AkihiroSuda wants to merge 1 commit intomoby:masterfrom
AkihiroSuda:ssh2
Closed

new feature: docker -H ssh://host#33566
AkihiroSuda wants to merge 1 commit intomoby:masterfrom
AkihiroSuda:ssh2

Conversation

@AkihiroSuda
Copy link
Copy Markdown
Member

@AkihiroSuda AkihiroSuda commented Jun 7, 2017

- What I did

Implemented docker -H ssh://host, which allows connecting to a Unix socket listening on a remote daemon via an OpenSSH connection.

[docker] ----- TCP -----> [sshd] -- Unix --> [dockerd]

Replaces #32161 (which used Go-native SSH rather than os/exec even on Unix, and hence didn't support ~/.ssh/config)

Closes #31871

Motivations:

The feature is purely implemented on the client side.
No need to configure the daemon.

- How I did it

  • on Unix: By os/exec-uting ssh -L local.sock:/var/run/docker.sock. So it should even work with ~/.ssh/config.

  • on Windows: using pageant + Go-native ssh (golang.org/x/crypto/ssh)

- How to verify it

  • No need to configure the daemon. Even no need to replace the daemon built from this PR. I confirmed this PR works well with vanilla 17.05.0-ce daemon.

  • You just need to create a SSH user account that can access /var/run/docker.sock

  • On Windows client, you need to register your key to pageant.exe. No need to install ssh.exe.

$ go build ./contrib/client-test
$ ./client-test ssh://me@host
(JSON representation of `docker info` will be shown)

The argument can be also:

  • ssh://me@host:22/var/run/docker.sock
  • ssh://host (using $USER as the user name)
  • ...

- Description for the changelog
Now docker client can connect to a Unix socket listening on a remote daemon via an OpenSSH connection

- A picture of a cute animal (not mandatory but encouraged)

penguins

TODO

Signed-off-by: Akihiro Suda [email protected]

This commit allows connecting to a Unix socket listening on a remote daemon
via an OpenSSH connection.

e.g. `docker -H ssh://host` or `docker -H ssh://me@host:22/var/run/docker.sock`.

The feature is purely implemented on the client side.
No need to configure the daemon.

Signed-off-by: Akihiro Suda <[email protected]>
@AkihiroSuda
Copy link
Copy Markdown
Member Author

Comment thread opts/hosts.go
case "fd":
return addr, nil
case "ssh": // unix over ssh (can be specified for `docker -H` but not for `dockerd -H`)
usr, err := whoami()
Copy link
Copy Markdown
Member

@tonistiigi tonistiigi Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not let ssh(1) handle this? This calls into /etc/passwd parsing on macOS that doesn't work for regular users. It also overrides any user set in the ssh config.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll update

@justincormack
Copy link
Copy Markdown
Contributor

Given that Windows will soon have native openssh support, it seems weird to special case it now?

@AkihiroSuda
Copy link
Copy Markdown
Member Author

@justincormack
If we are going to use socat or nc instead of -L local.sock:/var/run/docker.sock, we can eliminate special case for Windows ( docker/go-connections#39 (comment) )

@AkihiroSuda
Copy link
Copy Markdown
Member Author

Method No socket file leak Support ~/.ssh/config No dependency on Docker product Likely to work on default Docker installation
golang.org/x/crypto/ssh
golang.org/x/crypto/ssh+implement ~/.ssh/config parser ✅ (hard)
os/exec("ssh -L local.sock:/var/run/docker.sock)
os/exec("ssh socat-or-nc") ❌ (socat and nc are rarelly installed)
os/exec("ssh docker sockproxy")
os/exec("ssh dockerd sockproxy") ❌ (dockerd binary name might change on Moby Project)
os/exec("ssh docker sockproxy || ssh socat-or-nc")
SSH subsystem + os/exec("ssh -s somesubsystem") ❌ (needs to modify sshd_config)

design discussion held at docker/go-connections#39

Comments are welcome at docker/go-connections#39

@cpuguy83
Copy link
Copy Markdown
Member

What do you think about implementing a "connection helpers" interface like we do for credentials.
This would allow a user to supply their own custom helpers that will just work natively with the docker CLI.
Helpers can be defined in ~/.docker/config.json matching the protocol of the connection string to a config.
e.g.

{
  "ssh": "~/.docker/ssh_connection_helper",
  "weird": "~/my_weird_connection_helper"
}

Where -H ssh://1.2.3.4:22 would execute the ~/.docker/ssh_connection_helper helper and -H weird://1.2.3.4 would execute ~/my_weird_connection_helper

@AkihiroSuda
Copy link
Copy Markdown
Member Author

@cpuguy83 SGTM, I'll try to update this PR.
Do you come up with other possible plugins?

@AkihiroSuda
Copy link
Copy Markdown
Member Author

Temporarily closing.

Further discussion should be at #31871

@AkihiroSuda
Copy link
Copy Markdown
Member Author

Implemented @cpuguy83 's proposal: docker/cli#889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants