Skip to content

Warn on parse failure when reading known_hosts - #153

Merged
bitprophet merged 1 commit into
paramiko:masterfrom
glasserc:log_bad_hostkeys
Apr 29, 2013
Merged

bitprophet merged 1 commit into
paramiko:masterfrom
glasserc:log_bad_hostkeys

Conversation

@glasserc

Copy link
Copy Markdown
Contributor

This should fix #67 in that it should be much more obvious why a server is unknown: to wit, a key is being ignored.

I wasn't sure how to pass log information from client or transport to hostkeys so I just called out to util.get_logger again. If you have a better way in mind, please let me know and I'll try to implement it.

Comment thread paramiko/hostkeys.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to be something like:

"Not enough fields found in known_hosts in line %r" % line

Slightly clearer, also just uses repr to display the string.

(If we can get the line number at this point, that'd also be great to add.)

@bitprophet

Copy link
Copy Markdown
Member

Thanks for this!

  • I made some nitpicky language/PEP8 suggestions, if you could incorporate those :)
  • No big deal re: using logger in this way, right now anything is better than nothing wrt this problem area (poor communication re: keys).
  • Please rebase this against the 1.10 branch, and add a changelog entry (don't forget to credit yourself!) in the NEWS file in the 1.10 section.

I'll merge once those changes are in. Thanks again!

@glasserc

Copy link
Copy Markdown
Contributor Author

Hi, I understand the language changes, but which changes are the PEP8 ones? Unwrapping one-element tuples?

I can easily add lineno to from_line and use that to pass the line number information for logging purposes. There's only one caller of from_line, so that should be fine. Is that OK?

Ethan

@glasserc

Copy link
Copy Markdown
Contributor Author

Ah, I think I see -- spacing around the % operator. I'm leaving the one-element tuple (PEP8 is silent on that ;) ) and pushing --force onto this branch. Thanks for the review!

@bitprophet

Copy link
Copy Markdown
Member

Yes, it was mostly the spacing. I personally think one-item tuples in interpolation is ugly and prefer only to use it when required for disambiguating things, but won't fight over it. Also, no worries on the line number thing, that works for me. Thanks again!

bitprophet added a commit that referenced this pull request Apr 29, 2013
Warn on parse failure when reading known_hosts
@bitprophet
bitprophet merged commit 675d79d into paramiko:master Apr 29, 2013
@bitprophet

Copy link
Copy Markdown
Member

N.B. even with my personal, pretty boring known_hosts, I was seeing No logger defined for paramiko.hostkeys once this change landed, because I had some line in my file that was slightly off (and because the logging module default is to spew WARN and above).

I think it should probably be an info, not a warning, or lots of folks are going to start seeing this in their previously "working fine" setups and wonder what's up. It's still logged, and so will still be visible to somebody explicitly troubleshooting their known_hosts file, IMO.

Making that change myself now.

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.

Confusing error message when trying to verify unknown host key types

2 participants