Skip to content
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

Adding Support for encrypted SSH Private Keys(Resolving #2416) #3092

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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