-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
added option to specify profile when connecting to redshift via IAM #2581
Changes from 4 commits
71846c9
df894f9
0532103
78445f9
bd34dfe
65c1567
0c878a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class RedshiftCredentials(PostgresCredentials): | |
default=None, | ||
metadata={'description': 'If using IAM auth, the name of the cluster'}, | ||
) | ||
iam_profile: Optional[str] = None | ||
iam_duration_seconds: int = 900 | ||
search_path: Optional[str] = None | ||
keepalives_idle: int = 240 | ||
|
@@ -56,7 +57,12 @@ def type(self): | |
|
||
def _connection_keys(self): | ||
keys = super()._connection_keys() | ||
return keys + ('method', 'cluster_id', 'iam_duration_seconds') | ||
return keys + ( | ||
'method', | ||
'cluster_id', | ||
'iam_profile', | ||
'iam_duration_seconds' | ||
) | ||
|
||
|
||
class RedshiftConnectionManager(PostgresConnectionManager): | ||
|
@@ -87,10 +93,21 @@ def fresh_transaction(self, name=None): | |
|
||
@classmethod | ||
def fetch_cluster_credentials(cls, db_user, db_name, cluster_id, | ||
duration_s, autocreate, db_groups): | ||
iam_profile, duration_s, autocreate, | ||
db_groups): | ||
"""Fetches temporary login credentials from AWS. The specified user | ||
must already exist in the database, or else an error will occur""" | ||
boto_client = boto3.client('redshift') | ||
|
||
if iam_profile is None: | ||
boto_client = boto3.client('redshift') | ||
else: | ||
logger.debug("Connecting to Redshift using 'IAM'" + | ||
f"with profile {iam_profile}") | ||
boto_session = boto3.Session( | ||
profile_name=iam_profile, | ||
region_name='eu-west-1' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we may not want to hard-code this region name here. Do you think this should be an option in the profile? Or even better, can we document that the region should be specified in the configured AWS IAM profile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ops, my bad, I didn't mean to add that, just pushed the fix. Yea, I think everything should be specified in the profile. Is there a repo for the user documentation? Couldn't find anything in the dbt repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation is maintained in this repository: https://github.com/fishtown-analytics/docs.getdbt.com/ |
||
) | ||
boto_client = boto_session.client('redshift') | ||
|
||
try: | ||
return boto_client.get_cluster_credentials( | ||
|
@@ -123,6 +140,7 @@ def get_tmp_iam_cluster_credentials(cls, credentials): | |
credentials.user, | ||
credentials.database, | ||
credentials.cluster_id, | ||
credentials.iam_profile, | ||
iam_duration_s, | ||
credentials.autocreate, | ||
credentials.db_groups, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding this
### Next
section at the top, can you add a### Features
section under the## dbt 0.18.0 (Release TBD)
line, and add your line there? Please also add a link to the issue/PR, like the other features listed!Also, please add a new contributors section to the
## dbt 0.18.0 (Release TBD)
section with your username and a link here. Check out lower down in the file for the exact formatting!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!