fix(sts): honour 12-digit access key as account ID in STS responses (#983)

* fix(sts): honour 12-digit access key as account ID

GetCallerIdentity, AssumeRole, AssumeRoleWithWebIdentity,
AssumeRoleWithSAML, and GetFederationToken now resolve the account ID
from the request-scoped RegionResolver instead of the static IAM
default, so ARNs match the per-account namespace used by SNS, SQS, S3,
etc. Closes #981.

* fix(sts): derive AssumedRoleUser account from RoleArn

AssumeRole, AssumeRoleWithWebIdentity, and AssumeRoleWithSAML now build
AssumedRoleUser.Arn using the account ID parsed from the supplied
RoleArn, falling back to the caller's account only when the ARN is
missing or unparseable. This matches AWS cross-account assume-role
behaviour: the resulting ARN belongs to the target role's account, not
the caller's.
This commit is contained in:
Stuart Lang authored and GitHub committed 2026-05-21 20:36:28 -05:00
1 parent ff40a2fc0a
commit 788ddf751f
2 files changed
+63 -6

No files matched your search

@@ -52,6 +52,24 @@ class IamIntegrationTest {
@Test
@Order(2)
void stsGetCallerIdentityHonoursTwelveDigitAccessKey() {
given()
.formParam("Action", "GetCallerIdentity")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=123456789012/20260227/us-east-1/sts/aws4_request")
.when()
.post("/")
.then()
.statusCode(200)
.contentType("application/xml")
.body("GetCallerIdentityResponse.GetCallerIdentityResult.UserId", equalTo("123456789012"))
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Account", equalTo("123456789012"))
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Arn",
equalTo("arn:aws:iam::123456789012:root"));
}
@Test
@Order(3)
void stsAssumeRole() {
given()
.formParam("Action", "AssumeRole")
@@ -73,6 +91,42 @@ class IamIntegrationTest {
containsString("assumed-role/TestRole/test-session"));
}
@Test
@Order(4)
void stsAssumeRoleHonoursTwelveDigitAccessKey() {
given()
.formParam("Action", "AssumeRole")
.formParam("RoleArn", "arn:aws:iam::123456789012:role/TestRole")
.formParam("RoleSessionName", "tenant-session")
.formParam("DurationSeconds", "3600")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=123456789012/20260227/us-east-1/sts/aws4_request")
.when()
.post("/")
.then()
.statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.AssumedRoleUser.Arn",
equalTo("arn:aws:sts::123456789012:assumed-role/TestRole/tenant-session"));
}
@Test
@Order(6)
void stsAssumeRoleUsesAccountFromRoleArnForCrossAccount() {
given()
.formParam("Action", "AssumeRole")
.formParam("RoleArn", "arn:aws:iam::222222222222:role/CrossAccountRole")
.formParam("RoleSessionName", "cross-session")
.formParam("DurationSeconds", "3600")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=123456789012/20260227/us-east-1/sts/aws4_request")
.when()
.post("/")
.then()
.statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.AssumedRoleUser.Arn",
equalTo("arn:aws:sts::222222222222:assumed-role/CrossAccountRole/cross-session"));
}
// =========================================================================
// AWS Managed Policies (seeded at startup)
// =========================================================================