IAM authentication to access the Database #24451
adelinn
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
It would be great if Directus would become capable of authenticating to the database using a Service Account / Service Principal and IAM permissions in a cloud environment instead of requiring the use of plain password. There is currently possible to achieve that but the solution is very hacky.
Basic Example
Say I want to deploy Directus to Cloud Run. I can configure there an integration with Cloud SQL. Instead of specifying the
DB_PASSWORDI would set something likeDB_IAM_AUTH=gcpand Directus would configure Knex to use a Google Cloud Access Token for the password and refresh it before expiring.Motivation
Moving away form secrets in favor of temporary tokens has become the trend now as it reduces the risk of getting the database compromised if the service is compromised and makes secret management easier.
Additionally, it's a step forward in making security easier as handling a database secret can be done wrong, while configuring token based authentication is less likely to go wrong. And why to entrust a cloud environment a secret when that cloud environment is already trusted to run Directus? Why not leverage that trust as our database "password"?
Detailed Design
I suggest that a new environment variable would be implemented
DB_IAM_AUTHwhose value would specify what authentication libraries to use and how to configure Knex to authenticate with a token. Possible values could beazure,gcp,awsand maybe more.Note: The following examples have been written having Postgres in mind but they may require little adjustments to work for other databases.
A value of
gcpwould configure Knex this way:Note: I'm using
google-auth-libraryinstead of directly using@google-cloud/cloud-sql-connectorbecause the Cloud SQL connector establishes its own tunnel to the DB and can't use the already provided UNIX socket that the Cloud Run - Cloud SQL integration provides, and which is more secure than connecting to the DB through the public IP.And a value of
azurethis way:Requirements List
Must Have:
Drawbacks
Alternatives
Implement this using a javascript config file.
For GCP:
For Azure:
Adoption Strategy
It will not be a breaking change, nor require migration. It will just be a new feature.
Unresolved Questions
Whether implementing
DB_IAM_AUTHconfig variable is the best way to solve this.Beta Was this translation helpful? Give feedback.
All reactions