Skip to content

Add IAM roles login #976

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void initialize() throws Exception {
this.folder = folder;

this.client = buildS3Client(accessKey, secretKey, endpointValue, clientRegion);
this.presigner = buildS3Presinger(accessKey, secretKey, clientRegion);
this.presigner = buildS3Presigner(accessKey, secretKey, clientRegion);
bucketExists();
}
}
Expand All @@ -131,21 +131,20 @@ private S3Client buildS3Client(String accessKey, String secretKey, String endpoi

boolean bUseIAM = !getPropertyValue(USE_IAM, "", "").isEmpty() || (accessKey.equals("") && secretKey.equals(""));

S3ClientBuilder builder = bUseIAM ?
S3Client.builder() :
S3Client.builder().credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
)
);
S3ClientBuilder builder = bUseIAM
? S3Client.builder().credentialsProvider(DefaultCredentialsProvider.create())
: S3Client.builder().credentialsProvider(
StaticCredentialsProvider.create(
AwsBasicCredentials.create(accessKey, secretKey)
)
);

if (bUseIAM) {
logger.debug("Using IAM Credentials");
}

if (!endpoint.isEmpty() && !endpoint.contains(".amazonaws.com")) {
pathStyleUrls = true;

s3Client = builder
.endpointOverride(URI.create(endpoint))
.region(Region.of(region))
Expand Down Expand Up @@ -181,11 +180,22 @@ private S3Client buildS3Client(String accessKey, String secretKey, String endpoi
return s3Client;
}

private S3Presigner buildS3Presinger(String accessKey, String secretKey, String region) {
return S3Presigner.builder()
private S3Presigner buildS3Presigner(String accessKey, String secretKey, String region) {
boolean bUseIAM = !getPropertyValue(USE_IAM, "", "").isEmpty() || (accessKey.equals("") && secretKey.equals(""));

S3Presigner.Builder builder = S3Presigner.builder()
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
.build();
.credentialsProvider(
bUseIAM
? DefaultCredentialsProvider.create()
: StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey))
);

if (bUseIAM) {
logger.debug("Using IAM Credentials for presigner");
}

return builder.build();
}

private void bucketExists() {
Expand Down
Loading