Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDS IAM Database Authentication #80

Open
md5 opened this issue May 13, 2022 · 4 comments
Open

RDS IAM Database Authentication #80

md5 opened this issue May 13, 2022 · 4 comments
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue

Comments

@md5
Copy link

md5 commented May 13, 2022

Are there any plans for this gem to support RDS IAM Database Authentication?

@mullermp
Copy link
Contributor

mullermp commented May 13, 2022

Thanks for opening up an issue. We didn't have specific plans to add this (mainly because we hadn't considered it for aws-sdk-rails). I'm happy to make this as a feature request and contributions are always welcome. What did you have in mind for supporting this feature? The Ruby SDK does have an abstraction for this - https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/RDS/AuthTokenGenerator.html

@mullermp mullermp added the feature-request A feature should be added or improved. label May 13, 2022
@md5
Copy link
Author

md5 commented May 13, 2022

@mullermp I think since the tokens have a lifetime of 15 minutes, any implementation would need to be aware of that and would need to regenerate the token for new connections in the connection pool if the token has expired (or on a reconnect). The ActiveRecord internals for this don't seem particularly well-documented from what I could see, but I think it would probably need a wrapper adapter that knows about these details and delegates to the standard ActiveRecord adapter.

So in terms of a developer interface, I could imagine something like this (assuming that DATABASE_URL is providing the RDS hostname and database name):

default: &default
  adapter: aws-rds-iam
  delegate_adapter: postgresql
  encoding: unicode
  sslmode: require
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

production:
  <<: *default
  username: some_user

The aws-rds-iam adapter would supply the generated token to the PostgreSQL adapter in this case as the normal password setting.

@md5
Copy link
Author

md5 commented May 13, 2022

Looking closer at AuthTokenGenerator, it's just creating a presigned request and has no dependencies on any outside services, so it seems like it could just blindly create a new token any time a password is needed without regard to whether any previous token has expired or not.

@md5
Copy link
Author

md5 commented Sep 27, 2022

FWIW, there is a gem that enables RDS IAM authentication specifically for pg via monkey patching: https://github.com/haines/pg-aws_rds_iam

@RanVaknin RanVaknin added the p3 This is a minor priority issue label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

3 participants