Problem/Motivation
At the moment when $settings['skip_permissions_hardening'] = TRUE, the system module's system_requirements unconditionally issues a warning about the site's config files' permissions without actually checking them:
if (file_exists($full_path) && (Settings::get('skip_permissions_hardening') || !drupal_verify_install_file($full_path, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE))) {
$conf_errors[] = t("The file %file is not protected from modifications and poses a security risk. You must change the file's permissions to be non-writable.", ['%file' => $full_path]);
}
This is quite confusing and misleading (see related issues).
Proposed resolution
Drupal should either skip the checks and not issue any warnings about the state of specific conf files, or perform the checks but only issue any valid warnings (as opposed to errors).
A simple warning to remind developers not to carry this configuration over into production would seem sufficient.
Remaining tasks
* Decide whether to skip checks, or perform them and issue only valid warnings.
* Patch the existing code accordingly.
* Update tests as appropriate.
User interface changes
* Removal of invalid warnings when config file permissions are not actually incorrect.
API changes
* None.
Data model changes
* None.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2950851-16.patch | 7.59 KB | alexpott |
| #16 | 9-16-interdiff.txt | 8.02 KB | alexpott |
| #9 | 2950851-9.patch | 4.17 KB | mcdruid |
Comments
Comment #2
mcdruid commentedComment #3
mcdruid commentedComment #4
mcdruid commentedReading through the code a bit more, I can now see a reason for the existing logic:
https://api.drupal.org/api/drupal/core%21includes%21install.inc/function...
...actually tries to fix the permissions of the file according to the masks it is passed, so the existing code doesn't run the check with that function as doing so may change the existing permissions.
In which case, I'd argue we should skip the checks without issuing the warnings.
Comment #5
mcdruid commentedPatch which skips the checks on config files - which is not actually a change to the behaviour, we just no longer flag up permissions warnings without actually checking those permissions.
It seems to me that some of the comments in the surrounding code are also a little bit misleading:
...this doesn't mention that the code is about to try and fix any incorrect permissions.
...because
drupal_verify_install_fileactually tries to change the permissions if they don't initially match the mask, we only actually consider it an error if that attempt to fix the permissions fails.I wonder if we should add a word or two of extra explanation about what the "hardening" actually is here - i.e. attempts will be made to fix incorrect permissions?
Comment #7
mcdruid commentedOops; and now with a tweak to the test because the warning produced by
system_requirementsis slightly different.Comment #8
anavarreWithout the patch, the default message is:
With the patch, the message becomes:
So, it seems to me we're removing important information as to what exactly is happening. Our issue IIUC is what we're asking the end user to do to fix the issue. As such it looks like:
You must change the file's permissions to be non-writable.should be removedskip_permissions_hardeningset toTRUEand it's an issue in prod, would be helpful to understand what needs to be changed.Comment #9
mcdruid commentedSo let's make the warning that's shown when
skip_permissions_hardeningis enabled more explicit about the situation.Comment #10
anavarreWithout the patch:
With the patch:
I still feel we're lacking important information to understand what's going on. My sentiment is we need a) an understanding about what exactly is the consequence of enabling
skip_permissions_hardeningand b) how to remedy this e.g. on prod environments. What about:Comment #11
mcdruid commentedThe problem is that we don't know whether those config files are "protected from modifications" (i.e. are writable) or not; calling the function to verify that will change the permissions if they are writable.
I think we should avoid giving incorrect information (i.e. saying "settings.php is writable" when that may not be the case) as that just leads to confusion and frustration.
We could try to go the extra mile and actually check the permissions without trying to fix them, but that would mean using something other than
drupal_verify_install_file.I'm not sure it's worth the extra complexity of checking the permissions in a different way; the idea is simply to remind developers that they have disabled the "permissions hardening" locally, and that they'll want to ensure that setting is not carried over to production.
My vote is avoid saying anything about the actual state of specific config files because the code (as it stands) doesn't know what their permissions are.
Comment #12
anavarreI guess I can live with that. Let's see what committers think.
Comment #13
mcdruid commentedComment #15
anavarreTestbot?
Comment #16
alexpottI think this issue is a bit tricky. I think @anavarre's comment in #10 is correct. What we need is a version of drupal_verify_install_file() that does not try to autofix by default. That way we could do something like
And we could change
'value' => t('Not protected'),to'value' => t('Permissions hardening skipped'),so when it's a warning and not an error we know why.Something like the patch attached.
Comment #17
alexpottMeant to set to "needs review"
Comment #18
mcdruid commentedI think the patch in #16 looks good; I've verified that a writable settings.php file goes from producing an error to a warning when
skip_permissions_hardeningis enabled.It's an enhancement to be able to call
drupal_verify_install_file()without having it actually change permissions on files when appropriate.I'll take a look at drafting a change record for this.
Comment #20
mcdruid commentedHmm, testbot snafu?
Comment #21
mcdruid commentedDraft change record: https://www.drupal.org/node/2961774
Comment #22
mcdruid commentedNR for the change record.
Comment #23
anavarreReviewed the CR with @mcdruid and the last iteration looks great to me.
Comment #25
mcdruid commentedtestbot snafu?
Comment #26
alexpottYes
Comment #28
MixologicTestbot Snafu. Again.
Comment #30
catchCommitted 3663ab6 and pushed to 8.6.x. Thanks!