Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
automatic_updates
Merge requests
!1040
Issue
#3432476
add ConsoleUserValidator
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3432476
add ConsoleUserValidator
issue/automatic_updates-3432476:3432476-warn-root
into
3.0.x
Overview
2
Commits
3
Pipelines
5
Changes
1
1 unresolved thread
Hide all comments
Merged
Ted Bowman
requested to merge
issue/automatic_updates-3432476:3432476-warn-root
into
3.0.x
1 year ago
Overview
2
Commits
3
Pipelines
5
Changes
1
1 unresolved thread
Hide all comments
Expand
Closes
#3432476
0
0
Merge request reports
Viewing commit
a588bfb0
Prev
Next
Show latest version
1 file
+
40
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
a588bfb0
add ConsoleUserValidator
· a588bfb0
Ted Bowman
authored
1 year ago
src/Validator/ConsoleUserValidator.php
0 → 100644
+
40
−
0
Options
<?php
namespace
Drupal\automatic_updates\Validator
;
use
Drupal\automatic_updates
\ConsoleUpdateStage
;
use
Drupal\package_manager
\Event\PreCreateEvent
;
use
Drupal\package_manager
\Event\StatusCheckEvent
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* Validates that the `auto-update` script is not run as the root user.
*
* @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.
*/
class
ConsoleUserValidator
implements
EventSubscriberInterface
{
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
():
array
{
return
[
StatusCheckEvent
::
class
=>
[
'validateConsoleUser'
],
PreCreateEvent
::
class
=>
[
'validateConsoleUser'
],
];
}
/**
* Adds a warning if the `auto-update` script is run as the root user.
*
* @param \Drupal\package_manager\Event\StatusCheckEvent|\Drupal\package_manager\Event\PreCreateEvent $event
* The stage event.
*/
public
function
validateConsoleUser
(
StatusCheckEvent
|
PreCreateEvent
$event
)
{
if
(
$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