Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdog warnings about failed services file write #3481

Closed
neclimdul opened this issue Aug 9, 2017 · 7 comments
Closed

Watchdog warnings about failed services file write #3481

neclimdul opened this issue Aug 9, 2017 · 7 comments

Comments

@neclimdul
Copy link
Contributor

Problem/Motivation

Watchdog warnings on cron run and other commands when vendor permissions are hardened.

How to reproduce

  1. Install drupal console as part of a Drupal 8 installation.
  2. Run the following commands:
$ sudo chown -R root:root vendor
$ ./vendor/bin/drupal 

Drupal 8.3.x
Console 1.0.0

Warning: file_put_contents(/var/www/html/vendor/drupal/console/<uuid>-console.services.yml): failed to open stream: Permission denied in Drupal\Console\Bootstrap\AddServicesCompilerPass->process() (line 156 of /var/www/html/vendor/drupal/console/src/Bootstrap/AddServicesCompilerPass.php)
#0 /var/www/html/web/core/includes/bootstrap.inc(566): _drupal_error_handler_real(2, 'file_put_conten...', '/var/www/html/v...', 156, Array)
#1 [internal function]: _drupal_error_handler(2, 'file_put_conten...', '/var/www/html/v...', 156, Array)
#2 /var/www/html/vendor/drupal/console/src/Bootstrap/AddServicesCompilerPass.php(156): file_put_contents('/var/www/html/v...', 'services:\n con...')
#3 /var/www/html/vendor/symfony/dependency-injection/Compiler/Compiler.php(104): Drupal\Console\Bootstrap\AddServicesCompilerPass->process(Object(Drupal\Core\DependencyInjection\ContainerBuilder))
#4 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(598): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Drupal\Core\DependencyInjection\ContainerBuilder))
#5 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(1299): Symfony\Component\DependencyInjection\ContainerBuilder->compile()
#6 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(883): Drupal\Core\DrupalKernel->compileContainer()
#7 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(1158): Drupal\Core\DrupalKernel->initializeContainer()
#8 /var/www/html/vendor/drupal/console/src/Bootstrap/Drupal.php(128): Drupal\Core\DrupalKernel->rebuildContainer()
#9 /var/www/html/vendor/drupal/console/bin/drupal.php(78): Drupal\Console\Bootstrap\Drupal->boot() #10 /var/www/html/vendor/drupal/console/bin/drupal(4): require('/var/www/html/v...')
#11 {main}.

Solution

I see a couple possible solutions.

  1. Hide the error.
  2. Write to another location that we know is writable. ~/.console/ or the like.
  3. Write to the secure Drupal storage for the site.

Seems like writing to ~/.console would be the best option but I don't know all the requirements around this piece of code.

@jmolivas
Copy link
Member

jmolivas commented Aug 9, 2017

I think moving the storage directory to ~/.console/uuid/ may work

@jmolivas
Copy link
Member

@neclimdul I am testing to use instead this:

\Drupal::service('stream_wrapper.temporary')->getDirectoryPath();

@neclimdul
Copy link
Contributor Author

That could work, very similar to my 3 suggestion. They both could have the reverse problem of causing errors for users that are not the web user. However doing that can be problematic and only works for some commands since Drupal always assumes it can write to certain locations like this.

Testing now.

@jmolivas
Copy link
Member

@neclimdul I can send a PR so you can try a patch

@neclimdul
Copy link
Contributor Author

PR would be appreciated so I can confirm the patch I threw together is doing the same thing :)

@neclimdul
Copy link
Contributor Author

Different white space but same patch. Works for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants