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

Comments

Projects
None yet
4 participants
@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

This comment has been minimized.

Copy link
Owner

jschneier commented Feb 1, 2016

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Owner

jschneier commented Feb 1, 2016

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

This comment has been minimized.

Copy link

begincalendar commented May 12, 2016

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- referenced this issue Oct 9, 2016

Closed

SFTP problem #199

sallyruthstruik added a commit to sallyruthstruik/django-storages that referenced this issue Jun 2, 2017

@sallyruthstruik

This comment has been minimized.

Copy link
Contributor

sallyruthstruik commented Jun 2, 2017

Pull request with fix: #325

jschneier added a commit that referenced this issue Jun 2, 2017

@jschneier

This comment has been minimized.

Copy link
Owner

jschneier commented Jun 2, 2017

Fix merged

@pyup-bot pyup-bot referenced this issue Jul 18, 2017

Closed

Initial Update #42

@pyup-bot pyup-bot referenced this issue Oct 3, 2017

Merged

Initial Update #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.