@@ -294,8 +294,9 @@ void STSProfileCredentialsProvider::Reload()
294
294
}
295
295
296
296
// get the role arn from the profile at the top of the stack (which hasn't been popped out yet)
297
- const auto arn = sourceProfiles.back ()->second .GetRoleArn ();
298
- const auto & assumedCreds = GetCredentialsFromSTS (stsCreds, arn);
297
+ const auto & arn = sourceProfiles.back ()->second .GetRoleArn ();
298
+ const auto & externalId = sourceProfiles.back ()->second .GetExternalId ();
299
+ const auto & assumedCreds = GetCredentialsFromSTS (stsCreds, arn, externalId);
299
300
sourceProfiles.back ()->second .SetCredentials (assumedCreds);
300
301
}
301
302
@@ -309,14 +310,18 @@ void STSProfileCredentialsProvider::Reload()
309
310
AWSCredentialsProvider::Reload ();
310
311
}
311
312
312
- AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal (const Aws::String& roleArn, Aws::STS::STSClient* client)
313
+ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal (const Aws::String& roleArn, const Aws::String& externalId, Aws::STS::STSClient* client)
313
314
{
314
315
using namespace Aws ::STS::Model;
315
316
AssumeRoleRequest assumeRoleRequest;
316
317
assumeRoleRequest
317
318
.WithRoleArn (roleArn)
318
319
.WithRoleSessionName (Aws::Utils::UUID::PseudoRandomUUID ())
319
320
.WithDurationSeconds (static_cast <int >(std::chrono::seconds (m_duration).count ()));
321
+ if (!externalId.empty ())
322
+ {
323
+ assumeRoleRequest.SetExternalId (externalId);
324
+ }
320
325
auto outcome = client->AssumeRole (assumeRoleRequest);
321
326
if (outcome.IsSuccess ())
322
327
{
@@ -334,12 +339,17 @@ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal(cons
334
339
}
335
340
336
341
AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTS (const AWSCredentials& credentials, const Aws::String& roleArn)
342
+ {
343
+ return GetCredentialsFromSTS (credentials, roleArn, " " );
344
+ }
345
+
346
+ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTS (const AWSCredentials& credentials, const Aws::String& roleArn, const Aws::String& externalId)
337
347
{
338
348
using namespace Aws ::STS::Model;
339
349
if (m_stsClientFactory) {
340
- return GetCredentialsFromSTSInternal (roleArn, m_stsClientFactory (credentials));
350
+ return GetCredentialsFromSTSInternal (roleArn, externalId m_stsClientFactory (credentials));
341
351
}
342
352
343
353
Aws::STS::STSClient stsClient {credentials};
344
- return GetCredentialsFromSTSInternal (roleArn, &stsClient);
354
+ return GetCredentialsFromSTSInternal (roleArn, externalId, &stsClient);
345
355
}
0 commit comments