Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ingest): skip ssh known_hosts verification for git clone #5945

Merged
merged 2 commits into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -11,8 +11,9 @@


class GitClone:
def __init__(self, tmp_dir):
def __init__(self, tmp_dir: str, skip_known_host_verification: bool = True):
self.tmp_dir = tmp_dir
self.skip_known_host_verification = skip_known_host_verification

def clone(self, ssh_key: SecretStr, repo_url: str) -> Path:
unique_dir = str(uuid4())
Expand All @@ -30,6 +31,12 @@ def clone(self, ssh_key: SecretStr, repo_url: str) -> Path:
fp.write(ssh_key.get_secret_value())

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.
# See https://stackoverflow.com/a/28527476/5004662.
git_ssh_cmd += (
" -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
)
logger.debug("ssh_command=%s", git_ssh_cmd)
logger.info(f"⏳ Cloning repo '{repo_url}', this can take some time...")
git.Repo.clone_from(
Expand Down
2 changes: 1 addition & 1 deletion metadata-ingestion/tests/integration/git/test_git_clone.py
Expand Up @@ -7,7 +7,7 @@

def test_git_clone(pytestconfig, tmp_path):

git_clone = GitClone(tmp_path)
git_clone = GitClone(str(tmp_path))
secret_env_variable = "DATAHUB_LOOKML_GIT_TEST_SSH_KEY"
if os.environ.get(secret_env_variable) is not None:
secret_key = SecretStr(os.environ.get(secret_env_variable)) # type: ignore
Expand Down