Open denis-zyk opened 2 years ago
Hi @denis-zyk. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:
Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release
For more details, review the Magento Contributor Assistant documentation.
Add a comment to assign the issue: @magento I am working on this
To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
:clock10: You can find the schedule on the Magento Community Calendar page.
:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel
@magento give me 2.4-develop instance
Hi @denis-zyk, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.
Could anyone here take a look, please?
@magento give me 2.4-develop instance
Hi @denis-zyk, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.
Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If the issue has a valid description, the label Issue: Format is valid
will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid
appears.
[ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description
label to the issue by yourself.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Verified the issue on Magento 2.4-devvelop branch and the issue is reproducible. On changing crypt key from Admin, new crypt key is getting added every time in app/etc/env.php file. None of the encrypted config values (in core_config_data DB table) are re-encrypted using new crypt key during crypt key change
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2466 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
Verified the issue again on Magento 2.4-develop branch as per developer comments. Please find the observations/findings below:
As per dev docs, The encryption key should be changed on a regular basis to improve security, as well as at any time the original key might be compromised. Whenever the key is changed, all legacy data is re-encoded using the new key. Needed clarification on expected behavior of appending crypt key in env.php file every time.
Note: On removing old crypt key values from env.php file - Magento instance is not working and setup:upgrade gives following error:
Note: There is no issue for UPS shipping method. - No issue "core_config_data" table is updated with new encrypted values for UPS shipping method after generating the encryption key.
I've just created a PR #37705 which should resolve the issue. The underlying cause if the way the XML paths were retrieved, and how those were checked against the DB. More info on that is in the PR in case anyone is curious
I tried to apply your changes over 2.4.2 and 'key' still did not get overwritten but added to the existing value with a line break @Skullsneeze
Hi @chelevich, this is actually expected behaviour. The PR I created fixes an issue where certain encrypted config values were not re-encrypted using the new key.
The underlying reason for this was that the config_path directory was ignored during this re-encryption process originally.
So, after hundred crypt key changes we will have env.php file with hundred lines with previous crypt keys? Is it expected behavior?
So, after hundred crypt key changes we will have env.php file with hundred lines with previous crypt keys? Is it expected behavior?
Yes, seems so.
Any of the keys could be used to encrypt existing data and they have to keep all of them in env.php Key version is part of encrypted string @see \Magento\Framework\Encryption\Encryptor::decrypt
Core just cannot rebuild all encrypted strings across all custom modules.
Magento automatically re-encrypts encrypted values only in core_config_data
and sales_order_payment
.cc_number_enc
column when you change the key in admin panel.
This has become more important after the latest Security Bulletin which suggests to refresh Encryption Key
Just to further clear up any confusion about the keys in your env file. When decrypting Magento gets the existing keys in an array by taking the keys from env.php and splitting them on newlines.
Then they look at the first number in the encrypted string. This number corresponds to the number of the key in the array of encryption keys.
So your initial encrypted data will be prefixed with a 0 (first key in the array), and after re-encrypting your data should be prefixed with the a 1 (second/new key in the array).
This logic all works fine, except that when re-encrypting, config values which use a config_path in system.xml are not correctly updated when the provider config path does not match the path generated using the ids of the xml elements. This should be fixed with the PR
Community launched this module: https://github.com/genecommerce/module-encryption-key-manager To solve magento issues with that, I don't tested yet but it seems to work correctly ;)
Can anyone give us a dummy's guide to the gotchas of changing a production encryption key. The guide makes it seem so easy, I'm suspicious, after finding this thread.
If we follow the guide at https://experienceleague.adobe.com/en/docs/commerce-admin/systems/security/encryption-key:
System > Other Settings > Manage Encryption Key.
Do we need to also do some config changes?
Why would Adobe tell us urgently to rotate the encryption key using admin after applying the CosmicSting isolated patch if this does not work properly? Or does it? For instance genecommerce states in its module description that the JWT factory continues to accept the old key when the new key is generated using admin. Also this very issue is still open. If a Magento installation still is a possible victim of CosmicSting even after applying the patch (with an compromised old key) and rotating keys is a drag than I would expect a lot of panic. At least I am in panic :) Can someone elaborate on this please?
@Rickertje check this page:
There is a hotfix (https://experienceleague.adobe.com/docs/commerce-knowledge-base/assets/AC-12485_Hotfix_COMPOSER_patch.zip?lang=en) which should deal with the problem that JWT Factory will use the old key. That should be applied among with the latest security patch. If you have applied the isolated patch, that should already contain the hotfix.
What comes for rotating the key, as @Skullsneeze wrote, there seems to be bug that not all of core_config_data secrets are re-encrypted. There is fix in PR https://github.com/magento/magento2/pull/37705 which is still open probably because some of the tests was not passed.
In my understanding even with that PR fix, some 3rd party modules / custom tables that has secrets might not be re-encrypted. This module was already mentioned https://github.com/genecommerce/module-encryption-key-manager/#allows-you-to-keep-your-existing-media-cache-directories but you should also read this https://www.linkedin.com/pulse/magento-2-encryption-key-rotation-how-we-worked-around-core-deficiencies-inqzc/?published=t and check the stand-alone script for scanning fields that has encrypted data https://github.com/bemeir/magento2-rotate-encryption-keys
Still highlighting that both of those (module and stand-alone script) are provided as-is without any warranty. So you are using those at your own risk.
Thanks Seppo, that is a relief. I applied the isolated patch and I will now generate a new encryption key using admin. Also I will check for secrets that might not have been re-encrypted and re-encrypt them using the Bemeir module. Thanks for clarifying.
I face issue of blank value showing in admin configuration after upgrade Magento to 2.4.7 in local. I fixed it with by copying latest production encrypt key(env.php) in local which is rotated recently with last security patch.
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
app/etc/env.php
, while the previous crypt key is overwrittenActual result (*)
core_config_data
DB table) are re-encrypted using new crypt key during crypt key changeapp/etc/env.php
, meaning there is now a multiline string containing a previous crypt key, e.g.Where
391569b674c6f1e6fc9d545eaa1ef41e
is the previous crypt key, andbad91f79f8136c07098faae8c5102a76
is a newly generated crypt key. All the following crypt key changes will append another new crypt key to the list preserving all previous crypt keys.Doing such changes on a regular basis (again, as suggested by official documentation to be a good security practice, and I totally agree with that point), will actually keep "polluting"
app/etc/env.php
configuration file.Moreover, since the actual encrypted values are not re-encrypted using the new crypt key automatically, it imposes a security risk, and creates a general mess with different versions of crypt key being used all over the place.
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.