Skip to content

Commit d7b16ef

Browse files
authored
Merge pull request #2755 from aiordache/fix_ssh_bug
Fix host trimming and remove quiet flag for the ssh connection
2 parents 78f5249 + caab390 commit d7b16ef

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

docker/transport/sshconn.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,33 @@ def __init__(self, host):
2929
socket.AF_INET, socket.SOCK_STREAM)
3030
self.host = host
3131
self.port = None
32+
self.user = None
3233
if ':' in host:
3334
self.host, self.port = host.split(':')
35+
if '@' in self.host:
36+
self.user, self.host = host.split('@')
37+
3438
self.proc = None
3539

3640
def connect(self, **kwargs):
37-
port = '' if not self.port else '-p {}'.format(self.port)
38-
args = [
39-
'ssh',
40-
'-q',
41-
self.host,
42-
port,
43-
'docker system dial-stdio'
44-
]
41+
args = ['ssh']
42+
if self.user:
43+
args = args + ['-l', self.user]
44+
45+
if self.port:
46+
args = args + ['-p', self.port]
47+
48+
args = args + ['--', self.host, 'docker system dial-stdio']
4549

4650
preexec_func = None
4751
if not constants.IS_WINDOWS_PLATFORM:
48-
preexec_func = lambda: signal.signal(signal.SIGINT, signal.SIG_IGN)
52+
def f():
53+
signal.signal(signal.SIGINT, signal.SIG_IGN)
54+
preexec_func = f
4955

5056
self.proc = subprocess.Popen(
5157
' '.join(args),
58+
env=os.environ,
5259
shell=True,
5360
stdout=subprocess.PIPE,
5461
stdin=subprocess.PIPE,
@@ -124,9 +131,6 @@ def __init__(self, ssh_client=None, timeout=60, maxsize=10, host=None):
124131
if ssh_client:
125132
self.ssh_transport = ssh_client.get_transport()
126133
self.ssh_host = host
127-
self.ssh_port = None
128-
if ':' in host:
129-
self.ssh_host, self.ssh_port = host.split(':')
130134

131135
def _new_conn(self):
132136
return SSHConnection(self.ssh_transport, self.timeout, self.ssh_host)
@@ -169,7 +173,10 @@ def __init__(self, base_url, timeout=60,
169173
self._create_paramiko_client(base_url)
170174
self._connect()
171175

172-
self.ssh_host = base_url.lstrip('ssh://')
176+
self.ssh_host = base_url
177+
if base_url.startswith('ssh://'):
178+
self.ssh_host = base_url[len('ssh://'):]
179+
173180
self.timeout = timeout
174181
self.max_pool_size = max_pool_size
175182
self.pools = RecentlyUsedContainer(

0 commit comments

Comments
 (0)