Skip to content

AWS RDS token based password provider#9518

Merged
himanshug merged 29 commits intoapache:masterfrom
himanshug:aws_pwd_provider
Jan 7, 2021
Merged

AWS RDS token based password provider#9518
himanshug merged 29 commits intoapache:masterfrom
himanshug:aws_pwd_provider

Conversation

@himanshug
Copy link
Copy Markdown
Contributor

@himanshug himanshug commented Mar 14, 2020

Description

Adds a new PasswordProvider impl to access AWS RDS DB instances using temporary AWS tokens. Since these tokens expire periodically, additional changes are made to ask PasswordProvider for password every time a new DB connection is established.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths.
  • added integration tests.
  • been tested in a test Druid cluster.

Key changed/added classes in this PR
  • AWSRDSTokenPasswordProvider
  • BasicDataSourceExt

@himanshug
Copy link
Copy Markdown
Contributor Author

Update: This patch has been successfully running on few Druid clusters using AWS Aurora RDS DB clusters and accessing same without password but using ephemeral AWS IAM tokens.

@jihoonson
Copy link
Copy Markdown
Contributor

@himanshug thanks for the update. I removed the Area - SQL tag because I think it's about Druid SQL layer. I haven't looked through the whole PR yet, but it seems like this is in the core not an extension. But should it be an extension feature?

@himanshug
Copy link
Copy Markdown
Contributor Author

removing Area - SQL makes sense now that I think about it.

I actually thought of putting the new PasswordProvider in an extension. Looked at existing aws related extensions and it did not fit in any of those , the ec2-extensions or s3-extensions . So, had put there along side other common AWS related code.

Anyways, It is totally possible to put AWSRDSTokenPasswordProvider in a new extension (aws-rds-extensions). However, BasicDataSourceExt would stay in core. I will update the PR . thanks.

@jihoonson
Copy link
Copy Markdown
Contributor

Thanks, I will review soon.

<parent>
<groupId>org.apache.druid</groupId>
<artifactId>druid</artifactId>
<version>0.18.0-SNAPSHOT</version>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind updating the version to 0.19.0-SNAPSHOT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@stale stale Bot removed the stale label Oct 26, 2020
@stale
Copy link
Copy Markdown

stale Bot commented Dec 25, 2020

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@druid.apache.org list. Thank you for your contributions.

@stale stale Bot added the stale label Dec 25, 2020
@himanshug
Copy link
Copy Markdown
Contributor Author

un-stale !

@jihoonson jihoonson removed the stale label Jan 5, 2021
Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himanshug thank you for your patience. I finally reviewed. The PR LGTM overall, but have left some comments about documentation. I'm also wondering if we can easily add some integration tests which might not be running on Travis, but can be run manually.


import java.util.List;

public class AWSModule implements DruidModule
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe AWSRDSModule?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

* This class exists so that PasswordProvider is asked for password every time a brand new connection is established
* with DB. PasswordProvider impls such as based on AWS tokens refresh the underlying token periodically since
* each token is valid for a certain period of time only.
* So, This class overrides[ummm copies] the methods from base class in order to keep track of connection properties
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, would you fix ummm copies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if there is anything to fix as of now , BasicDataSource isn't open enough for extension to let us dynamically get password from config everytime a new connection is setup.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just assumed that you wanted to add a link instead of ummm copies. It would be enough to just remove it if there is nothing to fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see :) , updated the comment to hopefully remove the link confusion

This module provides AWS RDS token [password provider](../../operations/password-provider.md) provides temp token for accessing AWS RDS DB cluster.

```json
{ "type": "awsrdstoken", "user": "USER", "host": "HOST", "port": PORT, "region": "AWS_REGION" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe aws-rds-token?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@himanshug
Copy link
Copy Markdown
Contributor Author

@jihoonson thanks, I will merge it with master and get the build to pass so as to make it merge-able.

easiest way to manually test this is to deploy coordinator node on ec2 instance if coordinator starts successfully then it is good. manual integration test should also be possible, but steps to run such integration would still be to deploy some code inside an ec2 instance which can exercise the code here. integration test would be a nice addition though as a future PR specially as and when this extension gets wider adoption.

@himanshug
Copy link
Copy Markdown
Contributor Author

@jihoonson I think it is ready now.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @himanshug!

Copy link
Copy Markdown
Member

@clintropolis clintropolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall lgtm, sorry this one slipped through the cracks for so long

}

if (driverToUse == null) {
throw new RE("WTH! Couln't find a Driver");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i think we've been trying to tone it down and be professional and shit 😛 , related #10270

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed, I thought "WTF" to "WTH" transition was that :)

~ under the License.
-->

This module provides AWS RDS token [password provider](../../operations/password-provider.md) provides temp token for accessing AWS RDS DB cluster.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent confusion, should we more explicitly call out that this is not a metadata connector itself and just provides auth to be used by the extension that is appropriate for the RDS instance type?

Copy link
Copy Markdown
Contributor Author

@himanshug himanshug Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reworded to hopefully remove the confusion

To use this extension, make sure you [include](../../development/extensions.md#loading-extensions) it in your config file:

```
druid.extensions.loadList=["druid-aws-rds-extensions"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise i guess it is unrealistic that you would have a load list with only this extension, maybe should include mysql or postgres here, though maybe this doesn't need spelled out and is ok as it is...

Comment thread server/src/main/java/org/apache/druid/metadata/BasicDataSourceExt.java Outdated
@himanshug himanshug merged commit c7b1212 into apache:master Jan 7, 2021
@himanshug
Copy link
Copy Markdown
Contributor Author

thanks @clintropolis

@jihoonson jihoonson added this to the 0.21.0 milestone Jan 8, 2021
JulianJaffePinterest pushed a commit to JulianJaffePinterest/druid that referenced this pull request Jan 22, 2021
* refresh db pwd

* aws iam token password provider

* fix analyze-dependencies build

* fix doc build

* add  ut for BasicDataSourceExt

* more doc updates

* more  doc update

* moving aws  token password  provider to new extension

* remove duplicate changes

* make  all config inline

* extension docs

* refresh db  password  in SQL Firehose code path as well

* add ut

* fix build

* add new extension to distribution

* rds lib is not provided

* fix license build

* add version to license

* change parent version to 0.19.0-snapshot

* address review comments

* fix core/ code coverage

* Update server/src/main/java/org/apache/druid/metadata/BasicDataSourceExt.java

Co-authored-by: Clint Wylie <cjwylie@gmail.com>

* address review comments

* fix spellchecker

* remove inadvertant website file change

Co-authored-by: Clint Wylie <cjwylie@gmail.com>
Comment thread licenses.yaml
Comment on lines +155 to +156
libraries:
- com.amazonaws: aws-java-sdk-rds
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @himanshug, did you adopt source code from the AWS SDK? If so, source_paths field should be added. Otherwise, license_category should be binary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source code is not copied here , I guess this should be "binary" , yes. .. will update.

}

@Override
protected ConnectionFactory createConnectionFactory() throws SQLException
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@himanshug Did you adopt this source code from org.apache.commons.dbcp2.BasicDataSource? If so, it should be added in the licenses.yaml file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, most code in this file is copied from org.apache.commons.dbcp2.BasicDataSource , will send a PR shortly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

himanshug added a commit to himanshug/druid that referenced this pull request Feb 12, 2021
jihoonson pushed a commit that referenced this pull request Mar 10, 2021
… password provider in PR #9518 (#10885)

* license.yaml fixes for code introduced related to AWS RDS token based password provider in PR #9518

* add notice for commons-dbcp in license file

* add version and update NOTICE file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants