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

Add manual two factor authentication #259

Merged
merged 3 commits into from
Feb 4, 2024
Merged
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
28 changes: 27 additions & 1 deletion pysqa/ext/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ def __init__(self, config, directory="~/.queues", execute_command=execute_comman
self._ssh_key_passphrase = config["ssh_key_passphrase"]
else:
self._ssh_key_passphrase = None
if "ssh_two_factor_authentication" in config.keys():
self._ssh_two_factor_authentication = config[
"ssh_two_factor_authentication"
]
else:
self._ssh_two_factor_authentication = False
if "ssh_authenticator_service" in config.keys():
self._ssh_authenticator_service = config["ssh_authenticator_service"]
self._ssh_two_factor_authentication = True
else:
self._ssh_authenticator_service = None
if "ssh_proxy_host" in config.keys():
Expand Down Expand Up @@ -228,7 +235,11 @@ def _open_ssh_connection(self):
username=self._ssh_username,
key_filename=self._ssh_key,
)
elif self._ssh_password is not None and self._ssh_authenticator_service is None:
elif (
self._ssh_password is not None
and self._ssh_authenticator_service is None
and not self._ssh_two_factor_authentication
):
ssh.connect(
hostname=self._ssh_host,
port=self._ssh_port,
Expand All @@ -238,6 +249,7 @@ def _open_ssh_connection(self):
elif (
self._ssh_password is not None
and self._ssh_authenticator_service is not None
and self._ssh_two_factor_authentication
):

def authentication(title, instructions, prompt_list):
Expand All @@ -260,6 +272,20 @@ def authentication(title, instructions, prompt_list):
ssh._transport.auth_interactive(
username=self._ssh_username, handler=authentication, submethods=""
)
elif (
self._ssh_password is not None
and self._ssh_authenticator_service is None
and self._ssh_two_factor_authentication
):
ssh.connect(
hostname=self._ssh_host,
port=self._ssh_port,
username=self._ssh_username,
password=self._ssh_password,
)
ssh._transport.auth_interactive_dumb(
username=self._ssh_username, handler=None, submethods=""
)
else:
raise ValueError("Un-supported authentication method.")

Expand Down
Loading