Skip to content

Commit

Permalink
Revised mechanisms for getting the STS token duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Dines committed Feb 23, 2019
1 parent 51f5d4d commit 8447901
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.amazonaws.services.securitytoken.model.AssumeRoleResult;
import com.cloudbees.plugins.credentials.CredentialsDescriptor;
import com.cloudbees.plugins.credentials.CredentialsScope;
import javax.annotation.CheckForNull;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import javax.annotation.Nonnull;
import hudson.Extension;
import hudson.ProxyConfiguration;
Expand Down Expand Up @@ -74,8 +74,7 @@ public class AWSCredentialsImpl extends BaseAmazonWebServicesCredentials impleme
private final String iamRoleArn;
private final String iamMfaSerialNumber;

@CheckForNull
private Integer stsTokenDuration;
private volatile Integer stsTokenDuration;

// Old data bound constructor. It is maintained to keep binary compatibility with clients that were using it directly.
public AWSCredentialsImpl(@CheckForNull CredentialsScope scope, @CheckForNull String id,
Expand Down Expand Up @@ -141,7 +140,7 @@ public AWSCredentials getCredentials() {
}

AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn)
.withDurationSeconds(stsTokenDuration);
.withDurationSeconds(this.getStsTokenDuration());

AssumeRoleResult assumeResult = client.assumeRole(assumeRequest);

Expand All @@ -158,7 +157,7 @@ public AWSCredentials getCredentials(String mfaToken) {
AssumeRoleRequest assumeRequest = createAssumeRoleRequest(iamRoleArn)
.withSerialNumber(iamMfaSerialNumber)
.withTokenCode(mfaToken)
.withDurationSeconds(stsTokenDuration);
.withDurationSeconds(this.getStsTokenDuration());

AssumeRoleResult assumeResult = new AWSSecurityTokenServiceClient(initialCredentials).assumeRole(assumeRequest);

Expand Down

0 comments on commit 8447901

Please sign in to comment.