mirror of https://github.com/jumpserver/jumpserver
Merge pull request #9851 from jumpserver/pr@dev@fix_private_key
fix: 修复 ed25519 私钥测试可连接性失败问题pull/9871/head
commit
bb30fcd7fd
|
@ -12,7 +12,7 @@ from accounts.const import SecretType
|
||||||
from common.db import fields
|
from common.db import fields
|
||||||
from common.utils import (
|
from common.utils import (
|
||||||
ssh_key_string_to_obj, ssh_key_gen, get_logger,
|
ssh_key_string_to_obj, ssh_key_gen, get_logger,
|
||||||
random_string, lazyproperty, parse_ssh_public_key_str
|
random_string, lazyproperty, parse_ssh_public_key_str, is_openssh_format_key
|
||||||
)
|
)
|
||||||
from orgs.mixins.models import JMSOrgBaseModel, OrgManager
|
from orgs.mixins.models import JMSOrgBaseModel, OrgManager
|
||||||
|
|
||||||
|
@ -118,7 +118,13 @@ class BaseAccount(JMSOrgBaseModel):
|
||||||
key_name = '.' + md5(self.private_key.encode('utf-8')).hexdigest()
|
key_name = '.' + md5(self.private_key.encode('utf-8')).hexdigest()
|
||||||
key_path = os.path.join(tmp_dir, key_name)
|
key_path = os.path.join(tmp_dir, key_name)
|
||||||
if not os.path.exists(key_path):
|
if not os.path.exists(key_path):
|
||||||
self.private_key_obj.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(self.secret)
|
||||||
|
if is_openssh_format_key(self.secret.encode('utf-8')):
|
||||||
|
f.write("\n")
|
||||||
os.chmod(key_path, 0o400)
|
os.chmod(key_path, 0o400)
|
||||||
return key_path
|
return key_path
|
||||||
|
|
||||||
|
|
|
@ -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.encode('utf-8')):
|
||||||
|
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