This could possibly be a support request depending on if you're willing to add new features to 6.x-2.x.

There are a lot of organizations who have security policies that involve changing database passwords. I'm not entirely sure how to go about doing this, but it would be helpful to have an action that does the following:

1) Create a new database user/pass
2) Rewrite settings.php for the site
3) Remove the old database user for the site

Possibly in an experimental, disabled-by-default extension?

If this isn't something that could be included in Aegir, any information that you could provide to help me do this would be extremely helpful.

Comments

helmo’s picture

Would be nice to have.

It relates a bit to: #1132512: [meta] Manage databases as separate entities

It could also start as something in http://drupal.org/project/hosting_tasks_extra

cweagans’s picture

Any ideas about approach? I'm not sure how to make it happen.

cweagans’s picture

I mean, one way to do it is to have an action that does this:

For running the action on example.com:

* Migrate example.com to example.com.tmp
* Clone example.com.tmp to example.com
* Delete example.com.tmp

I'm not sure how well this would work in practice though, and it seems to be a pretty roundabout way of resetting a database password.

ergonlogic’s picture

Provision_Service_db_mysql::grant and Provision_Service_db_mysql::revoke methods already exist. Since site db credentials are stored in the vhost and the site drushrc.php, those are where we'd need a re-write, not settings.php.

cweagans’s picture

I see all of these bits that will be useful, but I'm not quite understanding how they fit together:

- provision_password() will help with generating new password
- Provision_Service_db_mysql::revoke will help with revoking the database credentials
- Provision_Service_db_mysql::grant will help with granting new ones

From a site action, how do I update the site drushrc.php/virtualhost with those new credentials?

ergonlogic’s picture

You probably want something like:

$config = new Provision_Config_Drushrc_Site(d()->name);
$config->db_passwd = $new_password;
$config->write();

With that, I think you can just verify the site to have the vhost re-created with the new credentials.

cweagans’s picture

Okay, I think that's enough to get me started. Thanks!

Should I write this as a hosting/provision patch/separate submodule? Or should this go into a contrib project?

ergonlogic’s picture

@cweagans, I think helmo's suggestion in #1 is good. tasks_extra is becoming our incubator for potential additions to aegir core .

anarcat’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

also, keep in mind this actually happens at every migrate.

i don't think we should have this that late in the 2.x release cycle, but it's welcome in contrib or 3.x.

cweagans’s picture

Yes, but you can't migrate the site to the same platform to change the database password :)

Also, I'm having a really hard time getting this to work. ergonlogic or anarcat, could we talk in IRC sometime? I have code written, and it'll definitely be open sourced - I'd love to have your input on where I'm going wrong if you happen to have some time.

ergonlogic’s picture

Status: Active » Postponed (maintainer needs more info)

@cweagans, I know you'd posted a gist or something with some code snippets at one point. Posting a patch to this issue would probably make things simpler though.

We'll be on IRC this week too.

cweagans’s picture

My complete provision_change_site_password.drush.inc is here: https://gist.github.com/cweagans/2926c8f7953d35291ec1

(I'm building it as a separate module, but I'll move it into a patch in provision_tasks_extra at some point, and possibly into Aegir 3.x at some point)

anarcat’s picture

Status: Postponed (maintainer needs more info) » Needs review

okay, so what's not working in that command?

cweagans’s picture

As far as I can tell, it's updating the MySQL password, but it's not regenerating the Apache config appropriately, so after this command is run, the site has one password, and the database has another.

helmo’s picture

I think I got it working....
https://gist.github.com/helmo/a564e718715787a0287f/revisions

diff --git a/provision_change_site_password.drush.inc b/provision_change_site_password.drush.inc
index 567e0d7..68c37ad 100644
--- a/provision_change_site_password.drush.inc
+++ b/provision_change_site_password.drush.inc
@@ -54,6 +54,9 @@ function drush_provision_change_site_password() {
       }
     }
 
+    // save new password to our context, other code needs it to e.d. render the vhost config
+    drush_set_option('db_passwd', $new_password, 'site');
+
     // Update the site context and trigger a verify to rewrite all related
     // Apache virtualhosts.
     $config = new Provision_Config_Drushrc_Site(d()->name);

A comment in generate_site_credentials() already mentions that this is not the best way to handle variables....

cweagans’s picture

Status: Needs review » Fixed

Thanks, helmo!! That works great - I'll go ahead and package this up.

anarcat’s picture

Status: Fixed » Postponed

let's mark this as postponed until we have a link to a contrib module here :)

helmo’s picture

Project: Hosting » Provision tasks extra
Version: 7.x-3.x-dev » 6.x-2.x-dev
Status: Postponed » Active

Moving to the provision_tasks_extra queue as per @cweagans in #12.

I doubt there would be much need for an addition to hosting_tasks_extra, or would anyone like to do this from the frontend?

cweagans’s picture

I'll add a configuration page to hosting_tasks_extra to rotate passwords every $interval, and a hook_cron to kick it off.

ergonlogic’s picture

Implementing a queue would probably be the best way forward to schedule regular triggering of this.

helmo’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new3 KB

This saved me again today ... I used this to fix some db privilege issues after a DNS name change, which messed up some grants.

Together with #2175595-1: Generate drush groups I was able to quickly reset all passwords on a server.

Here's a patch based on the gist .. only with minor cleanup.

* Is the filename OK?
* We could make the maintenance mode optional .. I temporarily disabled it to avoid errors during my recovery.

cweagans’s picture

Looks like this has been committed. Can we close it? I'm using this in production for a client for automatic password rotations every 90 days, and it seems to be working well.

helmo’s picture

Status: Needs review » Fixed

I see that I accidentally committed this in fd9a94eea65015780d98c34b00fab4b4cbabe9a8 "Fix hook_drush_load() check for http_basic_auth"

Code still seems ok, so lets leave it at that. We can always open a follow-up issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.