Problem/Motivation
When installing Drupal from the shell and configure through the site (or the other way around) the configuration directories are not writable for either the shell user or the web user.
Step to reproduce
Drupal then Drush
Install drupal site through web browser http://drupal.d8/core/install.php?langcode=en&profile=standard
$ drush status
mkdir(): Permission denied MTimeProtectedFastFileStorage.php:150 [warning]
chmod(): Permission denied MTimeProtectedFastFileStorage.php:152 [warning]
file_put_contents(/.../sites/default/files/php/service_container/.htaccess): failed to open [warning]
stream: Permission denied MTimeProtectedFastFileStorage.php:154
Drush then Drupal
$ drush site-install --yes
$ drush @drupal.d8 uli
The site shows error http://drupal.d8/index.php/user/1/edit?pass-reset-token=…
Warning: mkdir(): Permission denied in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->ensureDirectory() (line 150 of core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php).
Warning: chmod(): Permission denied in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->ensureDirectory() (line 152 of core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php).
Warning: file_put_contents(/Users/clemens/Sites/drupal/d8/www/sites/default/files/php/service_container/.htaccess): failed to open stream: Permission denied in Drupal\Component\PhpStorage\MTimeProtectedFastFileStorage->ensureDirectory() (line 154 of core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php).
See also drush #1899842: MTimeProtected Directory Grief
Proposed resolution
By following the umask approach done in twig thus relaxing on the permissions by respecting the current UMASK we allow sysadmins and scripts to work together with the webserver again.