Chmod values are currently hard coded in includes/file.inc and modules/simpletest/tests/file.test. The defaults might work on many setups, but on a setgid system where apache is given write access using the setgid directory group the hard coded values cause serious breakage (they remove the necessary setgid bit so created sub dirs have the wrong group).
Attached is a patch which makes these options configurable by setting a few defines for the used modes, replacing the hard coded values with these defines and making these defines available via default.settings.php.
For the chmod values I've used the current values*, but I would suggest to set the last octal to 0 by default. A permission of 0775 just doesn't make sense. You either give write permission to the owner or the group, the world read permission is superfluos. (Even 0777 makes more sense if the web server runs as nobody and needs world write access. So depending on the setup directory write permissions are 0700, 0770, 02770 or 0777, but never 0775.)
* One exception, I did change the 0444 directory permission to 0555. This should not cause any breakage.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | drupal.chmod_config.patch | 9.05 KB | leonardjo |
| #3 | drupal.chmod_config.patch | 9.2 KB | leonardjo |
| drupal.chmod_config.patch | 8.33 KB | leonardjo |
Comments
Comment #1
lilou commentedComment #3
leonardjo commentedPatch applies fine if you move it inside the drupal directory and use
$patch -p1 < drupal.chmod_config.patch
(the patch uses drupal/ instead of drupal-7.0/ as the base directory.)
However, I realized that on old installations the defines are only added in the default.settings.php but not necessarily set in settings.php.
To avoid breakage if the defines aren't set on an old installation the chmod values should be defined conditionally in file.inc and file.test.
Attached patch uses drupal-7.0/ as the base path and adds the aforementioned conditional defines so old installations can safely apply it without having to make changes to the config.
Still I would suggest to change the last octal in every chmod value to 0 before the patch is applied.
Please let me know if you want a different path shift or just check the patch for the base path and change patch's strip level (-p #) if you can't get it applied.
Comment #4
leonardjo commentedI just figured out patches need to be made from inside the base directory. What a shame diff(1) doesn't work like that so you have to hand edit patches :S
Anyway, attached the last patch fixed for the base path.
Comment #5
leonardjo commenteddrupal.chmod_config.patch queued for re-testing.
Comment #6
leonardjo commented#3: drupal.chmod_config.patch queued for re-testing.
Comment #7
leonardjo commented#3: drupal.chmod_config.patch queued for re-testing.
Comment #9
leonardjo commentedI cannot reproduce the failures in Authorize API the test system finds on a fresh Drupal-7 with this patch applied.
Could someone have a look at this patch and the errors? Can you please point out what needs to be fixed?
Comment #10
bfroehle commentedNow try doing a command which involves the authorize.php file, for example install a new module using the admin interface. (Note you'll have to be in an environment where the httpd user doesn't have write access to the files to trigger authorize.php).
Comment #11
damien tournoud commentedAll of those permissions are configurable via variables. The only one that is hardcoded is the read-only 444 on
.htaccess. I don't see the point in making this one configurable.Comment #12
damien tournoud commentedComment #13
leonardjo commented#4: drupal.chmod_config.patch queued for re-testing.
Comment #14
bfroehle commentedleonardjo: To change the defaults, you can already have put the following lines in your
settings.php:Comment #15
coderintherye commentedAssuming #11 kills the reasoning for the patch, I'd like to change this into a feature request for the documentation team to work on a handbook page explaining how to set these values. Like the OP I had trouble with permissions on a couple of hosts and had to play around with some of the chmod values directly at first because I was not sure where to set them.
Comment #16
leonardjo commentedA bit of a doh moment there. I didn't realize that variable_get takes the values from the db and uses the second argument as a fall back. (If only I could find where to set them.) Still...
These kind of basic file system permission variables belong in a config file, not in the database. If I pick up the database and drop it on another machine all I should have to do is edit 2 lines in a config file not have to fiddle with the contents of the database. These are local configuration options that are somewhat independent of the actual installation so it's kind of counter intuitive to me to store them in the database. (A bit like storing the database credentials in the database ;) But I suppose that's more a matter of opinion so do as you see fit.
Comment #17
leonardjo commentedAh right, in the config file itself. That indeed solves my problem.
And yes, that might be documented a bit more prominently :-) .
Comment #19
bfroehle commentedFrom post #15:
Comment #20
leonardjo commentedCould you give a simple scenario (which files/dirs to make inaccessible and what action to perform)? I still don't see how this patch could cause breakage there (as all it does is add some defines and use those instead of hard coded values).
Sorry for requeuing the test. I overlooked your comments (perhaps Firefox loads from cache when recreating a session and they just weren't there) so I thought that maybe the tests "got fixed" (as I see 2 failures in drupal_render() on a pristine installation which I didn't see on the testing machine I assumed these tests are in as much flux as HEAD is).
Just a thought, it might be useful if people could obsolote their own patches in these bug reports. I put in version #2, then realized that patches need to be -p0 from inside the installation root so I added #3, only to have #2 go through testing as there was no way to indicate only the latest version needed to be tested.
Closing out this report. Can any of you open an issue for the documentation or do you want me to do that?
Comment #21
bfroehle commentedThis issue will become the documentation request for configuring
in
settings.phpComment #22
leonardjo commentedJust put
in settings.default.php. That should make it much more obvious. Any mention in the documentation is an added bonus.
Comment #23
coderintherye commentedRight I agree, this should have a comment in settings.php as well documentation in the handbook. I could write a documentation page if no one else wants to.
Comment #24
jhodgdonDo we document every possible setting that someone could put in settings.php inside settings.default.php, or are they generally documented in the on-line drupal.org handbook only? I do not know the answer to that question.
If we only have some possible settings in settings.php then I am not sure that this is commonly enough needed to put there, and maybe it should just go into the Handbook.
Any thoughts on that?
Comment #25
leonardjo commentedFile permissions for writable files are a basic configuration option that you _need_ to set at installation time. They are about as basic as database credentials, so imo those options should be put in settings.default.php.
Comment #26
jhodgdonRight. My question is more about how often people need to overwrite the default chmod settings. If it's a rare thing to need to override, and we aren't documenting every possible thing you can override in default.settings.php, then we should put this along with all the other stuff we're documenting on a hypothetical doc page on drupal.org (if such a thing exists) and add a note in default.settings.php pointing to that page (if there is one). We should also consider moving other rarely-needed settings out of default.settings.php and into that doc page.
If our goal is to document all possiblities in default.settings.php, then that's a different story.
I still don't know what the answer to that question is.
Comment #27
bfroehle commentedI think that a note in the
default.settings.phpfile with a link to a documentation page on drupal.org of advanced settings would be appropriate. Users who require some massaging of default file permissions are going to know this and will likely read the settings file to find out how it is possible.Comment #28
coderintherye commentedYes, this is the same sentiment I have. Regarding the previous question of how common this need is, I don't think we could really tell unless we did a proactive study of all the major hosts to see if permissions needed to be changed to install on them (as I don't think relying on self-reporting from users would be enough to establish the need).
Comment #29
mlncn commentedSubscribe and bump. Not sure what to propose as language etc. this just looks like the kind of thing that will bite me at some point, so tracking here until it gets documented in settings.php ;-)
Comment #30
niklp commentedBumping this because I just spent two days trying to get a decent permissions setup only to find that setgid isn't honoured out of the box, and I still don't know where to look to see if this config will work on various versions of Drupal!
Comment #31
erikwebb commentedComment #38
kim.pepperClosing as outdated. Please re-open if this is still relevant.