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

feat: allow to configure php.user #45307

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,15 @@
*/
'config_is_read_only' => false,

/**
* In certain environments it is desired to set the config.php owner to
* something else than the user that is running the php process.
* In that case in order to determine the user that the php process uses,
* you can overwrite the user with this config flag for console.php and cron.php
* Defaults to ``''`` (empty string)
*/
'php.user' => '',

/**
* Logging
*/
Expand Down
8 changes: 7 additions & 1 deletion console.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ function exceptionHandler($exception) {
}

$user = posix_getuid();
$userNameArray = posix_getpwuid($user);
if ($userNameArray !== false) {
$userName = $userNameArray['name'];
}
$configUser = fileowner(OC::$configDir . 'config.php');
if ($user !== $configUser) {
$configuredUser = $config->getSystemValueString('php.user', '');
if ($user !== $configUser && $userName !== $configuredUser) {
szaimen marked this conversation as resolved.
Show resolved Hide resolved
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
echo "Another option is to configure 'php.user' in config.php which will overwrite this check.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as worded this is misleading, the option doesn't overwrite the check, it changes that the expected value of the check is.

I would go with something like

If the config file is not owned by the user running the webserver you can set the correct user by setting the 'php.user' option in your config.php

exit(1);
}

Expand Down
8 changes: 7 additions & 1 deletion cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@
}

$user = posix_getuid();
$userNameArray = posix_getpwuid($user);
if ($userNameArray !== false)) {

Check failure on line 134 in cron.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

ParseError

cron.php:134:32: ParseError: Syntax error, unexpected ')' on line 134 (see https://psalm.dev/173)
Fixed Show fixed Hide fixed
$userName = $userNameArray['name'];
}
$configUser = fileowner(OC::$configDir . 'config.php');
if ($user !== $configUser) {
$configuredUser = $config->getSystemValueString('php.user', '');
if ($user !== $configUser && $userName !== $configuredUser) {
echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
echo "Current user id: " . $user . PHP_EOL;
echo "Owner id of config.php: " . $configUser . PHP_EOL;
echo "Another option is to configure 'php.user' in config.php which will overwrite this check.";
exit(1);
}

Expand Down
Loading