Skip to content

Commit

Permalink
Passthrough SSH-Key filename && passphrase
Browse files Browse the repository at this point in the history
Signed-off-by: Max KvR <max.kvr@web.de>
  • Loading branch information
Max KvR committed Jan 27, 2023
1 parent aca129d commit 211d5c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docker/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(self, base_url=None, version=None,
timeout=DEFAULT_TIMEOUT_SECONDS, tls=False,
user_agent=DEFAULT_USER_AGENT, num_pools=None,
credstore_env=None, use_ssh_client=False,
ssh_key_phrase=None, ssh_key_filename=None,
max_pool_size=DEFAULT_MAX_POOL_SIZE):
super().__init__()

Expand Down Expand Up @@ -170,7 +171,8 @@ def __init__(self, base_url=None, version=None,
try:
self._custom_adapter = SSHHTTPAdapter(
base_url, timeout, pool_connections=num_pools,
max_pool_size=max_pool_size, shell_out=use_ssh_client
max_pool_size=max_pool_size, shell_out=use_ssh_client,
ssh_key_phrase=ssh_key_phrase, ssh_key_filename=ssh_key_filename
)
except NameError:
raise DockerException(
Expand Down
8 changes: 7 additions & 1 deletion docker/transport/sshconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class SSHHTTPAdapter(BaseHTTPAdapter):
def __init__(self, base_url, timeout=60,
pool_connections=constants.DEFAULT_NUM_POOLS,
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE,
shell_out=False):
shell_out=False, ssh_key_filename=None, ssh_key_phrase=None, ):
self.ssh_client = None
if not shell_out:
self._create_paramiko_client(base_url)
Expand All @@ -184,6 +184,8 @@ def __init__(self, base_url, timeout=60,
self.pools = RecentlyUsedContainer(
pool_connections, dispose_func=lambda p: p.close()
)
self.ssh_key_filename = ssh_key_filename
self.ssh_key_phrase = ssh_key_phrase
super().__init__()

def _create_paramiko_client(self, base_url):
Expand Down Expand Up @@ -213,6 +215,10 @@ def _create_paramiko_client(self, base_url):
self.ssh_params['username'] = host_config['user']
if 'identityfile' in host_config:
self.ssh_params['key_filename'] = host_config['identityfile']
if self.ssh_key_filename:
self.ssh_params['key_filename'] = self.ssh_key_filename
if self.ssh_key_phrase:
self.ssh_params['passphrase'] = self.ssh_key_phrase

self.ssh_client.load_system_host_keys()
self.ssh_client.set_missing_host_key_policy(paramiko.RejectPolicy())
Expand Down

0 comments on commit 211d5c4

Please sign in to comment.