From 66985335d06be7805571988edfe08c2d9e0111c7 Mon Sep 17 00:00:00 2001 From: Harshal Sheth Date: Wed, 14 Sep 2022 20:53:26 -0700 Subject: [PATCH] fix(ingest): add trailing newline to ssh keys (#5947) --- .../src/datahub/ingestion/source/git/git_import.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/metadata-ingestion/src/datahub/ingestion/source/git/git_import.py b/metadata-ingestion/src/datahub/ingestion/source/git/git_import.py index b552d2e986412..5fb924c4858b7 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/git/git_import.py +++ b/metadata-ingestion/src/datahub/ingestion/source/git/git_import.py @@ -22,6 +22,8 @@ def clone(self, ssh_key: SecretStr, repo_url: str) -> Path: dirs_to_create = [keys_dir, checkout_dir] for d in dirs_to_create: os.makedirs(d, exist_ok=True) + + # Write the SSH key to a file. git_ssh_identity_file = os.path.join(keys_dir, "ssh_key") with open( git_ssh_identity_file, @@ -29,7 +31,11 @@ def clone(self, ssh_key: SecretStr, repo_url: str) -> Path: opener=lambda path, flags: os.open(path, flags, 0o600), ) as fp: fp.write(ssh_key.get_secret_value()) + # SSH keys must have a trailing newline. Multiple newlines are fine, + # so we can just add one unconditionally. + fp.write("\n") + # Clone the repo using the ssh key. git_ssh_cmd = f"ssh -i {git_ssh_identity_file}" if self.skip_known_host_verification: # Without this, the ssh command will prompt for confirmation of the host key.