@@ -316,8 +316,9 @@ void STSProfileCredentialsProvider::Reload()
316
316
}
317
317
318
318
// get the role arn from the profile at the top of the stack (which hasn't been popped out yet)
319
- const auto arn = sourceProfiles.back ()->second .GetRoleArn ();
320
- const auto & assumedCreds = GetCredentialsFromSTS (stsCreds, arn);
319
+ const auto & arn = sourceProfiles.back ()->second .GetRoleArn ();
320
+ const auto & externalId = sourceProfiles.back ()->second .GetExternalId ();
321
+ const auto & assumedCreds = GetCredentialsFromSTS (stsCreds, arn, externalId);
321
322
sourceProfiles.back ()->second .SetCredentials (assumedCreds);
322
323
}
323
324
@@ -331,14 +332,18 @@ void STSProfileCredentialsProvider::Reload()
331
332
AWSCredentialsProvider::Reload ();
332
333
}
333
334
334
- AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal (const Aws::String& roleArn, Aws::STS::STSClient* client)
335
+ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal (const Aws::String& roleArn, const Aws::String& externalId, Aws::STS::STSClient* client)
335
336
{
336
337
using namespace Aws ::STS::Model;
337
338
AssumeRoleRequest assumeRoleRequest;
338
339
assumeRoleRequest
339
340
.WithRoleArn (roleArn)
340
341
.WithRoleSessionName (Aws::Utils::UUID::PseudoRandomUUID ())
341
342
.WithDurationSeconds (static_cast <int >(std::chrono::seconds (m_duration).count ()));
343
+ if (!externalId.empty ())
344
+ {
345
+ assumeRoleRequest.SetExternalId (externalId);
346
+ }
342
347
auto outcome = client->AssumeRole (assumeRoleRequest);
343
348
if (outcome.IsSuccess ())
344
349
{
@@ -356,13 +361,18 @@ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal(cons
356
361
}
357
362
358
363
AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTS (const AWSCredentials& credentials, const Aws::String& roleArn)
364
+ {
365
+ return GetCredentialsFromSTS (credentials, roleArn, " " );
366
+ }
367
+
368
+ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTS (const AWSCredentials& credentials, const Aws::String& roleArn, const Aws::String& externalId)
359
369
{
360
370
using namespace Aws ::STS::Model;
361
371
if (m_stsClientFactory) {
362
372
auto client = m_stsClientFactory (credentials);
363
- return GetCredentialsFromSTSInternal (roleArn, client.get ());
373
+ return GetCredentialsFromSTSInternal (roleArn, externalId, client.get ());
364
374
}
365
375
366
376
Aws::STS::STSClient stsClient {credentials};
367
- return GetCredentialsFromSTSInternal (roleArn, &stsClient);
377
+ return GetCredentialsFromSTSInternal (roleArn, externalId, &stsClient);
368
378
}
0 commit comments