Skip to content

Commit

Permalink
support public key auth with keyboard interactive (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi-FanLi authored Oct 13, 2023
1 parent 881fd1b commit e1a29fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions dpdispatcher/ssh_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
self.ssh = None
self.tar_compress = tar_compress
self.look_for_keys = look_for_keys
self._keyboard_interactive_auth = False
self._setup_ssh()

# @classmethod
Expand Down Expand Up @@ -189,20 +190,22 @@ def _setup_ssh(self):
if key is not None:
break

allowed_types = set()
if key is not None:
try:
ts.auth_publickey(self.username, key)
allowed_types = set(ts.auth_publickey(self.username, key))
except paramiko.ssh_exception.AuthenticationException as e:
key_error = e
else:
key_ok = True
if self.totp_secret is not None:
if self.totp_secret is not None or "keyboard-interactive" in allowed_types:
try:
ts.auth_interactive(self.username, self.inter_handler)
except paramiko.ssh_exception.AuthenticationException:
# since the asynchrony of interactive authentication, one addtional try is added
# retry for up to 6 times
raise RetrySignal("Authentication failed")
self._keyboard_interactive_auth = True
elif key_ok:
pass
elif self.password is not None:
Expand Down Expand Up @@ -392,6 +395,7 @@ def rsync_available(self) -> bool:
and self.exec_command("rsync --version")[1].channel.recv_exit_status() == 0
and self.totp_secret is None
and self.passphrase is None
and not self._keyboard_interactive_auth
)

@property
Expand Down

0 comments on commit e1a29fc

Please sign in to comment.