Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If "~/.ssh/known_hosts" does not exist, SFTP backend fails #118

Closed
jonazn opened this issue Feb 1, 2016 · 6 comments
Closed

If "~/.ssh/known_hosts" does not exist, SFTP backend fails #118

jonazn opened this issue Feb 1, 2016 · 6 comments

Comments

@jonazn
Copy link

jonazn commented Feb 1, 2016

In the SFTPStorage backend, the _connect() method attempts to "automatically add host keys from the current user," by loading the "~/.ssh/known_hosts" file. However, it doesn't check if that file actually exists before trying to use it. I spent a while trying to figure out why the SFTP backend wasn't working on my own server before pinpointing this issue. This happens on line 97 of sftpstorage.py:

self._ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))

Perhaps it would be useful to wrap that line in a try/except?

@jschneier
Copy link
Owner

Yeah we should definitely catch that error.

Hmm, the default is to automatically accept unknown hosts which seems...eager? My thinking is to deprecate that default and then if we do catch an error and you haven't told us to auto add I'll just raise a full on exception. What do you think of that plan?

@jonazn
Copy link
Author

jonazn commented Feb 1, 2016

That sounds like a reasonable solution, but there are also times you'd maybe want that behavior. Perhaps a solution could be an additional setting that, if set, lets you accept unknown hosts? It could default to False.

@jschneier
Copy link
Owner

Oh yeah, of course. I'm not even sure how I feel about the fact that it automatically loads the keys in ~/.ssh/knows_hosts.

Not sure how big of a deal it is though.

@begincalendar
Copy link

This issue just bit me, but in a roundabout way.

In the SFTPStorage.exists() method there is try/catch IOError around this self.sftp.stat(remote_path) and that call goes down to hit this issue.

So that try/catch is catching the wrong exception and returning False, which causes infinite recursion when trying to create a directory that doesn't exist.

@adi- adi- mentioned this issue Oct 9, 2016
sallyruthstruik added a commit to sallyruthstruik/django-storages that referenced this issue Jun 2, 2017
@sallyruthstruik
Copy link
Contributor

Pull request with fix: #325

jschneier pushed a commit that referenced this issue Jun 2, 2017
@jschneier
Copy link
Owner

Fix merged

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

No branches or pull requests

4 participants