Skip to content

Commit 848b721

Browse files
committed
update unit test. add additional entries to credential profile type detector
1 parent f5e4973 commit 848b721

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

generator/.DevConfigs/b24980c4-b6f6-4181-9789-fda85df054a3.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"core": {
33
"changeLogMessages": [
4-
"[Breaking Change] Allow source_profile to be used in conjunction with sso_session. If the profile specified via source_profile has sso_session, credentials will be retrieved from sso. The sso credentials will then be used to assume the role specified in the original profile. Previous behavior was that it assumed the role specified in source_profile, which is incorrect."
4+
"[Breaking Change] Allow source_profile to be used in conjunction with sso_session. If the profile specified via source_profile has sso_session, and the sso_session section is correctly configured, credentials will be retrieved from sso. The sso credentials will then be used to assume the role specified in the original profile. Previous behavior was that it assumed the role specified in source_profile, which does not follow the assume role profile chaining pattern."
55
],
66
"type": "patch",
77
"updateMinimum": true

sdk/src/Core/Amazon.Runtime/CredentialManagement/Internal/CredentialProfileTypeDetector.cs

+31-4
Original file line numberDiff line numberDiff line change
@@ -106,83 +106,107 @@ public static class CredentialProfileTypeDetector
106106
{
107107
new HashSet<string> { RoleArn, SourceProfile },
108108
new HashSet<string> { RoleArn, SourceProfile, AwsAccountId },
109+
new HashSet<string> { RoleArn, SourceProfile, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
110+
new HashSet<string> { RoleArn, SourceProfile, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
109111
}
110112
},
111113
{
112114
CredentialProfileType.AssumeRoleMFA, new List<HashSet<string>>()
113115
{
114116
new HashSet<string> { MfaSerial, RoleArn, SourceProfile },
117+
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
115118
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, AwsAccountId },
119+
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
116120
}
117121
},
118122
{
119123
CredentialProfileType.AssumeRoleMFASessionName, new List<HashSet<string>>()
120124
{
121125
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, RoleSessionName },
126+
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
122127
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, RoleSessionName, AwsAccountId },
128+
new HashSet<string> { MfaSerial, RoleArn, SourceProfile, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl }
123129
}
124130
},
125131
{
126132
CredentialProfileType.AssumeRoleExternalMFA, new List<HashSet<string>>()
127133
{
128-
new HashSet<string> { ExternalID, RoleArn, SourceProfile, MfaSerial }
134+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, MfaSerial },
135+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, MfaSerial, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl }
129136
}
130137
},
131138
{
132139
CredentialProfileType.AssumeRoleExternal, new List<HashSet<string>>()
133140
{
134141
new HashSet<string> { ExternalID, RoleArn, SourceProfile },
142+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
135143
new HashSet<string> { ExternalID, RoleArn, SourceProfile, AwsAccountId },
144+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl}
136145
}
137146
},
138147
{
139148
CredentialProfileType.AssumeRoleSessionName, new List<HashSet<string>>()
140149
{
141150
new HashSet<string> { RoleArn, SourceProfile, RoleSessionName },
151+
new HashSet<string> { RoleArn, SourceProfile, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl},
142152
new HashSet<string> { RoleArn, SourceProfile, RoleSessionName, AwsAccountId },
153+
new HashSet<string> { RoleArn, SourceProfile, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
143154
}
144155
},
145156
{
146157
CredentialProfileType.AssumeRoleExternalSessionName, new List<HashSet<string>>()
147158
{
148159
new HashSet<string> { ExternalID, RoleArn, SourceProfile, RoleSessionName },
160+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
149161
new HashSet<string> { ExternalID, RoleArn, SourceProfile, RoleSessionName, AwsAccountId },
162+
new HashSet<string> { ExternalID, RoleArn, SourceProfile, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
150163
}
151164
},
152165
{
153166
CredentialProfileType.AssumeRoleExternalMFASessionName, new List<HashSet<string>>()
154167
{
155168
new HashSet<string> { ExternalID, MfaSerial, RoleArn, SourceProfile, RoleSessionName },
169+
new HashSet<string> { ExternalID, MfaSerial, RoleArn, SourceProfile, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
156170
new HashSet<string> { ExternalID, MfaSerial, RoleArn, SourceProfile, RoleSessionName, AwsAccountId },
171+
new HashSet<string> { ExternalID, MfaSerial, RoleArn, SourceProfile, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
157172
}
158173
},
159174
{
160175
CredentialProfileType.AssumeRoleCredentialSource, new List<HashSet<string>>()
161176
{
162177
new HashSet<string> { RoleArn, CredentialSource },
163-
new HashSet<string> { RoleArn, CredentialSource, AwsAccountId }
178+
new HashSet<string> { RoleArn, CredentialSource, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
179+
new HashSet<string> { RoleArn, CredentialSource, AwsAccountId },
180+
new HashSet<string> { RoleArn, CredentialSource, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl }
164181
}
165182
},
166183
{
167184
CredentialProfileType.AssumeRoleCredentialSourceSessionName, new List<HashSet<string>>()
168185
{
169186
new HashSet<string> { RoleArn, CredentialSource, RoleSessionName },
187+
new HashSet<string> { RoleArn, CredentialSource, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
170188
new HashSet<string> { RoleArn, CredentialSource, RoleSessionName, AwsAccountId},
189+
new HashSet<string> { RoleArn, CredentialSource, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
171190
}
172191
},
173192
{
174193
CredentialProfileType.AssumeRoleWithWebIdentity, new List<HashSet<string>>()
175194
{
176195
new HashSet<string> { RoleArn, WebIdentityTokenFile },
196+
new HashSet<string> { RoleArn, WebIdentityTokenFile, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
177197
new HashSet<string> { RoleArn, WebIdentityTokenFile, CredentialSource },
198+
new HashSet<string> { RoleArn, WebIdentityTokenFile, CredentialSource, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
178199
new HashSet<string> { RoleArn, WebIdentityTokenFile, CredentialSource, AwsAccountId },
200+
new HashSet<string> { RoleArn, WebIdentityTokenFile, CredentialSource, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
179201
}
180202
},
181203
{
182204
CredentialProfileType.AssumeRoleWithWebIdentitySessionName, new List<HashSet<string>>()
183205
{
184206
new HashSet<string> { RoleArn, WebIdentityTokenFile, RoleSessionName },
185-
new HashSet<string> { RoleArn, WebIdentityTokenFile, RoleSessionName, AwsAccountId } ,
207+
new HashSet<string> { RoleArn, WebIdentityTokenFile, RoleSessionName, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl },
208+
new HashSet<string> { RoleArn, WebIdentityTokenFile, RoleSessionName, AwsAccountId },
209+
new HashSet<string> { RoleArn, WebIdentityTokenFile, RoleSessionName, AwsAccountId, SsoSession, SsoRegion, SsoRegistrationScopes, SsoStartUrl } ,
186210
}
187211
},
188212
{
@@ -253,13 +277,16 @@ public static string GetUserFriendlyCredentialType(CredentialProfileType? profil
253277

254278
HashSet<string> propertyNames = GetPropertyNames(profileOptions);
255279

280+
//SPEC: if sso_account_id or sso_role_name exist credentials MUST be resolved by the sso credential provider.
281+
if (propertyNames.Contains(SsoAccountId) || propertyNames.Contains(SsoRoleName))
282+
return CredentialProfileType.SSO;
256283

257284
// brute force algorithm - but it's a very small set
258285
foreach (var pair in TypePropertyDictionary)
259286
{
260287
foreach (var item in pair.Value)
261288
{
262-
if (item.IsSubsetOf(propertyNames))
289+
if (item.SetEquals(propertyNames))
263290
{
264291
profileType = pair.Key;
265292
}

sdk/test/UnitTests/Custom/Runtime/Credentials/AWSCredentialsFactoryTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public void GetSsoCredentialsWithMissingFields()
493493

494494
AssertExtensions.ExpectException(() =>
495495
AWSCredentialsFactory.GetAWSCredentials(SsoProfileMissingFields, ProfileStore),
496-
typeof(ArgumentNullException));
496+
typeof(InvalidDataException));
497497
}
498498

499499
[TestMethod]

0 commit comments

Comments
 (0)