mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
fad1093175
commit
199ee18a6b
9 files changed
+349
-50
No files matched your search
+34
-9
@@ -1062,22 +1062,47 @@ the four operations that carry state into the token they mint: `AssumeRole`, `As
|
||||
minted, which is where AWS answers it. A token asked through `MinimumSessionTokenSize` to be the
|
||||
limit itself therefore leaves nothing to carry a policy or a tag on top of it, and a request that
|
||||
asks for both is refused. `GetDelegatedAccessToken` carries no such state, and the member stays out
|
||||
of its response as the model deprecates it there. `SessionTokenSize` and `SessionTokenUtilization`,
|
||||
the two members the model now carries beside `PackedPolicySize`, are not published yet.
|
||||
of its response as the model deprecates it there.
|
||||
|
||||
What a session that fits cost is published three ways, one number each time. `SessionTokenSize` is
|
||||
"the size, in bytes, of the session token returned in the Credentials for this response",
|
||||
`SessionTokenUtilization` is that size as "the percentage (0-100) of the maximum allowed session
|
||||
token size that the returned session token consumes", and `PackedPolicySize` carries the same
|
||||
percentage where a response still declares it, truncated rather than rounded. AWS's own example
|
||||
responses are the pattern: 1428 bytes published as 34 in both percentage members, 1105 as 26, and
|
||||
856 as 20 on `GetSessionToken`, whose response declares no deprecated member at all. All six
|
||||
operations that mint a session publish the pair, `AssumeRole`, `AssumeRoleWithSAML`,
|
||||
`AssumeRoleWithWebIdentity`, `AssumeRoot`, `GetFederationToken` and `GetSessionToken`, and the four
|
||||
that carry state into their token publish the deprecated member ahead of it, which is the order
|
||||
AWS prints the three in.
|
||||
|
||||
The size published is that measure rather than the length of the string in `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 the returned string would
|
||||
tell a caller its session cost nothing while the same request was refused for being over the limit.
|
||||
|
||||
The measure is this emulator's own and the number will differ from AWS's. It is the token this
|
||||
emulator will mint for the request, whose length `MinimumSessionTokenSize` can ask to be raised,
|
||||
plus the state the request asks to carry into it in UTF-8 bytes: the inline document, every policy
|
||||
ARN, and every tag key and value. AWS assembles the real thing instead, and its size follows the
|
||||
input in neither direction. STS "serializes and compresses your session policies and tags when
|
||||
assembling the token", where "compression results vary based on the actual content, not just its
|
||||
length" and "two sets of tags with identical character counts can produce different token sizes",
|
||||
so a repetitive set can assemble smaller than the bytes it was written in. The one size recorded
|
||||
plus the state the request asks to carry into it in UTF-8 bytes, counted where the operation
|
||||
declares it: the inline document, every policy ARN, and every tag key and value. AWS assembles the
|
||||
real thing instead, and its size follows the input in neither direction. STS "serializes and
|
||||
compresses your session policies and tags when assembling the token", where "compression results
|
||||
vary based on the actual content, not just its length" and "two sets of tags with identical
|
||||
character counts can produce different token sizes", so a repetitive set can assemble smaller than
|
||||
the bytes it was written in. The one size recorded
|
||||
here ran larger than its input: for a request of 50 tags with 124-character keys and 256-character
|
||||
values, every field inside its own limit, AWS reported 26092 bytes against the limit of 4096, where
|
||||
those fields are about 19000 bytes of input. A recording of a second size would let the measure be
|
||||
calibrated, and that is the only thing this reading waits on.
|
||||
|
||||
Which of the three a request can be charged for is read from the generated request shapes rather
|
||||
than from the parameters it happens to carry, so a member STS would ignore costs its caller
|
||||
nothing. `AssumeRole` and `GetFederationToken` declare the document, the policy ARNs and the tags;
|
||||
`AssumeRoleWithSAML` and `AssumeRoleWithWebIdentity` declare the documents and no tags, a session
|
||||
tag reaching them inside the assertion or the web identity token, which Floci does not read as
|
||||
session tags yet, so it costs their token nothing here; and `AssumeRoot` and `GetSessionToken`
|
||||
declare none of the three, their tokens carrying nothing but themselves.
|
||||
|
||||
### Policy Simulation
|
||||
|
||||
| Action | Description |
|
||||
@@ -2278,7 +2303,7 @@ exchange its token. A token past that window, and one nothing matches, both answ
|
||||
token", and the remedy the reference gives, requesting a new token, is the same either way. A
|
||||
token offered by any other account answers `AccessDenied`, which is a refusal rather than an
|
||||
expiry. `PackedPolicySize` is left out of the response, the model deprecating it and stating it is
|
||||
not populated here.
|
||||
not populated here, and this operation declares neither of the two members that replace it.
|
||||
|
||||
IAM tells the partner how the request is going on the SNS topic it named, which is the only channel
|
||||
this family has outwards. Every state AWS lists notifies, `ASSIGNED`, `PENDING_APPROVAL`,
|
||||
|
||||
+15
-9
@@ -123,7 +123,7 @@ with `RootSessions` on. The target has to be a member account other than the man
|
||||
privileged tasks being what the management account performs on members. `DurationSeconds` is 0 to
|
||||
900 and defaults to 900, "the maximum session duration of 900 seconds (15 minutes)".
|
||||
|
||||
Four things are deviations rather than readings, since the operation models only
|
||||
Three things are deviations rather than readings, since the operation models only
|
||||
`RegionDisabledException` and `ExpiredTokenException`:
|
||||
|
||||
- Every caller, target and feature refusal is `AccessDenied` 403, and a task policy outside the
|
||||
@@ -137,14 +137,20 @@ Four things are deviations rather than readings, since the operation models only
|
||||
- "The global endpoint is not supported for AssumeRoot" is refused when the request arrives on the
|
||||
partition's global STS host. A request to a local host carries no such name, and the signing
|
||||
region cannot tell the two apart, so there is nothing to refuse there.
|
||||
- `SessionTokenSize` is answered as the length of the token issued, and `MinimumSessionTokenSize`
|
||||
pads it to at least the size asked for, held to the 0 to 4096 the model declares, "The value must
|
||||
not exceed 4,096 bytes", since the size asked for is the size materialized. This was the first
|
||||
operation to materialize it and is no longer the only one, the five others that model the member
|
||||
reading it through the same writer. Out of that range is
|
||||
a `ValidationError` and a value that is no integer an `InvalidParameterValue`, the pair
|
||||
`DurationSeconds` already answers. `SessionTokenUtilization` is not answered: the model documents
|
||||
neither member, so only the one with an obvious meaning is filled.
|
||||
|
||||
`MinimumSessionTokenSize` pads the token to at least the size asked for, held to the 0 to 4096 the
|
||||
model declares, "The value must not exceed 4,096 bytes", since the size asked for is the size
|
||||
materialized. Out of that range is a `ValidationError` and a value that is no integer an
|
||||
`InvalidParameterValue`, the pair `DurationSeconds` already answers. This was the first operation to
|
||||
materialize the member and is no longer the only one, the five others that model it reading it
|
||||
through the same writer.
|
||||
|
||||
What the session cost is published as the two members this response declares, `SessionTokenSize`
|
||||
carrying the token's size in bytes and `SessionTokenUtilization` that size as the percentage of the
|
||||
4,096-byte limit it consumes, which is what the reference defines each as. The
|
||||
[IAM service doc](iam.md#what-a-sessions-token-costs-and-when-it-is-refused) carries the measure
|
||||
behind both, this operation carrying no state into its token, and the deprecated member the pair
|
||||
replaces is not declared here at all.
|
||||
|
||||
The audit reads the `IAMAuditRootUserCredentials` task policy allows name the member account's root
|
||||
user when they are called with no `UserName`, which is what that policy's own `arn:aws:iam::*:root`
|
||||
|
||||
@@ -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);
|
||||
|
||||
+22
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user