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

Unify S3 client creation logic #1657

Merged
merged 5 commits into from
Aug 30, 2023
Merged

Unify S3 client creation logic #1657

merged 5 commits into from
Aug 30, 2023

Conversation

rosecodym
Copy link
Collaborator

@rosecodym rosecodym commented Aug 23, 2023

Description

This PR unifies some code paths within the S3 source. This is being done to better support a future implementation of S3 source validation; less code that runs means less code to validate. The logical change is to move the handling of "role-less" operation down the call tree, which allows for a single code path for more of the S3 code.

This PR also fixes a bug that would occur in the (rare) case that the source couldn't create a regional S3 client. Before, an error would be logged, but it would be followed by a panic. Now the bucket in question is skipped.

Base automatically changed from test-s3-role-assume to main August 25, 2023 15:30
@rosecodym rosecodym marked this pull request as ready for review August 28, 2023 19:24
@rosecodym rosecodym requested a review from a team as a code owner August 28, 2023 19:24
@rosecodym
Copy link
Collaborator Author

@codevbus this is a refactor of a feature you added so shout if anything looks incorrectly implemented

Copy link
Collaborator

@mcastorina mcastorina left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +131 to +134
stsClient := sts.New(sess)
cfg.Credentials = stscreds.NewCredentialsWithClient(stsClient, roleArn, func(p *stscreds.AssumeRoleProvider) {
p.RoleSessionName = "trufflehog"
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit (optional): This would be equivalent:

cfg.Credentials = stscreds.NewCredentials(sess, roleArn, func(p *stscreds.AssumeRoleProvider) {
    p.RoleSessionName = "trufflehog"
})

Comment on lines +216 to +219
roles := s.conn.Roles
if len(roles) == 0 {
roles = []string{""}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, this means we won't do the non-ARN scan of a bucket if any ARNs are given. Just confirming that's the expected behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, that's the existing behavior. the check is here.

@rosecodym rosecodym merged commit a2c0abb into main Aug 30, 2023
9 checks passed
@rosecodym rosecodym deleted the unify-s3-client-creation branch August 30, 2023 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants