Issue Summary
While using settings for the s3fs.access_key and s3fs.secret_key is preferrable to config, it does limit some of the administrative functionality of managing the configuration.
Proposed Resolution
When the key module is enabled allow s3fs to be configured to use a filesystem key which will no longer expose the key value in config as it can be outside of the site root. This should cover the security concerns by allowing keys to be provided as configs without exposing the key value stored in the filesystem.
The attached patch will use the configured keys if they are not set in settings.php.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | integrate_with_the_k-2976430-36.patch | 10.88 KB | cmlara |
| #36 | interdiff-2976430-35-36.txt | 1.04 KB | cmlara |
| #35 | integrate_with_the_k-2976430-35.patch | 10.71 KB | cmlara |
| #31 | 2976430-add-key-to-schema-file.patch | 13.12 KB | gavinrfitzgerald |
| #30 | 2976430-adding-key-to-schema.patch | 12.48 KB | gavinrfitzgerald |
Comments
Comment #2
malcolm_p commentedThe latest patch updates the warning from s3fs_requirements().
Comment #3
douggreen commentedI suggest that we not restrict the settings form to only the 'file' provider, because that prevents custom key implementations, that may be just as secure and also may use files. I ran into this because we store all or keys in a predefined place outside the document root, that varies depending on which environment (dev, test, live) the code is running on. I didn't roll a patch. Just remove the two #key_filters lines.
'#key_filters' => ['provider' => 'file'],Comment #4
malcolm_p commentedGiven the security concerns that caused storing the keys in config to be removed, I'm hesitant to remove the file restriction as it'd essentially allow storing keys in config again. I believe that if your custom KeyProvider plugin uses a storage_method that is also "file" it should show up with this filter. However a completely custom provider would still be an issue.
A more robust solution might be to use a list of allowed key providers from config ie. s3fs.settings:allowed_key_key_providers: []
Comment #5
manuel garcia commentedThanks for the patch, was about to suggest doing this :)
I agree with @douggreen on #3, we should not limit the key provider to just file. The suggestion on #4 to use a setting for allowed key providers sounds interesting, but also perhaps too convoluted.
Unfortunately this is not the case, using the
'provider'key on the filter limits by provider only. Other options could be'type', or'type_group', and unfortunately all of these would be discarding custom providers.You can see how all this works on
Drupal\key\Element\KeySelectandDrupal\key\KeyRepository.In my opinion the security concerns with storing key values in configuration should be tackled within key module itself, perhaps via means of informing the user of these concerns.
Comment #6
manuel garcia commentedIn reality what we would need is to be able to filter by
storage_method. Opened #3013279: Add ability to filter list of keys based on key storage_method for this.Comment #7
malcolm_p commentedAh, thanks for looking into that, I had believed that would already work.
The main use case I can see for a config specifying allowed providers (probably allowed_storage now) for #4 would be to also support external key management providers, which aren't currently covered by the patch.
Comment #8
manuel garcia commentedYeah I think if we can review and get #3013279: Add ability to filter list of keys based on key storage_method in, then we can update this patch which will get us both secured selections and the flexibility of using different key providers :)
Comment #9
manuel garcia commentedGreat news, #3013279: Add ability to filter list of keys based on key storage_method was committed so we should be able to filter by storage_method using the latest release of key module: https://www.drupal.org/project/key/releases/8.x-1.8
Lets use
'storage_method' => 'file'here instead.Comment #10
manuel garcia commentedAddressing #9
Comment #11
jansete commentedNice work guys, I'm reviewing today. I'll tell you something soon.
Comment #12
jansete commentedHi, i was reviewing it, and I have new proposals to add:
- Inject 'module_handler' service in SettingsForm
- Remove ':key_collection' => $key_collection_url in key_access_key and key_secret_key form elements, becuase is not being used (SettingsForm).
- We are using only file storage method, I think that is important that the user knows it, we should add this filter to form field descriptions.
- We should update README.txt with this new feature.
- We can add new @todo for 8.x-3.0-beta1 (in this release we will remove all backward compatibility with access_key and secret_key in database storage) to create a method to get the keys, and we have only one way to get them and avoid checkings in different places.
Comment #13
manuel garcia commentedThanks @jansete for the review!
Done. Injected it also on
S3fsServicewhile I was at it.Nice catch, done.
Not entirely sure what you mean here: what should the
@todosay? where should we place it? Do you mean to create a follow up or?Comment #14
malcolm_p commentedThanks for all the work on this Manuel, #13 is working well for me as well.
For the beta1 update I think the idea would be to update
Drupal\s3fs\S3fsService::getAmazonS3Clientmoving the logic checking config, settings, and now keys into a separate function. Does that sound right?Comment #15
manuel garcia commentedThanks @malcolm_p for the explanation.
For now, I've created a follow up here #3054540: Move the logic checking config, settings, and keys into a separate method please kindly review the summary & title as needed.
Setting to needs work due to that and adding the
@todoto the patch.Comment #16
manuel garcia commentedAlso needs work for this mentioned on #12:
Comment #17
jacobbell84 commentedI rerolled this for the alpha15 release and added a small blurb of help text to the README.txt to try and address the comment in #12
Comment #18
ravi.shankar commentedComment #19
manuel garcia commented#17 looks good to me, adding the @todos here requested on #12. Anything else we need to do here?
Comment #20
manuel garcia commentedI'm bumping the priority here, this is imho a security issue since people are probably committing their credentials to VCS.
Comment #21
malcolm_p commentedThe patch in #19 is working for me as well, if there are no other issues it'd be great for this to make a release.
Comment #22
darvanenOne big item, and a few nits.
The Key module does not store keys on a per-module basis as you can see by this function in \Drupal\key\KeyRepository:
I cannot recommend highly enough that you prefix the keys with the module name. I would also make them a constant since they're being used all over the place among other instances of the word 'key' which will be confusing for anyone looking at the code for the first time.
Restrict lines to 80 chars where at all possible
Comment over 80 chars
Over 80 chars.
Comment #23
jacobbell84 commentedComment #24
cmlaraRegarding #4:
It sounds like the only advantages we will gain to using the keys module is that
Looking at what I intend to develop for #3200292: [META] Support authentication other than InstanceProfile or Access Keys I believe we would gain the ability to know the config is in a file, and we will gain the ability for an admin to change the config inside the GUI by changing which config file. We we would not get a dropdown box, instead only receiving a text field, however that burden exists in the initial configuration of the Keys module too. Additional an admin would need to know how to write an AWS Profile file instead of just putting a single string in a file.
Perhaps if we were using more of the Keys module I could see more value, at the moment to me it feels like this is trying to add a module integration just to complete something that could be handled by adding a field for a file path for the access/private key or some documentation (I've recently committed a change to the README reminding about not storing keys inside the docroot).
There is note to a security concern that came up, I'm not aware off hand which incident this was, I could guess it was a config export, a settings.php leak, or a database leak revealing secret triggering some concerns but I'm too new to this project to know the exact specifics.
Regarding #20
Do we have any data that this change would significantly reduce key stored in version control? I could see an admin easily placing a file in version control as placing it in settings.php.
Is there something I'm missing on why integration to Keys would be better?
Comment #25
gavinrfitzgerald commentedRerolled patch for alpha17.
Comment #26
jacobbell84 commentedHi @cmlara,
I can't speak for everyone of course, but Keys does open the door for more then just storing keys in files. It also can store keys externally (i.e. Lockr) and can be extended to support other storage methods we haven't thought of yet. That said, maybe a compromise would be to do this as a sub module so that we're not adding dependencies to the main module?
Personally it makes it a little easier because I can set git ignores up to exclude anything put into our sites keys folders whereas trying to exclude the settings.php file gets more complicated. Obviously doesn't stop someone from deliberately adding the keys, but it's something.
Comment #27
cmlaraSetting needs work for further discussion. The readme portion looks to need a rewrite as the file was re-done in Alpha17 the context of the addition no longer makes sense. Noticed a dual
use MessengerTraitin the reroll as well.Thanks for providing your input @jacobbell84.
As it currently exists I believe this patch doesn't allow for that as it appears to be locked specifically to just the file storage by
'#key_filters' => ['storage_method' => 'file'],. This would open to other modules but only if they declare they use file storage which I'm not sure Lockr or other similar plugins would declare if they use many external systems like databases.The use of non-file storage on keys is what looks the most interesting to me personally for the Key's module value. This is why I wonder what is the background history I'm missing that it was suggested we not trust an administrators choice on where they put the credentials as a core requirement of this patch as currently built (comments #3-#10).
This is where I generally suggest something like
include('/path/to/keys/secretconfig.php')or$value = file_get_contents('/path/to/secret')or similar in settings.php that way the settings.php is safe and the secrets are in a more controlled location that can be ignored in the repo, or often in my own deployments isn't even inside the path of files deployed by the VCS and is controlled by external means (even if that is sometimes as low tech as writing the file one time and leaving it)As to submoduling: I'm not really sure off hand how easy this would be to split off. It may be doable I just haven't looked that closely at it. That question also has me wondering what jansete's meaning was when he suggested " to create a method to get the keys, and we have only one way to get them and avoid checkings in different places." if he meant standardizing all the authentication to one function as it appears the sub issue of #3054540: Move the logic checking config, settings, and keys into a separate method makes it seem or if he was referring to not having as many configuration methods available so there are not multiple ways to provide the same data (in which case we would want to standardize on one single method that can provide secret keys and not sub module it)
Comment #28
gavinrfitzgerald commentedOur CI environment enforces schema. I've added key to the module schema definition.
Comment #29
gavinrfitzgerald commentedFixing the previous patch.
Comment #30
gavinrfitzgerald commentedComment #31
gavinrfitzgerald commentedComment #32
cmlaraVersion back to dev as this is a feature request.
Back to needs work per #27 concerns raised about patch that have not yet been addressed.
Additionally this is needs work for additional discussion on patch about implementation details.
Patches need to be against dev to test and apply, especially with how much of the code is being worked on right now clearing up known issues in the code.
Comment #33
darvanenPlease see #3206162: 4.x Version which aims to implement this, and provide feedback if you have any.
Comment #34
darvanenOops, I meant to make that a related issue, not parent.
Comment #35
cmlaraHere is a re-rolled version of the patch based on latest Dev.
Changed names around to try and make the source code a little easier to follow per suggestions above.
This re-roll does NOT limit the configuration to FILE only keys in order to allow other 3rd party key providers to function. If Key's module ever gets a method to allow all methods EXCEPT a method that would solve this concern. I can see some users wanting to use the Keys module environment provider instead of settings.php with environment variables.
Looking at this I don't think this code will work with multivalue keys, I'm not sure if there is a way to exclude those from the selector list.
No interdiff due to the rebase.
Opinions?
Comment #36
cmlaraRebase and limited to Authentication key type to avoid the multivalue key problem.
Comment #39
cmlara