You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by "vikaskr22 (via GitHub)" <gi...@apache.org> on 2025/07/18 13:29:26 UTC

[PR] RANGER-5239: Decrypt and verify before storing newly re-encypted key … [ranger]

vikaskr22 opened a new pull request, #612:
URL: https://github.com/apache/ranger/pull/612

   …material into DB
   
   ## What changes were proposed in this pull request?
   
   A sanity check (kind of assertion) has been added in the RangerMasterKey to make sure re-encrypted material returns the the same old MK key material after decryption process. It is required , if decrypt operation fails due to any runtime error or returns some wrong material, it would be the case of data loss .   
   
   Since same encrypt/decrypt provider is being used for both MasterKey and Zone keys, I am not adding this check for zone keys. Adding such check for zone keys will impact the performance considering there would be many zone keys.
   
   ## How was this patch tested?
   
   mvn build
   Unit Test
   Manually verified in docker container by configuring the container to support FIPS provider and related configuration. Followed the steps from [](https://issues.apache.org/jira/browse/RANGER-3174)
   
   **What was tested:**
   
   By default, master key got created using PBEWithMD5AndDES, after configuration for FIPS and restart, Master key got re-encrypted using the configured algorithm PBKDF2WithHmacSHA256
   
    
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5239: Decrypt and verify before storing newly re-encypted key … [ranger]

Posted by "vikaskr22 (via GitHub)" <gi...@apache.org>.
vikaskr22 commented on code in PR #612:
URL: https://github.com/apache/ranger/pull/612#discussion_r2216316973


##########
kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java:
##########
@@ -308,6 +308,13 @@ public boolean reencryptMKWithFipsAlgo(String mkPassword) {
                 init();
                 PBEKeySpec newPbeKeySpec = getPBEParameterSpec(mkPassword, encrCryptoAlgo);
                 byte[] masterKeyToDB = encryptKey(oldKeyMaterial, newPbeKeySpec);
+                byte[] decryptedMaterialWithNewAlgo = decryptKey(masterKeyToDB, newPbeKeySpec);
+                // This is just a sanity check but important to ensure that returned key material after re-encryption is same as old MK key material.
+                if (!Base64.encode(oldKeyMaterial).equals(Base64.encode(decryptedMaterialWithNewAlgo))) {

Review Comment:
   No harm in adding the checks.
   
   I have following explanation on this:
   
   **oldKeyMaterial** is already being used in earlier statements, means, if it is null it would break before reaching to this line. If we have reached this line and **decryptedMaterialWithNewAlgo** is null , that means something like following:
   
   oldKeyMaterial.equals(null); that will be false.
   
   Pls let me know your thought?
   Thanks.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5239: Decrypt and verify before storing newly re-encypted key … [ranger]

Posted by "spolavarpau1 (via GitHub)" <gi...@apache.org>.
spolavarpau1 commented on code in PR #612:
URL: https://github.com/apache/ranger/pull/612#discussion_r2216247249


##########
kms/src/main/java/org/apache/hadoop/crypto/key/RangerMasterKey.java:
##########
@@ -308,6 +308,13 @@ public boolean reencryptMKWithFipsAlgo(String mkPassword) {
                 init();
                 PBEKeySpec newPbeKeySpec = getPBEParameterSpec(mkPassword, encrCryptoAlgo);
                 byte[] masterKeyToDB = encryptKey(oldKeyMaterial, newPbeKeySpec);
+                byte[] decryptedMaterialWithNewAlgo = decryptKey(masterKeyToDB, newPbeKeySpec);
+                // This is just a sanity check but important to ensure that returned key material after re-encryption is same as old MK key material.
+                if (!Base64.encode(oldKeyMaterial).equals(Base64.encode(decryptedMaterialWithNewAlgo))) {

Review Comment:
   Should we also check for null for oldKeyMaterial & decryptMaterialWithNewAlgo?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5239: Decrypt and verify before storing newly re-encypted key … [ranger]

Posted by "dhavalshah9131 (via GitHub)" <gi...@apache.org>.
dhavalshah9131 merged PR #612:
URL: https://github.com/apache/ranger/pull/612


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org