@@ -316,8 +316,9 @@ void STSProfileCredentialsProvider::Reload()
316316 }
317317
318318 // 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);
321322 sourceProfiles.back ()->second .SetCredentials (assumedCreds);
322323 }
323324
@@ -331,14 +332,18 @@ void STSProfileCredentialsProvider::Reload()
331332 AWSCredentialsProvider::Reload ();
332333}
333334
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)
335336{
336337 using namespace Aws ::STS::Model;
337338 AssumeRoleRequest assumeRoleRequest;
338339 assumeRoleRequest
339340 .WithRoleArn (roleArn)
340341 .WithRoleSessionName (Aws::Utils::UUID::PseudoRandomUUID ())
341342 .WithDurationSeconds (static_cast <int >(std::chrono::seconds (m_duration).count ()));
343+ if (!externalId.empty ())
344+ {
345+ assumeRoleRequest.SetExternalId (externalId);
346+ }
342347 auto outcome = client->AssumeRole (assumeRoleRequest);
343348 if (outcome.IsSuccess ())
344349 {
@@ -356,13 +361,18 @@ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal(cons
356361}
357362
358363AWSCredentials 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)
359369{
360370 using namespace Aws ::STS::Model;
361371 if (m_stsClientFactory) {
362372 auto client = m_stsClientFactory (credentials);
363- return GetCredentialsFromSTSInternal (roleArn, client.get ());
373+ return GetCredentialsFromSTSInternal (roleArn, externalId, client.get ());
364374 }
365375
366376 Aws::STS::STSClient stsClient {credentials};
367- return GetCredentialsFromSTSInternal (roleArn, &stsClient);
377+ return GetCredentialsFromSTSInternal (roleArn, externalId, &stsClient);
368378}
0 commit comments