From 12c8370f6810df5cd3da552e1e7412b4452c736a Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mar 17 2020 11:31:56 +0000 Subject: Implement OpenSSH password auth with sshpass Paramiko does not yet implement modern handshake variants with rsa-sha2-256. OpenSSH 8.2 release notes say that the old ssh-rsa algorithm (RSA with SHA-1 signature) be disabled soon. The algorithm does not work in FIPS either. The patch implements OpenSSH password-based logins using the sshpass utilility. It reads the password from a secure file and feeds it to OpenSSH command line tool. See: https://www.openssh.com/releasenotes.html See: https://linux.die.net/man/1/sshpass Signed-off-by: Christian Heimes --- diff --git a/pytest_multihost/transport.py b/pytest_multihost/transport.py index ec102db..b53a4d8 100644 --- a/pytest_multihost/transport.py +++ b/pytest_multihost/transport.py @@ -375,9 +375,15 @@ class OpenSSHTransport(Transport): if self.host.ssh_key_filename: key_filename = os.path.expanduser(self.host.ssh_key_filename) argv.extend(['-i', key_filename]) + # disable password prompt + argv.extend(['-o', 'BatchMode=yes']) elif self.host.ssh_password: - self.log.critical('Password authentication not supported') - raise RuntimeError('Password authentication not supported') + password_file = os.path.join(self.control_dir.path, 'password') + with open(password_file, 'w') as f: + os.fchmod(f.fileno(), 600) + f.write(self.host.ssh_password) + f.write('\n') + argv = ['sshpass', '-f', password_file] + argv else: self.log.critical('No SSH credentials configured') raise RuntimeError('No SSH credentials configured') diff --git a/python-pytest-multihost.spec b/python-pytest-multihost.spec index 926afa1..32eecac 100644 --- a/python-pytest-multihost.spec +++ b/python-pytest-multihost.spec @@ -33,10 +33,14 @@ BuildRequires: pytest BuildRequires: python3-devel BuildRequires: python3-setuptools BuildRequires: python3-pytest +BuildRequires: openssh-clients +BuildRequires: sshpass %endif Requires: python Requires: pytest >= 2.4.0 +Requires: openssh-clients +Recommends: sshpass # Should use python_provide macros, but those won't work in older EPEL Provides: python2-%{srcname} @@ -59,6 +63,8 @@ Summary: Utility for writing multi-host tests for pytest Requires: python3 Requires: python3-pytest +Requires: openssh-clients +Recommends: sshpass %description -n python3-%{srcname} Allows pytest tests to run commands on several machines.