spicedb icon indicating copy to clipboard operation
spicedb copied to clipboard

Support IAM database authentication for Postgres datastore

Open jhalleeupgrade opened this issue 2 years ago • 8 comments

As of now, there is only support for username:password in the connection string for Postgres. For those who use an AWS's hosted Postgres, it's preferable to use IAM database authentication.

jhalleeupgrade avatar Jun 22 '22 17:06 jhalleeupgrade

@jhalleeupgrade any pointers on documentation on how that is enabled?

josephschorr avatar Jun 22 '22 17:06 josephschorr

@josephschorr Sure! A good starting point for documentation would be: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/UsingWithRDS.IAMDBAuth.Connecting.Go.html

jhalleeupgrade avatar Jun 22 '22 17:06 jhalleeupgrade

cc @ecordell who will probably have opinions on the UX of how this is configured

jzelinskie avatar Jun 23 '22 00:06 jzelinskie

I'm not sure what the best CLI UX looks like for this feature.

Because it looks like the password field is overloaded to provide this functionality, there is an interesting workaround that could be done now: write a tiny program that prints the output of rdsutils.BuildAuthToken() and then just use that value for the password on the SpiceDB serve command: spicedb serve --datastore-engine postgres --datastore-uri "host=blahblah password=$(myProgram) ...".

jzelinskie avatar Jul 01 '22 05:07 jzelinskie

@jzelinskie I think we would need to provide a way to refresh at runtime, because the AWS Auth token has an expiration deadline.

palacerteupgrade avatar Jul 04 '22 17:07 palacerteupgrade

You're totally right that the value actually is short-lived. There's a lot of good discussion on this issue for our Postgres library. It looks like we should decide the UX for this and then we can add a BeforeConnect hook for connections to inject the "password" into the config.

jzelinskie avatar Jul 05 '22 02:07 jzelinskie

It looks like the postgres library supports an environment variable that specifies a password file whose value is read at connection time. If that's right then one way of using IAM database authentication today for a SpiceDB Postgres datastore is to run a script that re-writes the file at an interval appropriate for keeping credentials valid. Maybe some people might prefer the service file over the password file.

theantirobot avatar Dec 19 '22 23:12 theantirobot

Any updates on this?

elebiodaslingshot avatar May 10 '23 21:05 elebiodaslingshot