Skip to content

Commit

Permalink
ssh: reject unknown host keys when using Python SSH impl (#2932)
Browse files Browse the repository at this point in the history
In the Secure Shell (SSH) protocol, host keys are used to verify the identity of remote hosts. Accepting unknown host keys may leave the connection open to man-in-the-middle attacks.

Do not accept unknown host keys. In particular, do not set the default missing host key policy for the Paramiko library to either AutoAddPolicy or WarningPolicy. Both of these policies continue even when the host key is unknown. The default setting of RejectPolicy is secure because it throws an exception when it encounters an unknown host key.

Reference: https://cwe.mitre.org/data/definitions/295.html

NOTE: This only affects SSH connections using the native Python SSH implementation (Paramiko), when `use_ssh_client=False` (default). If using the system SSH client (`use_ssh_client=True`), the host configuration
(e.g. `~/.ssh/config`) will apply.

Signed-off-by: Audun Nes <[email protected]>
  • Loading branch information
avnes committed Jul 27, 2022
1 parent bb40ba0 commit d929864
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docker/transport/sshconn.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _create_paramiko_client(self, base_url):
self.ssh_params['key_filename'] = host_config['identityfile']

self.ssh_client.load_system_host_keys()
self.ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy())
self.ssh_client.set_missing_host_key_policy(paramiko.RejectPolicy())

def _connect(self):
if self.ssh_client:
Expand Down

0 comments on commit d929864

Please sign in to comment.