fix(sts): name the role, not the session, as a role session's web identity token subject (#9517)

This commit is contained in:
John Gillett authored and GitHub committed 2026-11-26 08:56:12 -04:00
1 parent 4ee43a0ce0
commit 2c2cf3e3e3
3 files changed
+33 -2

No files matched your search

+2 -1
View File
@@ -226,7 +226,8 @@ subject is signed and outlives the call, so a session that has already gone does
naming the account root. An unknown long-term key keeps the stand-in.
The claim layout is the one the IAM User Guide publishes. The standard OIDC claims sit at the top
level, `iss`, `aud`, `sub`, `iat`, `exp` and `jti`, with the caller's ARN as the subject, and the
level, `iss`, `aud`, `sub`, `iat`, `exp` and `jti`, with the caller's ARN as the subject (for a role
session, the role's ARN, path included, rather than the assumed-role session ARN), and the
custom claims are nested under the `https://sts.amazonaws.com/` namespace: `aws_account` for the
account the token was asked for, `source_region` for the region it was asked from, and the
request's tags under `request_tags`. The guide notes that "all these claims may not be present in
@@ -1487,7 +1487,9 @@ public class StsQueryHandler {
+ " lifetime of a session beyond what was granted when the session was"
+ " originally created.", AwsNamespaces.STS, 403);
}
String subject = iamService.resolveCallerArn(accessKeyId).orElseGet(() ->
// "For a role session, this is the ARN of the role": the principal's ARN, path included,
// rather than the assumed-role session ARN
String subject = iamService.resolvePrincipalArn(accessKeyId).orElseGet(() ->
regionResolver.buildGlobalArn("iam", regionResolver.getAccountId(), "root"));
String token = tokenIssuer.mint(
WebIdentityTokenIssuer.Algorithm.valueOf(params.getFirst("SigningAlgorithm")),
@@ -140,6 +140,34 @@ class WebIdentityTokenIntegrationTest {
"a request that named no tags carries no request_tags claim");
}
/**
* "For a role session, this is the ARN of the role": the subject names the role that was
* assumed, path included, rather than the assumed-role session ARN, which names the session
* and drops the path. A relying party checks the subject against the role ARN.
*/
@Test
void aRoleSessionsTokenNamesTheRoleAsItsSubject() throws Exception {
enabledIssuer();
String roleArn = iam("CreateRole")
.formParam("RoleName", "web-identity-subject-role")
.formParam("Path", "/service/")
.formParam("AssumeRolePolicyDocument", """
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",\
"Principal":{"AWS":"*"},"Action":"sts:AssumeRole"}]}""")
.when().post("/").then().statusCode(200)
.extract().path("CreateRoleResponse.CreateRoleResult.Role.Arn");
String sessionKey = sts("AssumeRole")
.formParam("RoleArn", roleArn)
.formParam("RoleSessionName", "local")
.when().post("/").then().statusCode(200)
.extract().path("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId");
String jwt = session(sessionKey).when().post("/").then().statusCode(200).extract().path(TOKEN);
assertTrue(roleArn.endsWith(":role/service/web-identity-subject-role"), roleArn);
assertEquals(roleArn, part(jwt, 1).path("sub").asText());
}
/**
* {@code ES384} is "ECDSA using P-384 curve with SHA-384", and JWS defines that signature as
* the raw {@code R || S} pair: two 48-byte halves for P-384. A DER sequence would be close to