fix(sts): publish the two members that replace PackedPolicySize (#9280)

Every response that mints a session declares the size of the token it hands
back and the share of the limit that size consumes, and this package published
neither. SessionTokenSize is "the size, in bytes, of the session token returned
in the Credentials for this response" and SessionTokenUtilization "the
percentage (0-100) of the maximum allowed session token size that the returned
session token consumes", which is word for word the definition of the
PackedPolicySize they were deprecated in favour of on 2026-06-17, and the guide
tells a caller to read the new one: "the SessionTokenUtilization response
element shows what percentage of the size limit the token uses. The
PackedPolicySize response element is deprecated."

All six operations that mint a session carry the pair: AssumeRole,
AssumeRoleWithSAML, AssumeRoleWithWebIdentity, AssumeRoot, GetFederationToken
and GetSessionToken. The four that carry state into their token declare the
deprecated member as well and publish all three, that one ahead of the pair and
holding the same percentage, so one number is published twice over. AWS's own
example responses are that shape: 1428 bytes with 34 in both percentage
members, 1105 with 26, and 856 with 20 on GetSessionToken, whose response
declares no deprecated member at all. The percentage truncates, as all three of
those pairs and the one pair recorded here report it.

The size published is the measure a session is refused by rather than the
length of the string in Credentials. AWS packs the session's state into the
token it hands back, so the two are one number there, while this package mints
an opaque token and keeps the state beside it, and a size read off that string
would tell a caller the session cost nothing while the same request was refused
for being over the limit. AssumeRoot answered that string's length, which on an
operation carrying no state is the same number, and reads the one measure now.

What that measure counts is the state the operation declares, read from the
generated request shapes rather than from whatever parameters a request
carries, which is what publishing a size on the two operations that declare
none asked for. A session tag reaches AssumeRoleWithSAML and
AssumeRoleWithWebIdentity inside the assertion or the token rather than as a
member of the request, so a tag sent to either no longer costs its token
anything, and a document or a tag sent to GetSessionToken or AssumeRoot costs
nothing either.

The IAM page carries the three members, which response declares which, the
published pairs behind the truncation, and why the size is the measure rather
than the string in Credentials. The STS page's privileged-session section no
longer counts its size member among that operation's deviations, nor says the
percentage goes unanswered: it publishes the pair the reference defines, as the
other five do.

Covered over the API by the three members on an assumed, a federated and a web
identity session, by the pair alone on the long-term session and on the
privileged session, by all three on a SAML session where the signing fixture
lives, and by a request whose undeclared parameters cost it nothing; at the
handler by the pair on each operation that harness can reach, by the deprecated
member appearing only where its response declares it, and by the declarations
the measure turns on, so a regenerated file that stopped carrying an operation
is caught there rather than by a session quietly reporting its token alone; and
on the exchange that declares none of the three, which publishes none.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-23 12:29:55 -04:00
1 parent fad1093175
commit 199ee18a6b
9 files changed
+349 -50

No files matched your search

@@ -519,6 +519,28 @@ class AssumeRoleWithSamlValidationIntegrationTest {
assertEquals(1024, token.length());
}
/**
* And it publishes what that token cost, the three members its response declares: the size in
* bytes, the percentage of the 4,096-byte limit it consumes, and the deprecated member
* carrying the same percentage. A tag is not among the state counted here, this operation
* declaring none: a session tag reaches it inside the assertion.
*/
@Test
void theSessionPublishesWhatItsTokenCost() {
String role = createRole(true);
String assertion = assertion(role, PROVIDER, Instant.now().plusSeconds(300), AUDIENCE, ISSUER, true);
String result = "AssumeRoleWithSAMLResponse.AssumeRoleWithSAMLResult.";
assumeRequest(role, assertion, PROVIDER)
.formParam("MinimumSessionTokenSize", "1024")
.formParam("Tags.member.1.Key", "team")
.formParam("Tags.member.1.Value", "payments")
.when().post("/").then().statusCode(200)
.body(result + "SessionTokenSize", equalTo("1024"))
.body(result + "SessionTokenUtilization", equalTo("25"))
.body(result + "PackedPolicySize", equalTo("25"));
}
private static void assertSignatureInvalid(Function<XMLSignatureFactory, List<Transform>> transforms) {
String role = createRole(true);
assume(role, assertion(role, PROVIDER, Instant.now().plusSeconds(300), AUDIENCE, ISSUER, true, false, transforms),
@@ -445,8 +445,11 @@ class DelegationRequestIntegrationTest {
exchanged.body(prefix + "Credentials.AccessKeyId", startsWith("ASIA"))
.body(prefix + "Credentials.SessionToken", not(equalTo(null)))
.body(prefix + "AssumedPrincipal", equalTo("arn:aws:iam::" + CUSTOMER + ":root"));
assertFalse(exchanged.extract().asString().contains("PackedPolicySize"),
String body = exchanged.extract().asString();
assertFalse(body.contains("PackedPolicySize"),
"the model deprecates it and states it is not populated for this operation");
assertFalse(body.contains("SessionTokenSize") || body.contains("SessionTokenUtilization"),
"and this operation declares neither of the two members that replace it");
}
/**
@@ -153,6 +153,11 @@ class StsAssumeRootIntegrationTest {
.body("ErrorResponse.Error.Code", equalTo("OrganizationNotFoundException"));
}
/**
* The privileged session acts as the member account's root, and reports what its token cost:
* 200 bytes of this emulator's own minting, 4 percent of the limit a session token is held to.
* The operation declares no state to carry and no deprecated member, so the pair is all of it.
*/
@Test
@Order(6)
void aPrivilegedSessionActsAsTheMemberAccountRoot() {
@@ -161,7 +166,8 @@ class StsAssumeRootIntegrationTest {
.when().post("/").then().statusCode(200)
.body("AssumeRootResponse.AssumeRootResult.Credentials.AccessKeyId", startsWith("ASIA"))
.body("AssumeRootResponse.AssumeRootResult.Credentials.Expiration", notNullValue())
.body("AssumeRootResponse.AssumeRootResult.SessionTokenSize", notNullValue())
.body("AssumeRootResponse.AssumeRootResult.SessionTokenSize", equalTo("200"))
.body("AssumeRootResponse.AssumeRootResult.SessionTokenUtilization", equalTo("4"))
.extract().path("AssumeRootResponse.AssumeRootResult.Credentials.AccessKeyId");
String sessionToken = assumeRoot(managementKey, memberAccount, TASK_POLICY)
.when().post("/").then().statusCode(200)
@@ -289,7 +295,8 @@ class StsAssumeRootIntegrationTest {
assumeRoot(managementKey, memberAccount, TASK_POLICY)
.formParam("MinimumSessionTokenSize", "1024")
.when().post("/").then().statusCode(200)
.body("AssumeRootResponse.AssumeRootResult.SessionTokenSize", equalTo("1024"));
.body("AssumeRootResponse.AssumeRootResult.SessionTokenSize", equalTo("1024"))
.body("AssumeRootResponse.AssumeRootResult.SessionTokenUtilization", equalTo("25"));
}
/**
@@ -8,6 +8,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* What a request asks to carry into its session token, and what AWS does when the token will not
@@ -16,6 +17,11 @@ import static org.hamcrest.Matchers.equalTo;
* percentage of the limit the session consumes, which is what the member is defined as, rather
* than a flat zero.
*
* <p>What a session that fits costs is published three ways where the response declares all
* three, {@code SessionTokenSize} in bytes with {@code SessionTokenUtilization} and the deprecated
* member carrying that size as the percentage of the limit it consumes, and as the pair alone on
* the two operations that carry nothing into the token they mint.
*
* <p>{@code docs/services/iam.md} records the measure, which is this emulator's own, and the one
* recorded size that shows AWS's assembly running larger than the bytes going in.
*/
@@ -86,6 +92,17 @@ class StsPackedSessionIntegrationTest {
/** The limit a session token is held to, which the refusal names. */
private static final int LIMIT = 4096;
private static final String ASSUMED = "AssumeRoleResponse.AssumeRoleResult.";
private static final String FEDERATED = "GetFederationTokenResponse.GetFederationTokenResult.";
private static final String LONG_TERM = "GetSessionTokenResponse.GetSessionTokenResult.";
private static final String WEB_IDENTITY =
"AssumeRoleWithWebIdentityResponse.AssumeRoleWithWebIdentityResult.";
/** What the percentage members report for a token of that size, truncated as AWS truncates it. */
private static String utilizationOf(int bytes) {
return Integer.toString(bytes * 100 / LIMIT);
}
/** What the measure reports for that set: the token it would be carried in, and the set. */
private static int recordedSetBytes() {
return MINTED_TOKEN_LENGTH + TAGS * (KEY_LENGTH + VALUE_LENGTH);
@@ -139,13 +156,12 @@ class StsPackedSessionIntegrationTest {
String document = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::"
+ repeat('b', 1000) + "/*\"}]}";
int percent = (MINTED_TOKEN_LENGTH + document.length()) * 100 / LIMIT;
sts("AssumeRole").formParam("RoleArn", roleArn())
.formParam("RoleSessionName", "packed-within")
.formParam("Policy", document)
.when().post("/").then().statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.PackedPolicySize",
equalTo(Integer.toString(percent)));
.body(ASSUMED + "PackedPolicySize",
equalTo(utilizationOf(MINTED_TOKEN_LENGTH + document.length())));
}
/**
@@ -157,8 +173,7 @@ class StsPackedSessionIntegrationTest {
sts("AssumeRole").formParam("RoleArn", roleArn())
.formParam("RoleSessionName", "packed-empty")
.when().post("/").then().statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.PackedPolicySize",
equalTo(Integer.toString(MINTED_TOKEN_LENGTH * 100 / LIMIT)));
.body(ASSUMED + "PackedPolicySize", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)));
}
/**
@@ -172,7 +187,89 @@ class StsPackedSessionIntegrationTest {
.formParam("RoleSessionName", "packed-padded")
.formParam("MinimumSessionTokenSize", Integer.toString(LIMIT))
.when().post("/").then().statusCode(200)
.body("AssumeRoleResponse.AssumeRoleResult.PackedPolicySize", equalTo("100"));
.body(ASSUMED + "PackedPolicySize", equalTo("100"))
.body(ASSUMED + "SessionTokenSize", equalTo(Integer.toString(LIMIT)))
.body(ASSUMED + "SessionTokenUtilization", equalTo("100"));
}
/**
* What a session that fits publishes: its token's size in bytes, and that size as the
* percentage of the limit it consumes, the deprecated member carrying the same percentage as
* the one that replaces it. AWS's own example response is this shape, 1428 bytes reported as
* 34 in both.
*/
@Test
void theThreeMembersReportOneNumber() {
String document = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::"
+ repeat('b', 500) + "/*\"}]}";
int bytes = MINTED_TOKEN_LENGTH + document.length();
sts("AssumeRole").formParam("RoleArn", roleArn())
.formParam("RoleSessionName", "packed-three-members")
.formParam("Policy", document)
.when().post("/").then().statusCode(200)
.body(ASSUMED + "SessionTokenSize", equalTo(Integer.toString(bytes)))
.body(ASSUMED + "SessionTokenUtilization", equalTo(utilizationOf(bytes)))
.body(ASSUMED + "PackedPolicySize", equalTo(utilizationOf(bytes)));
}
/** The federated session publishes the same three, its response declaring the same three. */
@Test
void aFederatedSessionPublishesTheSameThree() {
sts("GetFederationToken").formParam("Name", "packed-federated-members")
.when().post("/").then().statusCode(200)
.body(FEDERATED + "SessionTokenSize", equalTo(Integer.toString(MINTED_TOKEN_LENGTH)))
.body(FEDERATED + "SessionTokenUtilization", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)))
.body(FEDERATED + "PackedPolicySize", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)));
}
/**
* The long-term session publishes the pair and nothing beside it: its response declares
* neither the deprecated member nor the refusal, since it carries no state into the token it
* mints. AWS publishes the two alone for it as well, 856 bytes reported as 20.
*/
@Test
void aLongTermSessionPublishesThePairWithoutTheDeprecatedMember() {
// The absent member is read off the document rather than through an XML path, which
// answers an empty node for an element that is not there at all.
String body = sts("GetSessionToken")
.when().post("/").then().statusCode(200)
.body(LONG_TERM + "SessionTokenSize", equalTo(Integer.toString(MINTED_TOKEN_LENGTH)))
.body(LONG_TERM + "SessionTokenUtilization", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)))
.extract().asString();
assertFalse(body.contains("PackedPolicySize"), body);
}
/**
* A parameter the operation does not declare costs its session nothing. The long-term session
* is minted from the caller's own credentials and declares no document and no tag, so a
* request that sends both is answered as what it is, a token carrying nothing, where a measure
* that counted every parameter it found would have reported state the service never assembled.
*/
@Test
void aParameterTheOperationDoesNotDeclareCostsNothing() {
withRecordedTagSet(sts("GetSessionToken").formParam("Policy", repeat('p', 2000)))
.when().post("/").then().statusCode(200)
.body(LONG_TERM + "SessionTokenSize", equalTo(Integer.toString(MINTED_TOKEN_LENGTH)))
.body(LONG_TERM + "SessionTokenUtilization", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)));
}
/**
* And a tag set that would not fit an assumed session leaves a web identity session alone,
* rather than refusing it for state it never declared: a session tag reaches this operation
* through the token's own claims. What it reports is the token it minted.
*/
@Test
void tagsOnAnOperationThatDeclaresNoneDoNotRefuseTheSession() {
withRecordedTagSet(sts("AssumeRoleWithWebIdentity")
.formParam("RoleArn", roleArn())
.formParam("RoleSessionName", "packed-web-tags")
.formParam("WebIdentityToken", "a.b.c"))
.when().post("/").then().statusCode(200)
.body(WEB_IDENTITY + "SessionTokenSize", equalTo(Integer.toString(MINTED_TOKEN_LENGTH)))
.body(WEB_IDENTITY + "SessionTokenUtilization", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)))
.body(WEB_IDENTITY + "PackedPolicySize", equalTo(utilizationOf(MINTED_TOKEN_LENGTH)));
}
/** State on top of a token already at the limit does not fit, and the sentence names the size. */
@@ -58,6 +58,13 @@ class StsQueryHandlerTest {
private static final Pattern SESSION_TOKEN =
Pattern.compile("<SessionToken>([^<]+)</SessionToken>");
private static final Pattern SESSION_TOKEN_SIZE =
Pattern.compile("<SessionTokenSize>([^<]+)</SessionTokenSize>");
private static final Pattern SESSION_TOKEN_UTILIZATION =
Pattern.compile("<SessionTokenUtilization>([^<]+)</SessionTokenUtilization>");
private static final Pattern PACKED_POLICY_SIZE =
Pattern.compile("<PackedPolicySize>([^<]+)</PackedPolicySize>");
private static final Pattern ARN = Pattern.compile("<Arn>([^<]+)</Arn>");
private static final Pattern EXPIRATION = Pattern.compile("<Expiration>([^<]+)</Expiration>");
@@ -376,6 +383,72 @@ class StsQueryHandlerTest {
assertEquals(200, extract(SESSION_TOKEN, shorter).length());
}
/**
* What a session cost is published as the two members that replace the deprecated one: the
* size the token comes to in bytes, and that size as the percentage of the 4,096-byte limit it
* consumes. A token asked to be 1024 characters is a quarter of the limit, and the pair is
* asked of each operation on its own so one that stopped publishing it is caught here. The two
* this harness cannot reach are pinned where their requests can be built, as the token length
* above is.
*/
@ParameterizedTest
@ValueSource(strings = {"GetSessionToken", "AssumeRole", "AssumeRoleWithWebIdentity",
"GetFederationToken"})
void theSizeMembersReportTheTokenAndItsShareOfTheLimit(String action) {
MultivaluedMap<String, String> params = sessionRequest(action);
params.putSingle("MinimumSessionTokenSize", "1024");
String body = (String) newHandler().handle(action, params).getEntity();
assertEquals("1024", extract(SESSION_TOKEN_SIZE, body));
assertEquals("25", extract(SESSION_TOKEN_UTILIZATION, body));
}
/**
* The member AWS deprecated is published where its response still declares it, carrying the
* same percentage as the member that replaces it, and nowhere else: a session minted out of
* the caller's own credentials never packed anything, and its response declares neither that
* member nor the refusal.
*/
@Test
void theDeprecatedMemberIsPublishedOnlyWhereItsResponseDeclaresIt() {
String assumed = (String) newHandler()
.handle("AssumeRole", sessionRequest("AssumeRole")).getEntity();
assertEquals(extract(SESSION_TOKEN_UTILIZATION, assumed), extract(PACKED_POLICY_SIZE, assumed));
String longTerm = (String) newHandler()
.handle("GetSessionToken", sessionRequest("GetSessionToken")).getEntity();
assertFalse(PACKED_POLICY_SIZE.matcher(longTerm).find(), longTerm);
}
/**
* What a session's size counts is the state the operation declares, read from the generated
* request shapes rather than named per operation in the handler. These are the declarations
* the measure turns on, so a regenerated file that stopped carrying an operation is caught
* here rather than by a session quietly reporting its token alone.
*/
@Test
void theGeneratedShapesDeclareTheStateEachSessionCarries() {
assertTrue(StsRequestShapes.hasMember("AssumeRole", "Policy"));
assertTrue(StsRequestShapes.hasMember("AssumeRole", "PolicyArns"));
assertTrue(StsRequestShapes.hasMember("AssumeRole", "Tags"));
assertTrue(StsRequestShapes.hasMember("GetFederationToken", "Policy"));
assertTrue(StsRequestShapes.hasMember("GetFederationToken", "Tags"));
assertTrue(StsRequestShapes.hasMember("AssumeRoleWithSAML", "Policy"));
assertTrue(StsRequestShapes.hasMember("AssumeRoleWithWebIdentity", "Policy"));
// A session tag reaches these two inside the assertion or the token rather than as a
// member of the request, and the two below carry no state into their token at all.
assertFalse(StsRequestShapes.hasMember("AssumeRoleWithSAML", "Tags"));
assertFalse(StsRequestShapes.hasMember("AssumeRoleWithWebIdentity", "Tags"));
assertFalse(StsRequestShapes.hasMember("GetSessionToken", "Policy"));
assertFalse(StsRequestShapes.hasMember("GetSessionToken", "Tags"));
assertFalse(StsRequestShapes.hasMember("AssumeRoot", "Policy"));
assertFalse(StsRequestShapes.hasMember("AssumeRoot", "Tags"));
}
/** The least a request needs to reach issuance on an operation that models a token size. */
private static MultivaluedMap<String, String> sessionRequest(String action) {
Map<String, String> members = switch (action) {