Skip to content
Snippets Groups Projects

Issue #3432476 add ConsoleUserValidator

Merged Ted Bowman requested to merge issue/automatic_updates-3432476:3432476-warn-root into 3.0.x
1 unresolved thread
1 file
+ 5
1
Compare changes
  • Side-by-side
  • Inline
@@ -10,6 +10,10 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Validates that the `auto-update` script is not run as the root user.
*
* We add this warning to the StatusCheckEvent and PreCreateEvent events
* instead of directly in the `auto-update` script to ensure that the warning
* is surfaced to the status report page along with other warnings and errors.
*
* @todo Remove this validator in favor of exiting the `auto-update` script as
* early as possible if run as root in https://www.drupal.org/i/3432496.
*/
@@ -32,7 +36,7 @@ class ConsoleUserValidator implements EventSubscriberInterface {
* The stage event.
*/
public function validateConsoleUser(StatusCheckEvent|PreCreateEvent $event) {
if ($event->stage instanceof ConsoleUpdateStage && function_exists('posix_getuid') && posix_getuid() === 0) {
if (PHP_SAPI === 'cli' && $event->stage instanceof ConsoleUpdateStage && function_exists('posix_getuid') && posix_getuid() === 0) {
$event->addWarning([t('The `auto-update` script should not be run as the root user. Please run it as a less privileged user. In 3.1.0 if this script is run as the root user updates will not be preformed.')]);
}
}
Loading