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

[FEATURE] Use STS to receive a temporary credentials role session #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MurraySpeight
Copy link

#11

Configuring a role will assume an IAM role by using AWS Security Token Service. This is more secure than using a long-term password or access key credentials. A session has a limited duration, which reduces the risk if the credentials are compromised.
@MurraySpeight MurraySpeight changed the title Issue 11 [FEATURE] Use STS to receive a temporary credentials role session May 24, 2022
@duskobogdanovski
Copy link
Member

Hey @MurraySpeight, thank you for your contribution, could you please check and fix the code quality and also please add some tests that cover the new functionality?

RoleArn=self.role,
RoleSessionName="CkanExtS3Session")
credentials = assumed_role_object['Credentials']
return boto3.session.Session(
Copy link
Contributor

@ThrawnCA ThrawnCA Jun 8, 2022

Choose a reason for hiding this comment

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

Perhaps assign this to session (which is about to be returned) instead of returning it directly, so there's only a single exit point?

Or change line 71 into a guard clause, "if no role specified then return immediately".

Copy link
Author

Choose a reason for hiding this comment

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

I think you've missed the part where the initial session is used to communicate with STS if there is a role configured. So in this case both sessions are needed but only the one that has the assumed role is returned to be used for communicating with S3.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I didn't miss that. I'm just suggesting that it's more readable to assign and then return, instead of having two separate return statements.

(Having only one exit from a function is more of a guideline than a hard rule, but it's not a bad guideline when it's convenient.)

@MurraySpeight
Copy link
Author

Hey @MurraySpeight, thank you for your contribution, could you please check and fix the code quality and also please add some tests that cover the new functionality?

I've fixed the lint issue. I can't see how this test would be written based on what is there so I'm not going to be able to add a test case for this.

@ThrawnCA
Copy link
Contributor

I can't see how this test would be written based on what is there so I'm not going to be able to add a test case for this.

Perhaps you could mock out the assume_role function to at least test whether it's reached? Which would allow you to test the behaviour when ckanext.s3filestore.aws_role is populated/absent/blank/whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants