-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
base: master
Are you sure you want to change the base?
Conversation
szaimen
commented
May 14, 2024
•
edited by susnux
Loading
edited by susnux
- Needs Revert: "Check datadirectory owner, not config owner." #45302
ec1b47e
to
4494e8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I insist that it should use the new config value instead of the config.php owner if the value is filled.
Is if php.user is empty, it checks that running user is the owner of config.php.
If php.user is filled, it checks that running user is the one in php.user.
See my previous change suggestion.
but we already get the user via posix_getuid or not? |
We do, and we want to check that it’s the correct one. |
all right, done! |
b3d21be
to
de2dbf5
Compare
Signed-off-by: Simon L <szaimen@e.mail.de>
de2dbf5
to
087ba07
Compare
Not completely happy about it but too much time was spend already, and it does fix the usecase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 otherwise
Signed-off-by: Simon L <szaimen@e.mail.de>
f49d3f0
to
a0d9dca
Compare
Signed-off-by: Simon L <szaimen@e.mail.de>
Signed-off-by: Simon L <szaimen@e.mail.de>
9281f6f
to
1afe55b
Compare
$configUser = fileowner(OC::$configDir . 'config.php'); | ||
if ($user !== $configUser) { | ||
$configuredUser = $config->getSystemValueString('php.user', ''); | ||
if ($user !== $configUser && $username !== null && $userName !== $configuredUser) { |
Check failure
Code scanning / Psalm
TypeDoesNotContainType Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is not true? How can I fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure? Documentation says it should return false
on failure: https://www.php.net/manual/en/function.posix-getpwuid.php
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."; |
There was a problem hiding this comment.
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
$configUser = fileowner(OC::$configDir . 'config.php'); | ||
if ($user !== $configUser) { | ||
$configuredUser = $config->getSystemValueString('php.user', ''); | ||
if ($user !== $configUser && $username !== null && $userName !== $configuredUser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check always needs to check for $configuredUser
if set. Also accepting $configUser
can lead to the very issue this is trying to prevent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like
$phpUser = $config->getSystemValueString('php.user', '');
if (!$phpUser) {
$userNameArray = posix_getpwuid($user);
if ($userNameArray !== false) {
$phpUser = $userNameArray['name'];
}
}
if ($user != $phpUser) {
maybe
$configUser = fileowner(OC::$configDir . 'config.php'); | ||
if ($user !== $configUser) { | ||
$configuredUser = $config->getSystemValueString('php.user', ''); | ||
if ($user !== $configUser && $username !== null && $userName !== $configuredUser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Looks like a reasonable solution, if there's not an easy way to just verify if we can write to the directory (as the user is not really relevant, just whether we have write access). I don't remember my PHP so well, but in Python I'd probably just try/except a file write as a test. |
The user is actually relevant (there is a separate check for checking write access to the data dir iirc). If an |
As I wrote in the internal chat: can someone please take over this PR? It looked like a simple change but got more and more complicated. I fear I currently do not have the capacity to finish this as I am busy with AIO and Enterprise-AIO. |