You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider updating known_hosts writes to behave like OpenSSH - and append-only #835
save_host_keys in client.py does not perform any locking on the host_keys file before overwriting it and it does not do an atomic rename to replace it either.. This can lead to various race conditions if you have multiple instances using and updating this file at the same time.
I would further question why this module should be rewriting this file in entirety at all? Should it instead only be appending new items? openssh for example leaves conflicts up to the user to resolve, which is a safer path generally speaking.
There are a number of issues (e.g. #435, #680) that I see listed due to rewriting, changing order, losing information, dropping keys paramiko can't parse etc that would be avoided if it only appended new where it could.
Linking this to #625 which I just looked at, mostly just as both deal with known_hosts.
You're right that there's no locking or atomic renames, though I do note the file is reread just prior to writes, which heads off many instances of the problem, even though it certainly doesn't eradicate it.
openssh for example leaves conflicts up to the user to resolve
I can't recall offhand & don't have time to dig, but: does this mean it happily appends conflicting data and then prompts user about conflicts at load/read time? Either way, we do tend to try and honor OpenSSH's behavior barring reasons not to, so that seems like it might be a sensible change offhand, especially given the other upsides you mention.
Main downside is it would be backwards incompatible so we'd want to shunt such a change to the 3.0 release. Not an argument against, just something to be aware of.
changed the title [-]save_host_keys does not lock known_hosts for replacement[/-][+]Consider updating known_hosts writes to behave like OpenSSH - and append-only[/+]on Oct 28, 2016
Would you be willing to accept a PR that keeps the current behavior the default, but allows opt in to improved behavior now? With plan to flip the default in the 3.0 release?
I think I would, yea. I normally like to keep PRs separate but these changes are closely enough related I think you could just update #834 to include that, if you'd prefer. Thanks!
Activity
bitprophet commentedon Oct 28, 2016
Linking this to #625 which I just looked at, mostly just as both deal with known_hosts.
You're right that there's no locking or atomic renames, though I do note the file is reread just prior to writes, which heads off many instances of the problem, even though it certainly doesn't eradicate it.
I can't recall offhand & don't have time to dig, but: does this mean it happily appends conflicting data and then prompts user about conflicts at load/read time? Either way, we do tend to try and honor OpenSSH's behavior barring reasons not to, so that seems like it might be a sensible change offhand, especially given the other upsides you mention.
Main downside is it would be backwards incompatible so we'd want to shunt such a change to the 3.0 release. Not an argument against, just something to be aware of.
[-]save_host_keys does not lock known_hosts for replacement[/-][+]Consider updating known_hosts writes to behave like OpenSSH - and append-only[/+]bdowling commentedon Oct 28, 2016
Would you be willing to accept a PR that keeps the current behavior the default, but allows opt in to improved behavior now? With plan to flip the default in the 3.0 release?
bitprophet commentedon Nov 1, 2016
I think I would, yea. I normally like to keep PRs separate but these changes are closely enough related I think you could just update #834 to include that, if you'd prefer. Thanks!