-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Make logfile's mode configurable. #8282
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
Conversation
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.
Thanks for your contribution @Cybso. Makes sense to me to have an option for this. 👍
Technically we don’t support that Cron and Webserver is run by different users. Our documentation states this already because it could then cause the files in the data directory having the wrong permission. The same as what happened here. And also adding just more settings to „fix“ this flaw is also something we should avoid to not fragment the different setups and make it even harder why something happened. |
@MorrisJobke I understand your point here. However, in that case the detection of the webserver user is defective, because I simply cannot execute cron.php as www-data if the nextcloud installation (precisly: config.php) is owned by another user than www-data:
config.php is not owned (and not even writable) by the webserver user in my setup for security reasons(*). So maybe a better fix would be an option to suppress this check when being executed via CLI. Nextcloud supports non-writable config files via config_is_read_only = true, so I think for completeness it should also support that this file is not owned by www-data and that cron.php might not be able to detect the webserver user for sure. I'll workaround this by executing the cron job via an HTTP request in future. But I think this problem should be discussed further. (*): The security policy of my company does not allow any executable or includable files within the document root to be writable by the webserver when not absolutly needed (e.g. while doing updates). This could open an attack vector where a code injection exploit could be used to append PHP code to, lets say, config.php that sends login data back to the attackers server - and thus receive admin credentials in clear text. |
Sadly we do not allow this setup. Because we need to write the version number to this and when you want to upgrade via the web the config.php needs to be writable.
Have you enabled this setting? I thought we then don't check the config.php permissions.
We are aware of this and plan to fix this by putting the config into another file format and just parse this then But it is sadly a long road to go. |
I know, the ownership of the installation is changed to 'www-data' before updates or app installations and secured again when the changes are finished. No problem so far (besides cron.php)...
The setting is ignored in cron.php. But maybe the smartest solution to this problems would be to check for this setting and skip the process owner check if it has been enabled. Should I commit it into this PR or create a new branch for that change?
|
When 'config_is_read_only' has been enabled it is possible that not only the config.php file is not writable by the webserver, but also that it isn't owned by the webserver's uid at all. So when enabled and executed in CLI mode cron.php should not compare the owner of cron.php with the process owner as it may lead to wrong positive as well as wrong negative results. Refers to discussion in #8282. Signed-off-by: Roland Tapken <roland@bitarbeiter.net>
Besides this, @Cybso, is this change still relevant? From the comments it sounds like a fix for a very specific setup that we actually don't support. |
@ChristophWurst Although this particular case is likely to be quite an exception, I still think the patch should be merged. Because if the configuration is read-only, it does not matter to cron.php who owns the config.php. |
Oh wait, I spoke of the patch in ded52ab The original patch is obsolete. |
Yes, it does. Because cron jobs might want to change system configuration and thus they have to be able to write to that file. |
@ChristophWurst cron.php should not try to change the system configuration if 'config_is_read_only' is set
|
Oh, I'm sorry, I totally missed that part.
Then this sounds like the more sane way to go where we just fix the behavior of our existing configuration options instead of adding a new one 👍 |
The problem with this is, that the cron job could now be run by a user who cannot read the config file as well. Also this would allow to run cron with a user that has more permissions than the web server user and if this cron jobs writes a file to the file system it will be unwritable by the web server. :/ So there needs to be then another way to verify the owner. Maybe the nextcloud log file? But what if logging to the systemd journal is configured. 🙈 |
@MorrisJobke I would only check if the config is readable and if the cron job isn't run by root. If the admin decides to run the job by a non-root user that is not www-data but is able to write into the data directory I think one can safely assume the user knows what he's doing. |
We thought so in the past as well, but we got teached that some assumptions can't be made. On the other side it should still be safe as it is "read-only config + non-root user", which is already quite good failsafe. |
config/config.sample.php
Outdated
* | ||
* Defaults to 0640 (writeable by user, readable by group). | ||
*/ | ||
'logfilemode' => 0660, |
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.
When the default is 640 i would prefer to use this here as well.
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 updated this ;)
The file logger currently resets the mode of the logfile to 0640. When the webserver is running as a different user than the cron job (but both are in the same group) the files mode has to be 0660. The current implementation breaks logging for the user that is not the owner of the logfile. This patch introduces a new config option 'logfilemode' that expects an octal value (defaults to 0640). Unless the value is lower or equal than 0 the logfiles mode will be resetted to this value. Signed-off-by: Roland Tapken <roland@bitarbeiter.net>
I rebased and fixed the merge conflict. |
3c2f111
to
d17856a
Compare
Codecov Report
@@ Coverage Diff @@
## master #8282 +/- ##
============================================
- Coverage 53.45% 51.69% -1.77%
+ Complexity 25555 25386 -169
============================================
Files 1594 1599 +5
Lines 96259 95104 -1155
Branches 1343 1376 +33
============================================
- Hits 51459 49164 -2295
- Misses 44800 45940 +1140
|
Let me also fix the tests and then this can go in. |
The file logger currently resets the mode of the logfile to 0640.
When the webserver is running as a different user than the cron job
(but both are in the same group) the files mode has to be 0660. The
current implementation breaks logging for the user that is not the
owner of the logfile.
This patch introduces a new config option 'logfilemode' that expects
an octal value (defaults to 0640). Unless the value is lower or equal
than 0 the logfile's mode will be changed to this value.
Signed-off-by: Roland Tapken roland@bitarbeiter.net