I am building a Node.js application that receives a long term access token from another application that I need to access. I don't want to store these access tokens directly in the database since anyone who has access to these tokens can basically do whatever they want with it it.
I am new to Cloud KMS and such systems in general but spent the last few hours learning it. It seems like the ideal solution to solve my problem but I'm not entirely sure what strategy I should follow to store these access tokens:
- Should I store an encryption key in Cloud KMS and use that encryption key with an NPM package like this one to store access tokens in my database?
- Should I store the access tokens in KMS directly? My assumption is that I would have a key store and keys rotated every 14 days. Whenever I receive an access token, I simply encrypt it and store it at KMS. I only store the ciphertext in my database. When I need to access the access token from KMS, I use the ciphertext to decrypt it.
Which of the above is the right way to use KMS? If it's option 2, I have additional questions:
- Can I encrypt a large number of access tokens with a single key or do I need to create a new key for every access token?
- If I ever need to modify the access token encrypted at KMS, can I simply modify it or do I need to destroy the old version and encrypt again?
Thanks for your help!