Skip to content

Commit 112315f

Browse files
committed
add account id to supproted identity providers
1 parent 1bd5bdf commit 112315f

File tree

13 files changed

+128
-17
lines changed

13 files changed

+128
-17
lines changed

src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentials.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ namespace Aws
5454
{
5555
}
5656

57+
/**
58+
* Initializes object with accessKeyId, secretKey, sessionToken, expiration date and account Id.
59+
*/
60+
AWSCredentials(const Aws::String& accessKeyId,
61+
const Aws::String& secretKey,
62+
const Aws::String& sessionToken,
63+
Aws::Utils::DateTime expiration,
64+
const Aws::String& accountId)
65+
: m_accessKeyId(accessKeyId),
66+
m_secretKey(secretKey),
67+
m_sessionToken(sessionToken),
68+
m_expiration(expiration),
69+
m_accountId(accountId) {}
70+
5771
bool operator == (const AWSCredentials& other) const
5872
{
5973
return m_accessKeyId == other.m_accessKeyId
@@ -109,6 +123,14 @@ namespace Aws
109123
return m_expiration;
110124
}
111125

126+
/**
127+
* Gets the underlying account id
128+
*/
129+
inline const Aws::String GetAccountId() const
130+
{
131+
return m_accountId;
132+
}
133+
112134
/**
113135
* Sets the underlying access key credential. Copies from parameter accessKeyId.
114136
*/
@@ -133,6 +155,14 @@ namespace Aws
133155
m_sessionToken = sessionToken;
134156
}
135157

158+
/**
159+
* Sets the underlying account id. Copies from parameter accountId
160+
*/
161+
inline void SetAccountId(const Aws::String& accountId)
162+
{
163+
m_accountId = accountId;
164+
}
165+
136166

137167
/**
138168
* Sets the underlying access key credential. Copies from parameter accessKeyId.
@@ -158,6 +188,14 @@ namespace Aws
158188
m_sessionToken = sessionToken;
159189
}
160190

191+
/**
192+
* Sets the underlying account id. Copies from parameter accountId
193+
*/
194+
inline void SetExpiration(const char* accountId)
195+
{
196+
m_accountId = accountId;
197+
}
198+
161199
/**
162200
* Sets the expiration date of the credential
163201
*/
@@ -171,6 +209,7 @@ namespace Aws
171209
Aws::String m_secretKey;
172210
Aws::String m_sessionToken;
173211
Aws::Utils::DateTime m_expiration;
212+
Aws::String m_accountId;
174213
};
175214
}
176215
}

src/aws-cpp-sdk-core/include/smithy/identity/identity/AwsCredentialIdentity.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ namespace smithy {
1212
AwsCredentialIdentity(const Aws::String& accessKeyId,
1313
const Aws::String& secretAccessKey,
1414
const Aws::Crt::Optional<Aws::String>& sessionToken,
15-
const Aws::Crt::Optional<AwsIdentity::DateTime>& expiration)
16-
: m_accessKeyId(accessKeyId), m_secretAccessKey(secretAccessKey),
17-
m_sessionToken(sessionToken), m_expiration(expiration) {}
15+
const Aws::Crt::Optional<AwsIdentity::DateTime>& expiration,
16+
const Aws::Crt::Optional<Aws::String>& accountId)
17+
: m_accessKeyId(accessKeyId),
18+
m_secretAccessKey(secretAccessKey),
19+
m_sessionToken(sessionToken),
20+
m_expiration(expiration),
21+
m_accountId({accountId}) {}
1822

1923
Aws::String accessKeyId() const override;
2024
Aws::String secretAccessKey() const override;
2125
Aws::Crt::Optional<Aws::String> sessionToken() const override;
2226
Aws::Crt::Optional<AwsIdentity::DateTime> expiration() const override;
27+
Aws::Crt::Optional<Aws::String> accountId() const override;
2328

2429
protected:
2530
Aws::String m_accessKeyId;
2631
Aws::String m_secretAccessKey;
2732
Aws::Crt::Optional<Aws::String> m_sessionToken;
2833
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
34+
Aws::Crt::Optional<Aws::String> m_accountId;
2935
};
3036
}
3137

src/aws-cpp-sdk-core/include/smithy/identity/identity/AwsIdentity.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ namespace smithy {
1717
virtual Aws::Crt::Optional<DateTime> expiration() const {
1818
return Aws::Crt::Optional<DateTime>();
1919
};
20+
21+
virtual Aws::Crt::Optional<Aws::String> accountId() const {
22+
return Aws::Crt::Optional<Aws::String>{};
23+
}
2024
};
2125
}

src/aws-cpp-sdk-core/include/smithy/identity/identity/impl/AwsCredentialIdentityImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ namespace smithy {
2323
inline Aws::Crt::Optional<AwsIdentity::DateTime> AwsCredentialIdentity::expiration() const {
2424
return m_expiration;
2525
}
26+
27+
inline Aws::Crt::Optional<Aws::String> AwsCredentialIdentity::accountId() const {
28+
return m_sessionToken;
29+
}
2630
}

src/aws-cpp-sdk-core/include/smithy/identity/resolver/built-in/AwsCredentialsProviderIdentityResolver.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ namespace smithy
3535

3636
const auto fetchedCreds = m_credentialsProvider->GetAWSCredentials();
3737

38-
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("DefaultAwsCredentialIdentityResolver",
39-
fetchedCreds.GetAWSAccessKeyId(), fetchedCreds.GetAWSSecretKey(),
40-
fetchedCreds.GetSessionToken(), fetchedCreds.GetExpiration());
38+
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("AwsCredentialsProviderIdentityResolver",
39+
fetchedCreds.GetAWSAccessKeyId(),
40+
fetchedCreds.GetAWSSecretKey(),
41+
fetchedCreds.GetSessionToken(),
42+
fetchedCreds.GetExpiration(),
43+
fetchedCreds.GetAccountId());
4144

4245
return {std::move(smithyCreds)};
4346
}

src/aws-cpp-sdk-core/include/smithy/identity/resolver/built-in/DefaultAwsCredentialIdentityResolver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ namespace smithy {
4949
legacyCreds.GetAWSAccessKeyId(),
5050
legacyCreds.GetAWSSecretKey(),
5151
legacyCreds.GetSessionToken().empty()? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetSessionToken(),
52-
legacyCreds.GetExpiration());
52+
legacyCreds.GetExpiration(),
53+
legacyCreds.GetAccountId().empty()? Aws::Crt::Optional<Aws::String>() : legacyCreds.GetSessionToken());
5354

5455
return ResolveIdentityFutureOutcome(std::move(smithyCreds));
5556
}

src/aws-cpp-sdk-core/include/smithy/identity/resolver/built-in/SimpleAwsCredentialIdentityResolver.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ namespace smithy
3333
AWS_UNREFERENCED_PARAM(identityProperties);
3434
AWS_UNREFERENCED_PARAM(additionalParameters);
3535

36-
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("DefaultAwsCredentialIdentityResolver",
37-
m_credentials.GetAWSAccessKeyId(), m_credentials.GetAWSSecretKey(),
38-
m_credentials.GetSessionToken(), m_credentials.GetExpiration());
36+
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("SimpleAwsCredentialIdentityResolver",
37+
m_credentials.GetAWSAccessKeyId(),
38+
m_credentials.GetAWSSecretKey(),
39+
m_credentials.GetSessionToken().empty()? Aws::Crt::Optional<Aws::String>() : m_credentials.GetSessionToken(),
40+
m_credentials.GetExpiration(),
41+
m_credentials.GetAccountId().empty()? Aws::Crt::Optional<Aws::String>() : m_credentials.GetAccountId());
3942

4043
return {std::move(smithyCreds)};
4144
}

src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using Aws::Utils::Threading::WriterLockGuard;
3636
static const char ACCESS_KEY_ENV_VAR[] = "AWS_ACCESS_KEY_ID";
3737
static const char SECRET_KEY_ENV_VAR[] = "AWS_SECRET_ACCESS_KEY";
3838
static const char SESSION_TOKEN_ENV_VAR[] = "AWS_SESSION_TOKEN";
39+
static const char ACCOUNT_ID_ENV_VAR[] = "AWS_ACCOUNT_ID";
3940
static const char DEFAULT_PROFILE[] = "default";
4041
static const char AWS_PROFILE_ENV_VAR[] = "AWS_PROFILE";
4142
static const char AWS_PROFILE_DEFAULT_ENV_VAR[] = "AWS_DEFAULT_PROFILE";
@@ -91,6 +92,14 @@ AWSCredentials EnvironmentAWSCredentialsProvider::GetAWSCredentials()
9192
credentials.SetSessionToken(sessionToken);
9293
AWS_LOGSTREAM_DEBUG(ENVIRONMENT_LOG_TAG, "Found sessionToken");
9394
}
95+
96+
const auto accountId = Aws::Environment::GetEnv(ACCOUNT_ID_ENV_VAR);
97+
98+
if (!accountId.empty())
99+
{
100+
credentials.SetAccountId(accountId);
101+
AWS_LOGSTREAM_DEBUG(ENVIRONMENT_LOG_TAG, "Found accountId");
102+
}
94103
}
95104

96105
return credentials;
@@ -409,6 +418,11 @@ AWSCredentials Aws::Auth::GetCredentialsFromProcess(const Aws::String& process)
409418
credentials.SetExpiration((std::chrono::time_point<std::chrono::system_clock>::max)());
410419
}
411420

421+
if (credentialsView.KeyExists("AccountId"))
422+
{
423+
credentials.SetAccountId(credentialsView.GetString("AccountId"));
424+
}
425+
412426
AWS_LOGSTREAM_DEBUG(PROFILE_LOG_TAG, "Successfully pulled credentials from process credential with AccessKey: " << accessKey << ", Expiration:" << credentialsView.GetString("Expiration"));
413427
return credentials;
414428
}

src/aws-cpp-sdk-core/source/auth/GeneralHTTPCredentialsProvider.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,19 @@ void GeneralHTTPCredentialsProvider::Reload()
232232
return;
233233
}
234234

235-
Aws::String accessKey, secretKey, token;
235+
Aws::String accessKey, secretKey, token, accountId;
236236
Utils::Json::JsonView credentialsView(credentialsDoc);
237237
accessKey = credentialsView.GetString("AccessKeyId");
238238
secretKey = credentialsView.GetString("SecretAccessKey");
239239
token = credentialsView.GetString("Token");
240+
accountId = credentialsView.GetString("AccountId");
240241
AWS_LOGSTREAM_DEBUG(GEN_HTTP_LOG_TAG, "Successfully pulled credentials from metadata service with access key " << accessKey);
241242

242243
m_credentials.SetAWSAccessKeyId(accessKey);
243244
m_credentials.SetAWSSecretKey(secretKey);
244245
m_credentials.SetSessionToken(token);
245246
m_credentials.SetExpiration(Aws::Utils::DateTime(credentialsView.GetString("Expiration"), Aws::Utils::DateFormat::ISO_8601));
247+
m_credentials.SetAccountId(accountId);
246248
AWSCredentialsProvider::Reload();
247249
}
248250

src/aws-cpp-sdk-core/source/config/AWSConfigFileProfileConfigLoader.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Aws
2121
static const char ACCESS_KEY_ID_KEY[] = "aws_access_key_id";
2222
static const char SECRET_KEY_KEY[] = "aws_secret_access_key";
2323
static const char SESSION_TOKEN_KEY[] = "aws_session_token";
24+
static const char ACCOUNT_ID_KEY[] = "aws_account_id";
2425
static const char SSO_START_URL_KEY[] = "sso_start_url";
2526
static const char SSO_REGION_KEY[] = "sso_region";
2627
static const char SSO_ACCOUNT_ID_KEY[] = "sso_account_id";
@@ -445,7 +446,7 @@ namespace Aws
445446
}
446447

447448
auto accessKeyIdIter = currentKeyValues.find(ACCESS_KEY_ID_KEY);
448-
Aws::String accessKey, secretKey, sessionToken;
449+
Aws::String accessKey, secretKey, sessionToken, accountId;
449450
if (accessKeyIdIter != currentKeyValues.end())
450451
{
451452
accessKey = accessKeyIdIter->second;
@@ -467,7 +468,18 @@ namespace Aws
467468
sessionToken = sessionTokenIter->second;
468469
}
469470

470-
profile.SetCredentials(Aws::Auth::AWSCredentials(accessKey, secretKey, sessionToken));
471+
const auto accountIdIter = currentKeyValues.find(ACCOUNT_ID_KEY);
472+
473+
if (accountIdIter != currentKeyValues.end())
474+
{
475+
accountId = accountIdIter->second;
476+
}
477+
478+
profile.SetCredentials(Aws::Auth::AWSCredentials(accessKey,
479+
secretKey,
480+
sessionToken,
481+
DateTime{},
482+
accountId));
471483
}
472484

473485
if (!profile.GetSsoStartUrl().empty() || !profile.GetSsoRegion().empty()

0 commit comments

Comments
 (0)