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

Ensure master credentials are refreshed before refreshing temporary credentials #1389

Merged
merged 2 commits into from
Mar 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions lib/credentials.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ export class Credentials {
/**
* AWS access key ID.
*/
accessKeyId: string
accessKeyId: string;
/**
* Whether the credentials have been expired and require a refresh.
* Used in conjunction with expireTime.
*/
expired: boolean
expired: boolean;
/**
* Time when credentials should be considered expired.
* Used in conjunction with expired.
*/
expireTime: Date
static expiryWindow: number
expireTime: Date;
static expiryWindow: number;
/**
* AWS secret access key.
*/
secretAccessKey: string
secretAccessKey: string;
/**
* AWS session token.
*/
sessionToken: string
sessionToken: string;
}

interface CredentialsOptions {
Expand All @@ -71,4 +71,4 @@ interface CredentialsOptions {
* AWS session token.
*/
sessionToken?: string
}
}
22 changes: 14 additions & 8 deletions lib/credentials/temporary_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ AWS.TemporaryCredentials = AWS.util.inherit(AWS.Credentials, {
self.createClients();
if (!callback) callback = function(err) { if (err) throw err; };

self.service.config.credentials = self.masterCredentials;
var operation = self.params.RoleArn ?
self.service.assumeRole : self.service.getSessionToken;
operation.call(self.service, function (err, data) {
if (!err) {
self.service.credentialsFrom(data, self);
}
callback(err);
self.masterCredentials.get(function() {
self.service.config.credentials = self.masterCredentials;
var operation = self.params.RoleArn ?
self.service.assumeRole : self.service.getSessionToken;
operation.call(self.service, function (err, data) {
if (!err) {
self.service.credentialsFrom(data, self);
}
callback(err);
});
});
},

Expand All @@ -102,6 +104,10 @@ AWS.TemporaryCredentials = AWS.util.inherit(AWS.Credentials, {
while (this.masterCredentials.masterCredentials) {
this.masterCredentials = this.masterCredentials.masterCredentials;
}

if (typeof this.masterCredentials.get !== 'function') {
this.masterCredentials = new AWS.Credentials(this.masterCredentials);
}
},

/**
Expand Down
12 changes: 12 additions & 0 deletions test/credentials.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,18 @@ describe 'AWS.TemporaryCredentials', ->
creds.refresh ->
expect(spy.calls.length).to.equal(4)

it 'should refresh expired master credentials when refreshing self', ->
masterCreds = new AWS.Credentials('akid', 'secret')
masterCreds.expired = true;
refreshSpy = helpers.spyOn(masterCreds, 'refresh')

creds = new AWS.TemporaryCredentials({RoleArn: 'ARN'}, masterCreds);
creds.createClients()
mockSTS(new Date(AWS.util.date.getDate().getTime() + 100000),
RoleArn: 'ARN', RoleSessionName: 'temporary-credentials')
creds.refresh(->)
expect(refreshSpy.calls.length).to.equal(1)

describe 'AWS.WebIdentityCredentials', ->
creds = null

Expand Down