Skip to content

Fixes fatal error when missing known_hosts - #834

Open
bdowling wants to merge 4 commits into
paramiko:mainfrom
bdowling:fix_missing_host_keys
Open

bdowling wants to merge 4 commits into
paramiko:mainfrom
bdowling:fix_missing_host_keys

Conversation

@bdowling

Copy link
Copy Markdown

Quick fix that addresses #625 for the case where known_hosts does not exist.

Note: This does not create the parent directory, not sure the opinions on that, but it likely should, but the concern I would have is that the path to the known_host file could potentially be created outside our control, so it's not guaranteed we're working on ~/.ssh ...

Perhaps a compromise might be to add a test for the directory existing and report that as a clean failure or we just let the open Exception fire.

@coveralls

coveralls commented Oct 27, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.04%) to 74.247% when pulling bbbff69 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

@bitprophet

Copy link
Copy Markdown
Member

I never circled back on #625, just blatted some thoughts there.

This is a good partial solution insofar as it prevents the sanity reload of the file from dying if we're in the "I gave you a new, nonexistent known_hosts file that I expect you to create for me" scenario.

It will still IOError if the path is invalid or if permissions don't allow opening for writes. This is largely good - we do not want to mkdir despite that feeling like a nice thing to do, it actually just makes user error harder to spot :) - but as I noted in #625, if we want to act like OpenSSH's client program, the "best" behavior is to warn about those IOErrors and continue operating.

If you'd like to update this so it wraps the file open/write in a try/except for IOError, and writes a warning to stderr in the except clause, that'd be aces. Tests would also be awesome. I'll add this or the parent to a release milestone so somebody gets to it sometime though. Thanks!

also use hostkeys.save() which was same as existing code.
@bdowling

Copy link
Copy Markdown
Author

I added the IOError warnings.

Ref added to #835 also talks about this.

@coveralls

coveralls commented Oct 31, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.07%) to 74.275% when pulling 41f8180 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.01%) to 74.192% when pulling 9f51206 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.01%) to 74.192% when pulling 9f51206 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

@coveralls

coveralls commented Nov 1, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.08%) to 74.289% when pulling 9f51206 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.01%) to 74.192% when pulling 9f51206 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

@coveralls

coveralls commented Nov 2, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 74.331% when pulling 74dca98 on bdowling:fix_missing_host_keys into 7366f96 on paramiko:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants