Skip to content

Commit

Permalink
pyinfra/connectors: Fix overwriting of users known_hosts file (pyinfr…
Browse files Browse the repository at this point in the history
…a-dev#1209)

This fixes issue pyinfra-dev#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.
  • Loading branch information
vo452 committed Dec 5, 2024
1 parent 78c93ec commit 35cd986
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 35cd986

Please sign in to comment.