From b951ed9206010f6273f86a85a968ca70282daaed Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 2 Mar 2023 18:57:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20account=20=E7=A7=81?= =?UTF-8?q?=E9=92=A5=E6=96=87=E4=BB=B6=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/models/base.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/accounts/models/base.py b/apps/accounts/models/base.py index 7233a12a2..26ebcd89a 100644 --- a/apps/accounts/models/base.py +++ b/apps/accounts/models/base.py @@ -12,7 +12,7 @@ from accounts.const import SecretType from common.db import fields from common.utils import ( 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 @@ -118,7 +118,13 @@ class BaseAccount(JMSOrgBaseModel): key_name = '.' + md5(self.private_key.encode('utf-8')).hexdigest() key_path = os.path.join(tmp_dir, key_name) 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): + f.write("\n") os.chmod(key_path, 0o400) return key_path