Skip to content

Commit

Permalink
Only use accessKey and secretKey if they are not blank (#265)
Browse files Browse the repository at this point in the history
* allow for empty access key and secret key

* Simplify

---------

Co-authored-by: Basil Crow <[email protected]>
  • Loading branch information
samholton and basil authored Jan 13, 2025
1 parent 12bc4ec commit 8d05df9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ public boolean requiresToken() {
public AwsCredentials resolveCredentials() {

if (StringUtils.isBlank(iamRoleArn)) {
return AwsBasicCredentials.create(accessKey, secretKey.getPlainText());
if (StringUtils.isBlank(accessKey) && StringUtils.isBlank(secretKey.getPlainText())) {
// AWS SDK v2 does not allow blank accessKey and secretKey
return null;

Check warning on line 174 in src/main/java/com/cloudbees/jenkins/plugins/awscredentials/AWSCredentialsImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 172-174 are not covered by tests
} else {
return AwsBasicCredentials.create(accessKey, secretKey.getPlainText());
}
} else {
AwsCredentialsProvider baseProvider;
// Handle the case of delegation to instance profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ public MultiEnvironment bind(@NonNull Run<?, ?> build, FilePath workspace, Launc
AwsCredentials credentials = provider.resolveCredentials();

Map<String, String> m = new HashMap<String, String>();
m.put(accessKeyVariable, credentials.accessKeyId());
m.put(secretKeyVariable, credentials.secretAccessKey());
if (credentials != null) {

Check warning on line 142 in src/main/java/com/cloudbees/jenkins/plugins/awscredentials/AmazonWebServicesCredentialsBinding.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 142 is not covered by tests
m.put(accessKeyVariable, credentials.accessKeyId());
m.put(secretKeyVariable, credentials.secretAccessKey());
}

// If role has been assumed, STS requires AWS_SESSION_TOKEN variable set too.
if (credentials instanceof AwsSessionCredentials) {
Expand Down

0 comments on commit 8d05df9

Please sign in to comment.