- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.9k
Auto rotation of key encryption keys #14396
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
        
          
                core/src/main/java/org/apache/iceberg/encryption/StandardEncryptionManager.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                core/src/main/java/org/apache/iceberg/encryption/StandardEncryptionManager.java
          
            Show resolved
            Hide resolved
        
      | Thanks @ggershinsky for the PR! Is it possible to add a rotation test: insert a KEK with a timestamp older than 2 years and verify a new KEK is created and used? | 
| 
 Sure | 
|  | ||
| sem.setTestTimeShift(TimeUnit.DAYS.toMillis(800)); | ||
| // above rotation time, key must be different | ||
| assertThat(sem.keyEncryptionKeyID()).isNotEqualTo(initialKekID); | 
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.
nit: Do we want to check that the manifest‑list key metadata is encrypted by the rotated KEK?
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.
Yup, can be done.
| LGTM. Thanks @ggershinsky ! I’ll leave this PR open for a couple more days in case others want to review. | 
| Thanks @ggershinsky for the PR! | 
Iceberg table encryption has a "key encryption key" that encrypts manifest list key metadata for every snapshot (manifest list) produced in a table. The NIST SP 800-57 document recommends setting a limit of 2 years on the crypto-period of key wrapping (encryption) keys.
However, recording the creation timestamp of key encryption keys in the metadata.json file is not safe in non-REST catalogs, as an attacker can modify this file and update the timestamp to a newer value - making the writers re-use a key encryption key beyond the recommended limit, potentially allowing the attacker to reconstruct the key.
That's why the current code has only one key encryption key (without a timestamp), and requires the users to rotate the key manually every two years for each table. Also, the key metadata of the existing manifest lists has to be re-wrapped (re-encrypted) with the rotated key. Iceberg will need to build such re-wrapping procedure and provide it within two years.
Fortunately, there is a cryptographic solution that doesn't require manual key rotation and metadata re-wrapping. We can use the key encryption key timestamp as an AES GCM signature (AAD) when wrapping the manifest list key metadata. This way, the malicious tampering with timestamps will be detected by Iceberg readers upon decrypting the manifest list key metadata. This solution also enables automatic rotation of the key encryption keys, so the users don't need to run manual re-wrapping procedures on their tables.
This PR implements such auto-rotation solution.