version: 0.4-beta2

Currently post provision-verify, it's possible to end up with a local.settings.php owned by aegir.aegir and with inappropriate permissions like 600. Obviously this would cause anything in local.settings.php to be ignored since the web server user can't read the file. Worse, you could end up with permissions like 666 which violate security best practices.

During site verification, if local.settings.php exists, it should be chgrp'd to the web server group and chmod'd 440.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anarcat’s picture

Status: Active » Closed (won't fix)

I disagree - the local.settings.php is managed by the user, so the user should make sure the permissions are OK. Keep in mind that local.settings.php could be created with an ownership that would make aegir incapable of changing the mode (ie. if local.settings.php, which would seem to be a logical use for it), which would then make provision-verify fail.

I would rather leave this up to the user. No?

bwood’s picture

Miguel encouraged me to post here: http://community.aegirproject.org/node/362

I can see your point, but from the server admin's perspective: Aegir demands a non-standard drupal site development process i.e. user can't write to settings.php. Work around is that the user writes to local.settings.php. Bad perms on local.settings.php could compromise security. I agree that the user should set correct perms, but I was thinking that, as is the case with settings.php on a site import (IIRC), Aegir could set correct group/perms on local.settings.php if it is able. I was imagining:

pseudo code:

if (file_exists($locsettings)) {
  if (is_writable($locsettings)) {
    //chgrp, chmod
  }
  else {
    //warn: local.settings.php exists but is not writeable by the aegir user 
  }
}

I can continue to manage the permissions on this file externally to Aegir if you don't think this is doable/appropriate.

anarcat’s picture

Status: Closed (won't fix) » Active

I guess I see the point, thanks for updating this.

I am not sure I understand why people would have security-sensitive stuff in local.settings.php when the DB password is already in the settings.php, but I guess it can happen.

We can probably fix perms on verify, but note that if the user screws up the permissions when they edit the file, there's always going to be a window when the file will be vulnerable, so this may create a false sense of security..

crea’s picture

Subscribing

crea’s picture

Category: feature » bug

I observe the following behavior: after migration local.settings.php group ownership resets from www-data to aegir, leading to webserver not being able to access the file, so local settings stop working after migration. I consider this a bug, not a feature

crea’s picture

What happens here: tar extracts files ignoring ownership, so group ownership resets to running user (aegir).
Would making tar keep ownership add any security risks ?
I.e. change to
$command = 'gunzip -c %s | tar --same-owner -p -x -f -';

crea’s picture

Title: Provision-verify should manage group and permissions of local.settings.php » Local.settings.php can stop working due to file ownership/permissions
crea’s picture

Priority: Normal » Major
crea’s picture

The workaround is to set local.settings.php world-readable, but it adds security implications (you can't place secure credentials there, for example)

Robin Millette’s picture

subbing

Steven Jones’s picture

Version: 6.x-0.4-alpha3 » 6.x-1.2
Assigned: Unassigned » Steven Jones
Priority: Major » Critical

We have this happening on some aegir installs of ours, but not others. The local.settings.php becomes owned by aegir:aegir and so the web server can't read it, which screws things up nicely. Needs some investigation.

omega8cc’s picture

I think it is rather docs candidate and admin's responsibility to create this file world-readable, as there are no passwords etc stored probably, so it doesn't matter if the file ownership will change.

However, I never experienced that, even for sites cloned/migrated - Aegir never touched this file for me and it was always moved as-is.

gmania’s picture

Seeing this problem on our install as well. Particularly frustrating when permissions get changed while migrating a site and thus botching the whole genius of Aegir.

Setting world readable is not really an option, as this has security implications if things like API keys for external services (Facebook, AWS, etc) are stored in local.settings.php It seems to me to be the appropriate place to store stuff like that, but if anyone has any suggestions as to where to store that sort of info, I'm always open to ideas!

gmania’s picture

Here's a quick fix:

Add the following code to a MYFILE.drush.inc file in /var/aegir/.drush

function drush_MYFILE_post_provision_deploy() {
  //Make the local.settings.php file readable by the webserver
    provision_file()->chgrp(d()->site_path . '/local.settings.php', d('@server_master')->web_group, TRUE)
      ->succeed('Changed group ownership of file @path to @gid')
      ->fail('Could not change group ownership of file @path to @gid');
}

Tested and working with Apache.

If we're interested in updating Provision to include this code, should be as simple as adding this code somewhere in deploy.provision.inc

anarcat’s picture

Priority: Critical » Major
Status: Active » Needs work

I think this would make sense, *if* this will not fail if local.settings.php is absent or if aegir can't change the perms. Can you roll out a patch that would do that?

Thanks.

Steven Jones’s picture

Version: 6.x-1.2 » 6.x-1.6

Sure.

Steven Jones’s picture

Version: 6.x-1.6 » 6.x-1.7
Assigned: Steven Jones » Unassigned
Status: Needs work » Needs review
FileSize
931 bytes

Here's a patch, doesn't try to do anything with the permissions, but keeps the group correct, so the end user is free to set the permissions as they need.

omega8cc’s picture

Or we could create an empty local.settings.php file by default, with correct ownership/group and permissions and then always check/set them only in function provision_drupal_drush_exit(), so only once on successful verify. Note that attached example patch is for 6.x-2.x

omega8cc’s picture

The patch from #18 is designed to break the site, as it never sets correct gid when the file exists. Fixed patch for 6.x-2.x attached.

Steven Jones’s picture

Status: Needs review » Needs work

Thanks for the patch, but I think that we should make sure that the permissions are at least enough to not cause any errors, but we shouldn't force the permissions to 0440 unless we have good reason to?

helmo’s picture

settings.php gets 0440.
As that was done as a security measure why not for local.settings.php as well?

The reason against making it read-only it is convenience ... ?

Steven Jones’s picture

Well, local.settings.php is supposed to not really be managed by Aegir at all, it's just for people to pop their special config in anyway. So we should aim to ensure that it has the permissions that we need at least, but we shouldn't then start taking whatever permissions it has away if people have set them like that.

SocialNicheGuru’s picture

Issue summary: View changes

thanks. this is nice.

I agree that having it be the same settings as settings.php is a good idea. As an admin if I want to go in and edit, I just need to take the extra step.

Up until now I have constantly had to go in and do the chown/chmod dance. Thanks for this patch.

helmo’s picture

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

Still applies to 7.x-3.x and still sounds reasonable to add... Any objections left?

SocialNicheGuru’s picture

Status: Needs work » Reviewed & tested by the community

the patch works for me

helmo’s picture

The chmod and chgrp part was identical between the if and else blocks... so this new patch simplifies it a bit.

Committing.

  • helmo committed 9c89864 on 7.x-3.x authored by Steven Jones
    Issue #1066000 by omega8cc, Steven Jones, helmo: Local.settings.php can...
helmo’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Aegir 3.2

Status: Fixed » Closed (fixed)

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