I set the SETGID bit on files directory so that any new directories or files created by drupal/php inside sites/default/files will take the group ownership of parent directory i.e here files. But I figured out Drupal clears/unset the SETGID bit for newly created directories like css, php, js etc.

I checked with a simple script if it is an issue with PHP-FPM, but it was not. I think Drupal does chmod in his side while creating new dirs which turns out to SETGID bit to be unset automatically.

I found there is one SO question related to Wordpress ( https://superuser.com/questions/1271465/force-wordpress-php-to-respect-setgid-bit-when-creating-new-files-directories )

How to reproduce ?

chown :deploy web/sites/default/files
chmod g+s web/sites/default/files

ls -al web/sites/default/files

drwxrwxr-x    2 www-data deploy        4096 Nov  7 08:41 css
drwxrwxr-x    2 www-data deploy        4096 Nov  7 08:32 js
drwxrwxrwx    3 www-data deploy        4096 Nov  7 08:32 php

Expected result (x bit should be replaced by s for group)

ls -al web/sites/default/files

drwxrwsr-x    2 www-data deploy        4096 Nov  7 08:41 css
drwxrwsr-x    2 www-data deploy        4096 Nov  7 08:32 js
drwxrwsrwx    3 www-data deploy        4096 Nov  7 08:32 php

Is it an issue of Drupal 8 or a knowing behavior ? Any workaround for this issue ?

Update-1

However I found something inside settings.php regarding chmod. I tried to uncomment and set my required permission like 2770 (Where 2 is SETGID bit) but it doesn't help.

/**
 * Default mode for directories and files written by Drupal.
 *
 * Value should be in PHP Octal Notation, with leading zero.
 */
  $settings['file_chmod_directory'] = 02770;
# $settings['file_chmod_file'] = 0664;

It seems like Drupal 7 obeys setgid rule ( https://www.drupal.org/docs/7/install/step-3-create-settingsphp-and-the-files-directory ) But why doesn't work for me. Doesn't it work for Drupal 8 ?

Update-2

I found a strange behaviour setgid works for the directory Php/twig i.e all the dir/files inside php directory owned by group deploy. But inside css and js dir it doesn't obey the rule.

  • So you are setting the group sticky bit, but the directories in sites/default/files already exist? – mpdonadio Nov 7 at 20:39
  • When I execute composer install a script triggers and creates the files dir then chmod 2770 on files. Then when I browse drupal sites it creates some temporary dirs like php, js, css etc which doesn't have the SETGID bit set on it. So @mpdonadio to answer your question directories inside sites/default/files doesn't exist while I set sticky bit on files – SkyRar Nov 7 at 20:43
  • The leading value has to be zero because PHP's chmod doesn't support setuid, setgid, etc – Clive Nov 8 at 14:35
  • @Clive I also checked on the PHP page, It was written in the comment that we can set SETUID/SETGID using octal notation like 02755 . We have to add a 0 before it. Also I examined it. So I don't think what you told is correct . Php does support SETUID or SETGID. – SkyRar Nov 8 at 15:18
  • Oh ok I'm obviously mistaken - but in that case it should just work, Drupal just proxies its chmod requests through to FileSystem::chmod, which uses PHP's chmod to make the change. If it was me I'd be setting a breakpoint in that function and comparing the inputs at that point to the working vanilla PHP version you've got – Clive Nov 8 at 20:16

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.