Skip to content

Commit 154eced

Browse files
committed
Allow SSH authentication via GSS.
This attempt to implement GSS as requested in #946. I've tried to also document the other environment variable, though I couldn't find where or how they are supposed to be used. I'm also currently trying to find a deployment that could use GSS to test this, but haven't so far. I'm assuming that if GSS is enabled then it takes priority over username/password.
1 parent 6c227e6 commit 154eced

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

docs/source/config-options.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ The following environment variables can be used to influence functionality and a
451451
The port number used for ssh operations for installations choosing to
452452
configure the ssh server on a port other than the default 22.
453453
454+
EG_REMOTE_PWD=None
455+
The password to use to ssh to remote hosts
456+
457+
EG_REMOTE_USER=None
458+
The username to use when connecting to remote hosts (default to `getpass.getuser()`
459+
when not set).
460+
461+
EG_REMOTE_GSS_SSH=None
462+
Use gss instead of EG_REMOTE_USER and EG_REMOTE_PWD to connect to remote host via SSH.
463+
454464
EG_YARN_CERT_BUNDLE=<custom_truststore_path>
455465
The path to a .pem or any other custom truststore used as a CA bundle in yarn-api-client.
456466
```

enterprise_gateway/services/processproxies/processproxy.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import subprocess
1919
import sys
2020
import time
21+
import warnings
2122

2223
from asyncio import Event, TimeoutError
2324
from calendar import timegm
@@ -586,18 +587,35 @@ def _get_ssh_client(self, host):
586587
global remote_user
587588
global remote_pwd
588589
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+
)
591600

592601
try:
593602
ssh = paramiko.SSHClient()
594603
ssh.load_system_host_keys()
595-
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
596604
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)
599608
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)
601619
except Exception as e:
602620
http_status_code = 500
603621
current_host = gethostbyname(gethostname())

0 commit comments

Comments
 (0)