I’m using HashiCorp Vault to safely store secrets for my system. These secrets are read during system initialization (via runtime.exs).
One of the features that Vault gives is creating database credentials with TTL, meaning that your database connection will be available for a specific time (say, 1 hour) and then you will need to ask vault for a new credential and restart the connection.
This way you never have a perpetual credential to the database limiting the window for a data leak in case your credentials are compromised.
This can easily be done using Ecto dynamic repos, but this means that I will have to manage the connection pool by myself.
So, is there some way to add support for dynamic credentials with TTL for the already implemented Ecto pool?
My guess is that I would be able to configure my repo something like this:
config :ecto, Repo,
update_credentials: &MyCredModule.get_credentials/0
This function would return a tuple, something like
{
%{username: "...", password: "..."}, # New credentials
~U[2020-01-01 01:01:00.000000Z] # TTL or when pool needs to get new credentials again
}
I thought about creating an issue in Ecto’s GitHub suggesting something like this, but decided to try here first in case a solution already exists.
PS. I already saw some topics here discussing this, but they are old and/or don’t have any solution, so I decided to create a new one instead of resurrecting an older one.