Let's break it apart. You have an encryption key:
YOUR_KEY
You use this to encrypt the data in your database:
ENCRYPTED_PII_DATA = AES(PII, YOUR_KEY)
You don't want your key stolen so you encrypt it with AWS KMS and it gets stored in your application as:
YOUR_KMS_ENCRYPTED_KEY
Therefore when your application launches it grabs YOUR_KMS_ENCRYPTED_KEY
out of its own store and sends that to AWS KMS for decryption:
YOUR_KEY = KMS_DECRYPT(YOUR_KMS_ENCRYPTED_KEY)
Thus restoring the original YOUR_KEY
which (presumably) you store in memory and use to decrypt all your PII as needed:
PII = AES_DECRYPT(ENCRYPTED_PII_DATA, YOUR_KEY)
So what happens when you ask AWS to rotate its master key? In your case: nothing. AWS KMS keeps all the old versions of its own encryption key around so that it can continue to decrypt any data it had previously encrypted. Your application doesn't know anything about the rotation of course, so the next time your app launches it will grab YOUR_KMS_ENCRYPTED_KEY
out of its store, send it off to AWS again, ask for it to be decrypted, and AWS will return YOUR_KEY
just as it always has. You will then be able to decrypt your data with YOUR_KEY
just like you always did. However rotation will give you another option. After your app decrypts its key, it can go ahead and ask AWS KMS to re-encrypt it again:
YOUR_KMS_ENCRYPTED_KEY_V2 = KMS_ENCRYPT(YOUR_KEY)
This will return back a new encrypted version of YOUR_KEY
which is encrypted using the new AWS master key. However, this is still just an encrypted version of YOUR_KEY
, and when you ask AWS KMS to decrypt it again, you'll still end up with YOUR_KEY
. As a result, from the perspective of your PII, your master key has never changed. You will still be able to decrypt your PII just as you did before, since your key has never changed (just the encrypted version of it).
In other words, since you aren't using KMS to encrypt your PII, but instead are using it to encrypt the encryption key used for your PII, you aren't actually rotating the key used for your PII. If you also wanted to rotate the key used to encrypt your PII then you would have to manage that process yourself, which would mean:
- Generate
YOUR_KEY_V2
- Use
YOUR_KEY
to decrypt your PII
- Re-encrypt your PII with
YOUR_KEY_V2
- Encrypt
YOUR_KEY_V2
- YOUR_KEY_V2_KMS_ENCRYPTED = KMS_ENCRYPT(YOUR_KEY_V2)
- Store
YOUR_KEY_V2_KMS_ENCRYPTED
and throw away YOUR_KMS_ENCRYPTED_KEY
(just make sure you do this in a way that you don't permanently lose access to data if any of the above steps are interrupted, which is probably the hard part)
Hopefully that was clear and answers your first question. Your last question however:
Is it even necessary to rotate the data key? Or rotating master key
every year is sufficient.
Is unanswerable. Only you can decide if it is necessary to rotate the data key. Your company may have guidance about what kind of key rotations are necessary and when, but otherwise it's not like there is a law about this. You have to decide for yourself what risks you are trying to protect against, the best way to mitigate those risks, and which steps are worth the effort. As an example, rotating the KMS master key may provide some protection in the event that someone grabs an old key out of a stolen backup, but provides no protection in the event that someone manages to grab YOUR_KEY
directly out of the running application. In the latter case all PII would be accessible to anyone who stole YOUR_KEY
. The only way to protect against that would be by using AWS KMS to encrypt the PII directly, but of course doing that has monetary and performance costs.