fix(ssh-tunnel): wrap pkey into StringIO buffer before creating the tunnel (#22763)

This commit is contained in:
Hugh A. Miles II 2023-01-17 22:52:18 +00:00 committed by GitHub
parent c58dbf8b9c
commit c536f713d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -16,9 +16,11 @@
# under the License.
import importlib
from io import StringIO
from typing import TYPE_CHECKING
from flask import Flask
from paramiko import RSAKey
from sshtunnel import open_tunnel, SSHTunnelForwarder
from superset.databases.utils import make_url_safe
@ -59,7 +61,9 @@ class SSHManager:
if ssh_tunnel.password:
params["ssh_password"] = ssh_tunnel.password
elif ssh_tunnel.private_key:
params["private_key"] = ssh_tunnel.private_key
private_key_file = StringIO(ssh_tunnel.private_key)
private_key = RSAKey.from_private_key(private_key_file)
params["private_key"] = private_key
params["private_key_password"] = ssh_tunnel.private_key_password
return open_tunnel(**params)