-
Notifications
You must be signed in to change notification settings - Fork 9
feat: option to assume role to get credentials #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
36a3dd9
bed7137
22b1a17
89310a9
abfbd23
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 |
|---|---|---|
|
|
@@ -27,3 +27,4 @@ MANIFEST | |
| # Environments | ||
| .venv | ||
| venv/ | ||
| .idea/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,13 +156,7 @@ def get_password(self, service, username): | |
| name=repository_name, | ||
| ) | ||
|
|
||
| # Create session with any supplied configuration. | ||
| session = boto3.Session( | ||
| region_name=region, | ||
| profile_name=config.get("profile_name"), | ||
| aws_access_key_id=config.get("aws_access_key_id"), | ||
| aws_secret_access_key=config.get("aws_secret_access_key"), | ||
| ) | ||
| session = self.get_boto_session(region=region, config=config) | ||
|
Owner
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. As part of 537fe6f, I've created a |
||
|
|
||
| # Create a CodeArtifact client for this repository's region. | ||
| client = session.client("codeartifact", region_name=region) | ||
|
|
@@ -193,3 +187,30 @@ def set_password(self, service, username, password): | |
| def delete_password(self, service, username): | ||
| # Defer deleting a password to the next backend | ||
| raise NotImplementedError() | ||
|
|
||
| @staticmethod | ||
| def get_boto_session(*, region, config): | ||
| should_assume_role = config.get("assume_role") | ||
|
|
||
| # Create session with any supplied configuration. | ||
| session = boto3.Session( | ||
| region_name=region, | ||
| profile_name=config.get("profile_name"), | ||
| aws_access_key_id=config.get("aws_access_key_id"), | ||
| aws_secret_access_key=config.get("aws_secret_access_key"), | ||
| ) | ||
|
|
||
| if should_assume_role is not None: | ||
| assumed_role = session.client("sts").assume_role( | ||
| RoleArn=config["assume_role"], | ||
| RoleSessionName=config.get( | ||
| "assume_role_session_name", "KeyRingsCodeArtifact" | ||
|
Author
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. So the AWS SDK will not pick a
Owner
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. As mentioned in a comment, I'd like this fallback to be a dynamic value usable for auditing in CloudTrail, but that's not required for this PR. |
||
| ), | ||
| ) | ||
| return boto3.Session( | ||
| aws_access_key_id=assumed_role["Credentials"]["AccessKeyId"], | ||
| aws_secret_access_key=assumed_role["Credentials"]["SecretAccessKey"], | ||
| aws_session_token=assumed_role["Credentials"]["SessionToken"], | ||
| ) | ||
|
|
||
| return session | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pytest >= 6 | ||
| pytest-cov | ||
| pytest-mock | ||
|
Owner
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. This shouldn't be necessary with the recent unit test modifications. |
||
|
Owner
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 recent changes to the unit tests in 537fe6f may help clean up these tests. |
Uh oh!
There was an error while loading. Please reload this page.
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.
I'd like to rename this to
assume_role_arnto be more explicit about the content it contains.