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
Commits
73009dfd
Commit
73009dfd
authored
11 months ago
by
Ted Bowman
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3432476
: Warn if auto-update script is running as root
parent
78052119
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1040
Issue #3432476 add ConsoleUserValidator
Pipeline
#130710
passed with warnings
11 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/src/ConverterCommand.php
+2
-0
2 additions, 0 deletions
scripts/src/ConverterCommand.php
src/Validator/ConsoleUserValidator.php
+44
-0
44 additions, 0 deletions
src/Validator/ConsoleUserValidator.php
with
46 additions
and
0 deletions
scripts/src/ConverterCommand.php
+
2
−
0
View file @
73009dfd
...
...
@@ -311,6 +311,8 @@ class ConverterCommand extends Command {
// https://drupal.org/i/3347937.
'scripts'
,
'dictionary.txt'
,
// @todo Remove in https://www.drupal.org/i/3432496.
'src/Validator/ConsoleUserValidator.php'
,
];
$removals
=
array_map
(
function
(
$path
)
use
(
$core_module_path
)
{
return
"
$core_module_path
/
$path
"
;
...
...
This diff is collapsed.
Click to expand it.
src/Validator/ConsoleUserValidator.php
0 → 100644
+
44
−
0
View file @
73009dfd
<?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.
*
* 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.
*/
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
(
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.'
)]);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment