From 35cd9866c77e1b53684464f16bff18b4ad04ed95 Mon Sep 17 00:00:00 2001 From: Erik Voldstad Date: Mon, 2 Dec 2024 18:04:35 +0100 Subject: [PATCH] pyinfra/connectors: Fix overwriting of users known_hosts file (#1209) This fixes issue #1209, making it so that we append new keys to the users known_hosts file instead of overwriting it. Additionally: Added a testcase that should discover this breaking in the future. Broke out the append functionality into a "append_hostkey" function, making it so we don't needlessly reuse code for AskPolicy and AcceptNewPolicy. Linting actually correct this time. Previous behaviour when adding a new key: Create a paramiko.HostKeys object Read the users known_hosts file Add the new key to the object Save the object, overwriting the users host_keys file. New behaviour: Create a paramiko.HostKeyEntry object using the new hostname and corresponding key. Append this key to the existing known_hosts file. --- .typos.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.typos.toml b/.typos.toml index 186698e11..cbb102110 100644 --- a/.typos.toml +++ b/.typos.toml @@ -13,7 +13,7 @@ extend-ignore-re = [ "forr something in", "unknown tag 'forr'", "nd6 options=", -] + "4Ue1", # Ignore false positive in test_sshuserclient.py (EXAMPLE_KEY_1) [default.extend-words] datas = "datas"