I have a question regarding secure storage of API keys & secrets.
Here's my scenario:
I'm developing a program that collects/analyzes data from multiple external APIs. The data is rather sensitive, and the APIs all require a key & secret. My software will call these APIs, crunch the data returned, and store the results. I expect that I'll end up hosting this software in 'the cloud' eventually so I can have maximum up-time & scalability.
My question is what's the safest/best way to store the credentials (keys & secrets) for the external APIs that I'm calling?
Here are a few things that I've been considering, but I'm really open to anything...
If you are using dynamically generated secrets, the most effective way to store this information is to use the Keystore API. You should not store them in shared preferences without encrypting this data first because they can be extracted when performing a backup of your data.
So instead of storing the key in plain text (bad) or encrypting it, we should store it as a hashed value within our database. A hashed value means that even if someone gains unauthorised access to our database, no API keys are leaked and it's all safe.
However, experts do not consider API keys to be secure enough on their own. This is for a few reasons: API keys can't authenticate the individual user making the request, only the project or application sending the request. API keys are like passwords — only effective if the owner stores them securely.
The best place to store an API key is in a secrets manager. Read more about regenerating API keys.
You're going to end up chasing your tail on this one, purely because a server breach is game over. There are definitely steps you can take to reduce the damage a server breach can cause, but nothing foolproof.
Consider the options you've outlined:
My point is, you are focusing on the wrong part of your security. If the attacker gains access to the server, it is already game over. Focus on preventing access to your server in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With