mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ssoportal): name IAM Identity Center role sessions after the user (#8162)
* fix(ssoportal): name IAM Identity Center role sessions after the user * refactor(identitystore): read a user through findUser in one place
This commit is contained in:
1 parent
25811dd4c6
commit
5c08fff5d7
6 files changed
+54
-6
No files matched your search
@@ -80,7 +80,7 @@ class SsoPortalIntegrationTest {
|
||||
.then().statusCode(400)
|
||||
.body("__type", containsString("InvalidRequestException"));
|
||||
|
||||
given()
|
||||
String roleAccessKeyId = given()
|
||||
.header("x-amz-sso_bearer_token", accessToken)
|
||||
.queryParam("account_id", "111111111111")
|
||||
.queryParam("role_name", "PortalDirect" + suffix)
|
||||
@@ -89,7 +89,20 @@ class SsoPortalIntegrationTest {
|
||||
.body("roleCredentials.accessKeyId", Matchers.startsWith("ASIA"))
|
||||
.body("roleCredentials.secretAccessKey", Matchers.not(Matchers.emptyString()))
|
||||
.body("roleCredentials.sessionToken", Matchers.not(Matchers.emptyString()))
|
||||
.body("roleCredentials.expiration", Matchers.greaterThan(System.currentTimeMillis()));
|
||||
.body("roleCredentials.expiration", Matchers.greaterThan(System.currentTimeMillis()))
|
||||
.extract().path("roleCredentials.accessKeyId");
|
||||
|
||||
// IAM Identity Center names the role session after the user.
|
||||
given()
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + roleAccessKeyId
|
||||
+ "/20260101/us-east-1/sts/aws4_request, SignedHeaders=host, Signature=abc")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "GetCallerIdentity")
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Arn", Matchers.equalTo(
|
||||
"arn:aws:sts::111111111111:assumed-role/AWSReservedSSO_PortalDirect" + suffix
|
||||
+ "_floci/portal-" + suffix + "@example.com"));
|
||||
|
||||
given()
|
||||
.header("x-amz-sso_bearer_token", accessToken)
|
||||
|
||||
@@ -70,12 +70,15 @@ class SsoPortalServiceTest {
|
||||
PaginatedResult<PortalRoleInfo> roles = service.listAccountRoles(accessToken, accountId, null, null);
|
||||
assertEquals("PlatformAdmins", roles.items().getFirst().roleName());
|
||||
|
||||
when(ssoAdminService.portalSessionName(any(), eq(principalId))).thenReturn(Optional.of("alice@example.com"));
|
||||
PortalRoleCredentials credentials = service.getRoleCredentials(accessToken, accountId, "PlatformAdmins");
|
||||
assertTrue(credentials.accessKeyId().startsWith("ASIA"));
|
||||
assertTrue(credentials.expiration() > System.currentTimeMillis());
|
||||
|
||||
ArgumentCaptor<String> roleArn = ArgumentCaptor.forClass(String.class);
|
||||
verify(iamService).registerSessionForAccount(eq(accountId), any(), any(), any(), roleArn.capture(), any(), eq(null));
|
||||
// The role session is named after the Identity Store user, as IAM Identity Center names it.
|
||||
verify(iamService).registerSessionForAccount(eq(accountId), any(), any(), any(), roleArn.capture(), any(), eq(null),
|
||||
eq("alice@example.com"));
|
||||
assertEquals("arn:aws-cn:iam::" + accountId
|
||||
+ ":role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_PlatformAdmins_floci", roleArn.getValue());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user