@@ -294,8 +294,9 @@ void STSProfileCredentialsProvider::Reload()
294294 }
295295
296296 // 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);
299300 sourceProfiles.back ()->second .SetCredentials (assumedCreds);
300301 }
301302
@@ -309,14 +310,18 @@ void STSProfileCredentialsProvider::Reload()
309310 AWSCredentialsProvider::Reload ();
310311}
311312
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)
313314{
314315 using namespace Aws ::STS::Model;
315316 AssumeRoleRequest assumeRoleRequest;
316317 assumeRoleRequest
317318 .WithRoleArn (roleArn)
318319 .WithRoleSessionName (Aws::Utils::UUID::PseudoRandomUUID ())
319320 .WithDurationSeconds (static_cast <int >(std::chrono::seconds (m_duration).count ()));
321+ if (!externalId.empty ())
322+ {
323+ assumeRoleRequest.SetExternalId (externalId);
324+ }
320325 auto outcome = client->AssumeRole (assumeRoleRequest);
321326 if (outcome.IsSuccess ())
322327 {
@@ -334,12 +339,17 @@ AWSCredentials STSProfileCredentialsProvider::GetCredentialsFromSTSInternal(cons
334339}
335340
336341AWSCredentials 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)
337347{
338348 using namespace Aws ::STS::Model;
339349 if (m_stsClientFactory) {
340- return GetCredentialsFromSTSInternal (roleArn, m_stsClientFactory (credentials));
350+ return GetCredentialsFromSTSInternal (roleArn, externalId m_stsClientFactory (credentials));
341351 }
342352
343353 Aws::STS::STSClient stsClient {credentials};
344- return GetCredentialsFromSTSInternal (roleArn, &stsClient);
354+ return GetCredentialsFromSTSInternal (roleArn, externalId, &stsClient);
345355}
0 commit comments