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

@@ -147,7 +147,7 @@ public class StsQueryHandler {
// A session whose token will not fit is refused before anything is minted, on every
// operation that carries state into the token it mints.
if (PACKED_SESSION_OPERATIONS.contains(action)) {
AssembledSession session = assembledSession(params);
AssembledSession session = assembledSession(action, params);
if (session.tooLarge()) {
return session.refusal();
}
@@ -235,7 +235,7 @@ public class StsQueryHandler {
.elem("Arn", assumedRoleArn)
.elem("AssumedRoleId", assumedRoleId)
.end("AssumedRoleUser")
.elem("PackedPolicySize", assembledSession(params).utilization())
.raw(sessionSizeXml("AssumeRole", params))
.build();
return Response.ok(AwsQueryResponse.envelope("AssumeRole", AwsNamespaces.STS, result)).build();
}
@@ -249,7 +249,14 @@ public class StsQueryHandler {
*/
private static final int SESSION_TOKEN_LIMIT = 4096;
/** The operations that carry state into the token they mint and model the refusal for it. */
/**
* The operations that carry state into the token they mint and model the refusal for it, which
* are the same four whose responses still declare the member AWS deprecated, both following
* from the state: a packed size was what carrying it cost. {@code GetDelegatedAccessToken}
* declares that member too and states it is not populated, carrying nothing into its token,
* while {@code GetSessionToken} and {@code AssumeRoot} carry none either and declare neither
* it nor the refusal.
*/
private static final Set<String> PACKED_SESSION_OPERATIONS = Set.of(
"AssumeRole", "AssumeRoleWithSAML", "AssumeRoleWithWebIdentity", "GetFederationToken");
@@ -284,11 +291,12 @@ public class StsQueryHandler {
}
/**
* The member's own unit, truncated as AWS's own recorded pair reports it: a token of 2532
* bytes is published as 61.
* The member's own unit, truncated as AWS's own published pairs report it: session tokens
* of 1428, 1105 and 856 bytes are published as 34, 26 and 20, and the one pair recorded
* here reports 2532 bytes as 61.
*/
String utilization() {
return Integer.toString(bytes * 100 / SESSION_TOKEN_LIMIT);
int utilization() {
return bytes * 100 / SESSION_TOKEN_LIMIT;
}
Response refusal() {
@@ -305,24 +313,69 @@ public class StsQueryHandler {
* value. {@code TransitiveTagKeys} names tags already counted, so it adds nothing of its own,
* which is what AWS says of its own packing as well: "the transitive status of a session tag
* does not impact its packed binary size".
*
* <p>Each of the three is counted only where the operation declares it, read from the
* generated request shapes rather than named per operation here: a session tag reaches
* {@code AssumeRoleWithSAML} inside the assertion rather than as a member of the request, and
* the two operations that mint a session out of the caller's own credentials declare no state
* at all, so a parameter STS would ignore cannot be made to cost a caller anything.
*/
private AssembledSession assembledSession(MultivaluedMap<String, String> params) {
private AssembledSession assembledSession(String action, MultivaluedMap<String, String> params) {
StringBuilder state = new StringBuilder();
String document = params.getFirst("Policy");
if (document != null) {
state.append(document);
}
for (AwsQueryLists.IndexedMember arn : AwsQueryLists.members(params, "PolicyArns", null)) {
String value = params.getFirst(arn.prefix() + ".arn");
if (value != null) {
state.append(value);
if (StsRequestShapes.hasMember(action, "Policy")) {
String document = params.getFirst("Policy");
if (document != null) {
state.append(document);
}
}
tagClaims(params).forEach((key, value) -> state.append(key).append(value));
if (StsRequestShapes.hasMember(action, "PolicyArns")) {
for (AwsQueryLists.IndexedMember arn : AwsQueryLists.members(params, "PolicyArns", null)) {
String value = params.getFirst(arn.prefix() + ".arn");
if (value != null) {
state.append(value);
}
}
}
if (StsRequestShapes.hasMember(action, "Tags")) {
tagClaims(params).forEach((key, value) -> state.append(key).append(value));
}
return new AssembledSession(sessionTokenLength(params)
+ state.toString().getBytes(StandardCharsets.UTF_8).length);
}
/**
* What the session a request minted cost, as the members that operation's response declares:
* the token's size in bytes, and that size as the percentage of the limit it consumes.
*
* <p>{@code SessionTokenSize} is "the size, in bytes, of the session token returned in the
* Credentials for this response" and {@code SessionTokenUtilization} "the percentage (0-100)
* of the maximum allowed session token size that the returned session token consumes", which
* is word for word what the member they arrived beside was defined as, and the guide tells a
* caller to read the percentage instead: "the SessionTokenUtilization response element shows
* what percentage of the size limit the token uses. The PackedPolicySize response element is
* deprecated." So one number is published twice over where all three are declared, which is
* what AWS's own example responses carry: 1428 bytes with 34 in both percentage members, 1105
* with 26, and 856 with 20 on the operation that declares no deprecated member at all. Their
* order is the published one too, the deprecated member first, then the size, then the
* percentage.
*
* <p>The size is the measure this emulator refuses a session by rather than the length of the
* string in {@code Credentials}. AWS packs the session's state into the token it hands back,
* so there the two are one number; this emulator mints an opaque token and keeps the state
* beside it, and a size read off that string would tell a caller a session cost nothing while
* the refusal read the same request as over the limit.
*/
private String sessionSizeXml(String action, MultivaluedMap<String, String> params) {
AssembledSession session = assembledSession(action, params);
XmlBuilder members = new XmlBuilder();
if (PACKED_SESSION_OPERATIONS.contains(action)) {
members.elem("PackedPolicySize", session.utilization());
}
return members.elem("SessionTokenSize", session.bytes())
.elem("SessionTokenUtilization", session.utilization())
.build();
}
/**
* What a call's MFA parameters authenticated: the instant the device was used, or the denial
* that answers a device the caller cannot present. Both {@code GetSessionToken} and
@@ -548,7 +601,10 @@ public class StsQueryHandler {
String sessionToken = sessionToken(params);
Instant expiration = clock.instant().plusSeconds(durationSeconds);
String result = credentialsXml(accessKeyId, secretKey, sessionToken, expiration);
String result = new XmlBuilder()
.raw(credentialsXml(accessKeyId, secretKey, sessionToken, expiration))
.raw(sessionSizeXml("GetSessionToken", params))
.build();
// No role ARN: the credentials route back to the caller's account and act as the caller.
iamService.registerIssuedSession(accessKeyId, secretKey, sessionToken, null, expiration, null,
regionResolver.getAccountId(), callerAccessKeyId());
@@ -623,7 +679,7 @@ public class StsQueryHandler {
.elem("Arn", assumedRoleArn)
.elem("AssumedRoleId", assumedRoleId)
.end("AssumedRoleUser")
.elem("PackedPolicySize", assembledSession(params).utilization())
.raw(sessionSizeXml("AssumeRoleWithWebIdentity", params))
.elem("Provider", provider)
.elem("Audience", audience)
.elem("SubjectFromWebIdentityToken", subject)
@@ -829,7 +885,8 @@ public class StsQueryHandler {
String result = new XmlBuilder()
.raw(credentialsXml(accessKeyId, secretKey, sessionToken, expiration))
.start("AssumedRoleUser").elem("Arn", assumedRoleArn).elem("AssumedRoleId", assumedRoleId).end("AssumedRoleUser")
.elem("PackedPolicySize", assembledSession(params).utilization()).elem("Issuer", verified.issuer()).elem("Audience", "urn:amazon:webservices")
.raw(sessionSizeXml("AssumeRoleWithSAML", params)).elem("Issuer", verified.issuer())
.elem("Audience", "urn:amazon:webservices")
.elem("NameQualifier", verified.nameQualifier()).elem("SubjectType", verified.subjectType()).elem("Subject", verified.subject()).build();
return Response.ok(AwsQueryResponse.envelope("AssumeRoleWithSAML", AwsNamespaces.STS, result)).build();
}
@@ -885,7 +942,7 @@ public class StsQueryHandler {
.elem("FederatedUserId", federatedUserId)
.elem("Arn", federatedUserArn)
.end("FederatedUser")
.elem("PackedPolicySize", assembledSession(params).utilization())
.raw(sessionSizeXml("GetFederationToken", params))
.build();
return Response.ok(AwsQueryResponse.envelope("GetFederationToken", AwsNamespaces.STS, result)).build();
}
@@ -905,7 +962,8 @@ public class StsQueryHandler {
* same way: the provider obtains the "approver's temporary credentials". The two differ in the
* case {@code OnlySendByOwner} is for, where the owner could not approve and forwarded the
* request on. {@code PackedPolicySize} is left out: the model deprecates it and states it is
* not populated for this operation.
* not populated for this operation, which declares neither of the two members that replace it
* either.
*/
private Response handleGetDelegatedAccessToken(MultivaluedMap<String, String> params) {
Response validation = validateDeclaredConstraints("GetDelegatedAccessToken", params);
@@ -1018,7 +1076,7 @@ public class StsQueryHandler {
String result = new XmlBuilder()
.raw(credentialsXml(accessKeyId, secretKey, sessionToken, expiration))
.elem("SessionTokenSize", String.valueOf(sessionToken.length()))
.raw(sessionSizeXml("AssumeRoot", params))
.build();
return Response.ok(AwsQueryResponse.envelope("AssumeRoot", AwsNamespaces.STS, result)).build();
}
@@ -38,6 +38,14 @@ final class StsRequestShapes {
private StsRequestShapes() {
}
/**
* Whether the operation's generated input shape declares the member, which is how a read of a
* request asks what that request is allowed to carry rather than naming the operations itself.
*/
static boolean hasMember(String action, String member) {
return CHECK.hasMember(action, member);
}
/** Every constraint the model declares for {@code action} that {@code params} breaks. */
static List<String> violations(String action, MultivaluedMap<String, String> params) {
return CHECK.violations(action, params);