|
18 | 18 | import subprocess
|
19 | 19 | import sys
|
20 | 20 | import time
|
| 21 | +import warnings |
21 | 22 |
|
22 | 23 | from asyncio import Event, TimeoutError
|
23 | 24 | from calendar import timegm
|
@@ -586,18 +587,35 @@ def _get_ssh_client(self, host):
|
586 | 587 | global remote_user
|
587 | 588 | global remote_pwd
|
588 | 589 | if remote_user is None:
|
589 |
| - remote_user = os.getenv('EG_REMOTE_USER', getpass.getuser()) |
590 |
| - remote_pwd = os.getenv('EG_REMOTE_PWD') # this should use password-less ssh |
| 590 | + use_gss = os.getenv("EG_REMOTE_GSS_SSH", None) |
| 591 | + remote_pwd = os.getenv("EG_REMOTE_PWD") # this should use password-less ssh |
| 592 | + remote_user = os.getenv("EG_REMOTE_USER", getpass.getuser()) |
| 593 | + |
| 594 | + if use_gss and (remote_pwd or remote_user): |
| 595 | + warnings.warn( |
| 596 | + "Both `EG_REMOTE_GSS_SSH` and one of `EG_REMOTE_PWD` or `EG_REMOTE_USER` is set. " |
| 597 | + "Those options are mutually exclusive, you configuration may be incorrect. " |
| 598 | + "EG_REMOTE_GSS_SSH will take priority." |
| 599 | + ) |
591 | 600 |
|
592 | 601 | try:
|
593 | 602 | ssh = paramiko.SSHClient()
|
594 | 603 | ssh.load_system_host_keys()
|
595 |
| - ssh.set_missing_host_key_policy(paramiko.RejectPolicy()) |
596 | 604 | host_ip = gethostbyname(host)
|
597 |
| - if remote_pwd: |
598 |
| - ssh.connect(host_ip, port=ssh_port, username=remote_user, password=remote_pwd) |
| 605 | + if use_gss: |
| 606 | + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
| 607 | + ssh.connect(host_ip, port=ssh_port, gss_auth=True) |
599 | 608 | else:
|
600 |
| - ssh.connect(host_ip, port=ssh_port, username=remote_user) |
| 609 | + ssh.set_missing_host_key_policy(paramiko.RejectPolicy()) |
| 610 | + if remote_pwd: |
| 611 | + ssh.connect( |
| 612 | + host_ip, |
| 613 | + port=ssh_port, |
| 614 | + username=remote_user, |
| 615 | + password=remote_pwd, |
| 616 | + ) |
| 617 | + else: |
| 618 | + ssh.connect(host_ip, port=ssh_port, username=remote_user) |
601 | 619 | except Exception as e:
|
602 | 620 | http_status_code = 500
|
603 | 621 | current_host = gethostbyname(gethostname())
|
|
0 commit comments