mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-06-23 21:47:27 +00:00
fix: 修复 ed25519 私钥测试可连接性失败问题
This commit is contained in:
parent
6bc2f73f49
commit
03cc487fe6
@ -13,7 +13,7 @@ from sshtunnel import SSHTunnelForwarder, BaseSSHTunnelForwarderError
|
|||||||
|
|
||||||
from assets.automations.methods import platform_automation_methods
|
from assets.automations.methods import platform_automation_methods
|
||||||
from common.utils import get_logger, lazyproperty
|
from common.utils import get_logger, lazyproperty
|
||||||
from common.utils import ssh_pubkey_gen, ssh_key_string_to_obj
|
from common.utils import ssh_pubkey_gen, is_openssh_format_key
|
||||||
from ops.ansible import JMSInventory, PlaybookRunner, DefaultCallback
|
from ops.ansible import JMSInventory, PlaybookRunner, DefaultCallback
|
||||||
|
|
||||||
logger = get_logger(__name__)
|
logger = get_logger(__name__)
|
||||||
@ -127,7 +127,13 @@ class BasePlaybookManager:
|
|||||||
key_path = os.path.join(path_dir, key_name)
|
key_path = os.path.join(path_dir, key_name)
|
||||||
|
|
||||||
if not os.path.exists(key_path):
|
if not os.path.exists(key_path):
|
||||||
ssh_key_string_to_obj(secret, password=None).write_private_key_file(key_path)
|
# https://github.com/ansible/ansible-runner/issues/544
|
||||||
|
# ssh requires OpenSSH format keys to have a full ending newline.
|
||||||
|
# It does not require this for old-style PEM keys.
|
||||||
|
with open(key_path, 'w') as f:
|
||||||
|
f.write(secret)
|
||||||
|
if is_openssh_format_key(secret):
|
||||||
|
f.write("\n")
|
||||||
os.chmod(key_path, 0o400)
|
os.chmod(key_path, 0o400)
|
||||||
return key_path
|
return key_path
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ def ssh_private_key_gen(private_key, password=None):
|
|||||||
|
|
||||||
def ssh_pubkey_gen(private_key=None, username='jumpserver', hostname='localhost', password=None):
|
def ssh_pubkey_gen(private_key=None, username='jumpserver', hostname='localhost', password=None):
|
||||||
private_key = ssh_private_key_gen(private_key, password=password)
|
private_key = ssh_private_key_gen(private_key, password=password)
|
||||||
if not isinstance(private_key, (paramiko.RSAKey, paramiko.DSSKey)):
|
if not isinstance(private_key, _supported_paramiko_ssh_key_types):
|
||||||
raise IOError('Invalid private key')
|
raise IOError('Invalid private key')
|
||||||
|
|
||||||
public_key = "%(key_type)s %(key_content)s %(username)s@%(hostname)s" % {
|
public_key = "%(key_type)s %(key_content)s %(username)s@%(hostname)s" % {
|
||||||
|
Loading…
Reference in New Issue
Block a user