-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
#2183 Fixed .my.cnf messing up mysql connection + minor credential-leak fix #2387
Conversation
…ential-leak fix
It seems this code hasn't changed in the master branch, so it should be possible to pick this commit. |
Drush's temp files are cleaned up in a shutdown function. They are only exposed momentarily. I dont see this as a security risk. Many people actually like that Drush respects my.cnf. We need to cater to those people as well. |
Hi @weitzman , "They are only exposed momentarily" BTW, 'cleaned up in a shutdown function' assumes that drush will not crash, which is impossible to predict because as far as I know drush loads contrib and custom code as well. As for using .my.cnf: looking at the commits it seems that the --defaults-extra-file param was put there accidentally while it was just meant to hide credentials. |
I can't speak to the change from 'defaults-extra-file' to 'defaults-file' - that's unrelated to the security issue, so maybe it should be put in a different PR? However, setting the mode of the temporary file to 0700 seems like a good and simple way to improve the security of this file. Even though the file should only exist for a short time and be removed, in a shared environment it does present a potential security risk. Why not set the mode to be safe? :-) |
I'm fine with the mode change. The defaults-file change here is insufficient for reasons described above. |
What's your proposal @weitzman ? It's still kind of messy then, because you can also provide a hostname (and other options) in .my.cnf, so there will be no consistency around this without custom parsing of .my.cnf (or any other file in the mysql include chain for that matter), which seems hacky. I'll happily create a PR for that switch, but currently I don't see an obvious, consistent way of resolving this without skipping the whole .my.cnf thing. |
Having a command open such as Could this be written something private, like ~/.drush/tmp instead? |
To accomplish that, Just set the environment variable TEMP=$HOME/.drush/tmp (see drush_find_tmp()). This can fix other problems when multiple users on same server share caches.This could potentially become a default but then cleanup would become Drush's responsibility instead of re-using the OS temp dirs. |
I've looked into this a bit more, and at least in the versions I've tested, the file is owned by whatever process owner ran the drush command, with restrictive file permissions already in place.
|
@@ -20,8 +20,8 @@ public function creds($hide_password = TRUE) { | |||
password="{$this->db_spec['password']}" | |||
EOT; | |||
|
|||
$file = drush_save_data_to_temp_file($contents); | |||
$parameters['defaults-extra-file'] = $file; | |||
$file = drush_save_data_to_temp_file($contents, NULL, 0700); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this be 0600?
@CashWilliams, you're right about that one. Don't know why I put 700 Op 13 okt. 2016 16:24 schreef "Cash Williams" [email protected]:
|
@CashWilliams , you seem to be right about the default restrictive filemode.
|
After wrestling this with problem, I discovered some strange behavior in MySQL:
The manual says this is for Given this, I don't see how using the @weitzman, can you say more about what users like about pulling the password from |
@dylantack , See commit above. BTW, it doesn't seem entirely true what you say; if you specify user and password (so both, not only password) in ~/.my.cnf, that combo will be used and will work. In that case the whole drupal credentials-combo is disregarded. This might provide a workaround for people who use drush 8.x . |
I have to agree with the users that are saying we should switch this to |
I fixed this to use defaults-file in master branch. Will make a new release of master very soon. It should be fully released in a couple months so I'm not so inclined to back port. Some people depend on current behavior so back porting is tricksy. |
ok.. |
Having encountered this problem and looked at the various options available, I agree that drush should be using --defaults-file and not defaults-extra-file. Please can we make this change permanent? |
Please merge this PR, it fixes the problem where .my.cnf is used to connect to mysql.
Furthermore, the filemode-option in drush_save_data_to_temp_file() provides a way to prevent credential leakage, since that seemed to be the whole point of using the --defaults-extra-file param.
Prior to this commit the sql credentials were exposed in the open-to-anyone /tmp folder.
Created this on the 8.x branch, but maybe it's just possible to merge this 1:1 to the master branch (didn't check).