Fix crash on empty answer to the unknown host key prompt
An empty answer raised IndexError, and running without a terminal (e.g. from cron) raised EOFError. Treat both as "no", and log why the connection was aborted.
This commit is contained in:
@@ -375,12 +375,18 @@ class Backup:
|
|||||||
|
|
||||||
return ssh
|
return ssh
|
||||||
except UserWarning:
|
except UserWarning:
|
||||||
|
try:
|
||||||
k = input(
|
k = input(
|
||||||
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ')
|
f'Unknown key for host {self.ssh_host}. Continue anyway? (Y/N) ')
|
||||||
|
except EOFError:
|
||||||
|
# No terminal available (e.g. cron or systemd)
|
||||||
|
k = ''
|
||||||
|
|
||||||
if k[0].upper() == 'Y':
|
if k.strip().upper().startswith('Y'):
|
||||||
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
else:
|
else:
|
||||||
|
logger.critical('Unknown host key for %s. Connection aborted', self.ssh_host)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
except paramiko.BadHostKeyException as e:
|
except paramiko.BadHostKeyException as e:
|
||||||
logger.critical('Can\'t connect to the server.')
|
logger.critical('Can\'t connect to the server.')
|
||||||
|
|||||||
Reference in New Issue
Block a user