From 0ec28aee68e91134c53e78cdb66239a0a21f795b Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:17:09 -0400 Subject: [PATCH] feat(iam): read a Query list's constraints from the model (#6625) The Query walk the managed-policy family reads its constraints through read scalars only, and refused an operation whose input carries a list when the vendored file loaded. It reads a list now, and a structure, which is what the rest of this track is gated on: 34 of IAM's 180 operations carry a list or a map, and 6 of STS's 11 do. A list arrives numbered under its own name, Audience.member.1 or the bare Audience.1, and a member of a list of structures carries its fields under that prefix, as Tags.member.1.Key does. Each is named in a message the way this package already names one, filter.1.member and tags.1.member.key, under the index the request spelled rather than the position the member sits at, which is what #6478 settled. The count is held to the list's own bounds with the value left out of the message, which is the form checkListLength and the audience check both already answer: quoting it would echo every member of the list back. A list of no members is how an absent list arrives on this protocol, so a required one reads as null rather than as a list breaking a minimum of 1, and only a minimum above 1 is reachable at all. A structure member arrives as TaskPolicyArn.Arn and is named taskPolicyArn.arn, and a request naming none of its fields is a request without the member. GetAccountAuthorizationDetails is the operation this wave opts in, and the one where the model adds refusals rather than rewording an answer already given: the handler reads none of its three declared members, so a Filter outside the model's enum, a MaxItems outside 1 to 1000 and a Marker breaking its length or its pattern are all answered with a 200 today. They are a 400 ValidationError now, which is the ordering #6402 settled for this package. A map is still refused when the file loads, and so is anything nested deeper than a list of structures. The refusal is the point rather than a gap: this package answers a map against the whole map today, Map keys must satisfy constraint on PutAccountProperties, where the protocol numbers a map's entries as Properties.entry.N.key, and no source here says which of the two AWS answers. Reading one would reword a merged answer on the strength of a guess. The reader the walk needs went into AwsQueryLists rather than into a third copy. That file already reads a list's values, and StsQueryHandler holds a private copy that captures the prefix and the index for the same reason this one does; the STS wave is where that copy goes. A number too large for a long is a number all the same, which the range check reads as one now. It compared through a long before, so a MaxItems of 9223372036854775808 failed to parse, read as no number at all and reached the operation past a maximum of 1000. The bound it breaks is one that fits in a long either way, so the comparison carries no width of its own, and the value is written as the number reads rather than as the request spelled it, a leading plus or zero gone, which is what a parsed value already answered. Seven unit tests cover the new forms, two of them on the reader, which is where one of them found that a key naming its own member read as a member numbered after it: the index is a number or the key is not a member's. Four wire tests cover the operation. Removing the list branch fails four of the six list and structure tests and two of the four wire tests: the two that stay green are MaxItems and Marker, scalars the walk already read, so they prove the operation was opted in rather than the walk. --- docs/services/iam.md | 21 ++ .../floci/core/common/AwsQueryLists.java | 33 +++ .../core/common/QueryConstraintCheck.java | 172 ++++++++++++-- .../core/common/SmithyValidationErrors.java | 39 +++- .../floci/services/iam/IamRequestShapes.java | 12 +- .../resources/aws/iam-request-shapes.json | 36 ++- .../floci/core/common/AwsQueryListsTest.java | 32 +++ .../core/common/QueryConstraintCheckTest.java | 221 ++++++++++++++++-- .../IamRequestConstraintsIntegrationTest.java | 86 ++++++- tools/aws/regen_iam_shapes.py | 16 +- 10 files changed, 604 insertions(+), 64 deletions(-) diff --git a/docs/services/iam.md b/docs/services/iam.md index a2f05eeeb5..fe06cfd7f6 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -171,6 +171,27 @@ hand-written check the rest of the service still uses stops at the first and rep alone. A boolean member publishes no constraint to hold it to, so a `SetAsDefault` that is neither `true` nor `false` reaches the operation, which reads anything but `true` as false. +A list is read the same way, from the parameters the protocol numbers under its name: +`Audience.member.1` or the bare `Audience.1`, with a member of a list of structures carrying its +fields under that prefix as `Tags.member.1.Key` does. Each is named in a message the way this +service already names one, `filter.1.member` and `tags.1.member.key`, under the index the request +spelled rather than the position the member sits at, and the count is held to the list's own +bounds with the value left out of the message. A member outside its enum is reported under its own +index for the same reason, which is a reading: two other services here answer one against the +whole list instead, and nothing recorded says which form AWS answers on this protocol. A list of +no members is how an absent list arrives, so a required one reads as null rather than as a list +breaking a minimum of 1. A structure member arrives as `TaskPolicyArn.Arn` and is named +`taskPolicyArn.arn`. A map is not read yet, nor is anything nested deeper than a list of +structures. The request form is published, `AcquireRole`'s own sample numbering a map as +`ReplacementValues.entry.1.key` and `.entry.1.value`, but the message this service answers for one +names the whole map rather than the entry that broke a constraint, and nothing here says which AWS +names, so reading a map would move a merged answer on a guess. `GetAccountAuthorizationDetails` is +the first operation read through the walk, and nothing of it was read before: a `Filter` member +outside the model's enum, a `MaxItems` outside 1 to 1000 and a `Marker` breaking its length or its +pattern were all answered with a 200. A number too large for a 64-bit integer is a number all the +same, so a `MaxItems` of `9223372036854775808` breaks the maximum rather than reading as no number +at all. + ### Permission Boundaries | Action | Description | diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryLists.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryLists.java index 287240144f..04105569fc 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryLists.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryLists.java @@ -4,6 +4,7 @@ import jakarta.ws.rs.core.MultivaluedMap; import java.util.Comparator; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -38,6 +39,38 @@ public final class AwsQueryLists { .toList(); } + /** + * One member of a Query list: the prefix its own parameters are named under, and the index the + * request numbered it with, read back as it was spelled rather than as the number it reads as. + */ + public record IndexedMember(String prefix, String index) { + } + + /** + * The members of {@code list}, in the order their indexes read, each with the prefix its own + * parameters are named under. Unlike {@link #values}, a member of a list of structures counts: + * its fields arrive under the prefix rather than at it, as {@code Tags.member.1.Key} does, and + * a member present with an empty value is still a member. + * + *
The index is kept as the request spelled it, {@code 007} and all, and a segment that is no
+ * number is not one: with a null {@code member}, {@code SubnetIds.SubnetIdentifier.4} is a list
+ * naming its own member rather than a member numbered {@code SubnetIdentifier}, and this reads
+ * the generic and bare forms only, as {@link #memberKeys} does.
+ */
+ public static List Scalars only for now. An operation whose input shape carries a list or a map is refused when
- * the file loads rather than passed over quietly, since reading one means reading
- * {@code Name.member.N} and {@code Name.entry.N.key} and naming each index as the request spelled
- * it.
+ * A list arrives numbered under its own name, {@code Audience.member.1} or the bare
+ * {@code Audience.1}, and a member of a list of structures carries its fields under that prefix,
+ * {@code Tags.member.1.Key}. Each is named in a message the way this package already names it:
+ * {@code audience.1.member} and {@code tags.1.member.key}, with the index the request spelled
+ * rather than the position the member sits at. A list of no members is how an absent list arrives
+ * on this protocol, so a required one reads as null rather than as a list breaking its minimum, and
+ * the count is held to the list's own bounds with the value left out of the message. A structure
+ * member arrives as {@code TaskPolicyArn.Arn} and is named {@code taskPolicyArn.arn}.
+ *
+ * A map is refused when the file loads rather than passed over quietly: this package answers one
+ * today in a form of its own, {@code Map keys must satisfy constraint: [...]} against the whole map,
+ * and which of the two forms AWS answers for a Query map is a question no source here settles. So is
+ * anything nested deeper than a list of structures or a structure of scalars.
*/
public final class QueryConstraintCheck {
@@ -47,6 +57,9 @@ public final class QueryConstraintCheck {
/** The shape types a Query parameter can carry on its own, without an index or an entry. */
private static final Set A number too large for a {@code long} is a number all the same, and the bound it breaks is
+ * one that fits in one, so the range is compared without a width of its own. The value is
+ * written as the number reads rather than as the request spelled it, a leading zero or plus
+ * gone, which is what a parsed value already answered.
*/
private static String numberViolation(JsonNode shape, String value, String path) {
- long number;
- try {
- number = Long.parseLong(value.trim());
- } catch (NumberFormatException expected) {
+ String text = value.trim();
+ if (!INTEGER.matcher(text).matches()) {
// Not a number at all, so no range of the model's is what it breaks.
return null;
}
- return SmithyValidationErrors.outOfRange(path, number,
- shape.path("min").asLong(Long.MIN_VALUE), shape.path("max").asLong(Long.MAX_VALUE));
+ BigInteger number = new BigInteger(text);
+ long min = shape.path("min").asLong(Long.MIN_VALUE);
+ long max = shape.path("max").asLong(Long.MAX_VALUE);
+ if (number.compareTo(BigInteger.valueOf(min)) < 0) {
+ return SmithyValidationErrors.valueTooSmall(path, number.toString(), min);
+ }
+ if (number.compareTo(BigInteger.valueOf(max)) > 0) {
+ return SmithyValidationErrors.valueTooLarge(path, number.toString(), max);
+ }
+ return null;
}
private static String enumViolation(JsonNode shape, String value, String path) {
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
index c9fbdb9a65..de34c23514 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
@@ -75,16 +75,29 @@ public final class SmithyValidationErrors {
/** The violation for a number outside {@code min} to {@code max}, or {@code null} for one inside. */
public static String outOfRange(String path, long value, long min, long max) {
if (value < min) {
- return "Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
- + "Member must have value greater than or equal to " + min;
+ return valueTooSmall(path, Long.toString(value), min);
}
if (value > max) {
- return "Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
- + "Member must have value less than or equal to " + max;
+ return valueTooLarge(path, Long.toString(value), max);
}
return null;
}
+ /**
+ * The violation for a number below {@code min}, with the value already written: a number too
+ * large for a {@code long} is still a number, and the bound it breaks is one that fits in one.
+ */
+ public static String valueTooSmall(String path, String value, long min) {
+ return "Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
+ + "Member must have value greater than or equal to " + min;
+ }
+
+ /** The violation for a number above {@code max}, with the value already written. */
+ public static String valueTooLarge(String path, String value, long max) {
+ return "Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
+ + "Member must have value less than or equal to " + max;
+ }
+
/** The violation for a string outside its length bounds, or {@code null} for one inside. */
public static String lengthOutOfRange(String path, String value, int min, int max) {
int length = value.codePointCount(0, value.length());
@@ -98,6 +111,24 @@ public final class SmithyValidationErrors {
return null;
}
+ /**
+ * The violation for a list holding a member count outside its bounds, or {@code null} for one
+ * inside. The offending value is left out, which is the form this package already answers for a
+ * tag list and for an audience: quoting it would echo every member of the list back in the
+ * message.
+ */
+ public static String sizeOutOfRange(String path, int size, int min, int max) {
+ if (size < min) {
+ return "Value at '" + path + "' failed to satisfy constraint: "
+ + "Member must have length greater than or equal to " + min;
+ }
+ if (size > max) {
+ return "Value at '" + path + "' failed to satisfy constraint: "
+ + "Member must have length less than or equal to " + max;
+ }
+ return null;
+ }
+
/** Also used by services that reject whitespace-only input as an empty member. */
public static String lengthTooShort(String path, String value, int min) {
return "Value '" + value + "' at '" + path + "' failed to satisfy constraint: "
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamRequestShapes.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamRequestShapes.java
index 5a80c17ff5..e2b0a2693f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamRequestShapes.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamRequestShapes.java
@@ -11,11 +11,13 @@ import jakarta.ws.rs.core.MultivaluedMap;
* ValidationError} whether or not the thing it names exists, the ordering #6402 settled for this
* package.
*
- * The vendored file carries one wave of operations rather than all 180, and grows a wave at a
- * time: the managed-policy family first, where no operation checks a declared constraint by hand,
- * so the model adds the refusals AWS answers without rewording an answer already given.
- * {@code AttachRolePolicy} and {@code DetachRolePolicy} are the exception and the parity case,
- * {@code IamService.validateRoleName} already answering {@code roleName} in the same form.
+ * The vendored file carries a wave of operations rather than all 180, and grows a wave at a
+ * time, each one chosen where no operation checks a declared constraint by hand, so the model adds
+ * the refusals AWS answers without rewording an answer already given. The managed-policy family
+ * came first, with {@code AttachRolePolicy} and {@code DetachRolePolicy} as the exception and the
+ * parity case, {@code IamService.validateRoleName} already answering {@code roleName} in the same
+ * form. {@code GetAccountAuthorizationDetails} is the first read through the list walk, its
+ * {@code Filter}, {@code MaxItems} and {@code Marker} having been read by nothing at all.
*/
final class IamRequestShapes {
diff --git a/src/main/resources/aws/iam-request-shapes.json b/src/main/resources/aws/iam-request-shapes.json
index 9bccce9f5f..0885222f05 100644
--- a/src/main/resources/aws/iam-request-shapes.json
+++ b/src/main/resources/aws/iam-request-shapes.json
@@ -15,7 +15,8 @@
"CreatePolicyVersion": "CreatePolicyVersionRequest",
"GetPolicyVersion": "GetPolicyVersionRequest",
"DeletePolicyVersion": "DeletePolicyVersionRequest",
- "SetDefaultPolicyVersion": "SetDefaultPolicyVersionRequest"
+ "SetDefaultPolicyVersion": "SetDefaultPolicyVersionRequest",
+ "GetAccountAuthorizationDetails": "GetAccountAuthorizationDetailsRequest"
},
"shapes": {
"AttachGroupPolicyRequest": {
@@ -116,6 +117,24 @@
"PolicyArn": "arnType"
}
},
+ "EntityType": {
+ "type": "string",
+ "enum": [
+ "User",
+ "Role",
+ "Group",
+ "LocalManagedPolicy",
+ "AWSManagedPolicy"
+ ]
+ },
+ "GetAccountAuthorizationDetailsRequest": {
+ "type": "structure",
+ "members": {
+ "Filter": "entityListType",
+ "MaxItems": "maxItemsType",
+ "Marker": "markerType"
+ }
+ },
"GetPolicyRequest": {
"type": "structure",
"required": [
@@ -155,12 +174,27 @@
"booleanType": {
"type": "boolean"
},
+ "entityListType": {
+ "type": "list",
+ "member": "EntityType"
+ },
"groupNameType": {
"type": "string",
"min": 1,
"max": 128,
"pattern": "[\\w+=,.@-]+"
},
+ "markerType": {
+ "type": "string",
+ "min": 1,
+ "max": 320,
+ "pattern": "[\\u0020-\\u00FF]+"
+ },
+ "maxItemsType": {
+ "type": "integer",
+ "min": 1,
+ "max": 1000
+ },
"policyDocumentType": {
"type": "string",
"min": 1,
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryListsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryListsTest.java
index 4396f9837d..1b3d5e1c49 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryListsTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryListsTest.java
@@ -50,6 +50,38 @@ class AwsQueryListsTest {
assertEquals(List.of(), AwsQueryLists.values(params, "TagKeys", "TagKey"));
}
+ @Test
+ void membersCarryThePrefixTheirFieldsArriveUnderAndTheIndexAsSpelled() {
+ MultivaluedMap {@code AttachRolePolicy}'s {@code RoleName} is the parity case rather than a change:
* {@code IamService.validateRoleName} already answered it in this form, from the same bounds and
@@ -230,4 +231,79 @@ class IamRequestConstraintsIntegrationTest {
.when().post("/").then().statusCode(404)
.body(CODE, equalTo("NoSuchEntity"));
}
+
+ /**
+ * {@code GetAccountAuthorizationDetails} is the first operation read through the list walk, and
+ * none of its three members was read at all before: a {@code Filter} outside the model's enum,
+ * a {@code MaxItems} outside its range and a {@code Marker} breaking its length all reached the
+ * operation and were answered with a 200.
+ */
+ @Test
+ void aFilterMemberOutsideItsEnumIsRefusedWhereItUsedToBeIgnored() {
+ iam("GetAccountAuthorizationDetails")
+ .formParam("Filter.member.1", "Users")
+ .when().post("/").then().statusCode(400)
+ .body(CODE, equalTo("ValidationError"))
+ .body(MESSAGE, equalTo("1 validation error detected: Value 'Users' at"
+ + " 'filter.1.member' failed to satisfy constraint: Member must satisfy enum"
+ + " value set: [User, Role, Group, LocalManagedPolicy, AWSManagedPolicy]"));
+
+ iam("GetAccountAuthorizationDetails")
+ .formParam("Filter.member.1", "User")
+ .when().post("/").then().statusCode(200)
+ .body(containsString("GetAccountAuthorizationDetailsResult"));
+ }
+
+ /**
+ * Each member of a list is named under the index the request spelled rather than the position
+ * it sits at, and the two are reported together in one message.
+ */
+ @Test
+ void twoBrokenListMembersAreReportedTogetherUnderTheIndexesTheRequestSpelled() {
+ iam("GetAccountAuthorizationDetails")
+ .formParam("Filter.member.2", "Users")
+ .formParam("Filter.member.9", "Policies")
+ .when().post("/").then().statusCode(400)
+ .body(CODE, equalTo("ValidationError"))
+ .body(MESSAGE, containsString("2 validation errors detected: Value 'Users' at"
+ + " 'filter.2.member'"))
+ .body(MESSAGE, containsString("Value 'Policies' at 'filter.9.member'"));
+ }
+
+ /** {@code maxItemsType} is 1 to 1000, which this operation reads nothing of today. */
+ @Test
+ void aMaxItemsOutsideItsRangeIsRefused() {
+ iam("GetAccountAuthorizationDetails")
+ .formParam("MaxItems", "1001")
+ .when().post("/").then().statusCode(400)
+ .body(CODE, equalTo("ValidationError"))
+ .body(MESSAGE, equalTo("1 validation error detected: Value '1001' at 'maxItems' failed"
+ + " to satisfy constraint: Member must have value less than or equal to 1000"));
+
+ iam("GetAccountAuthorizationDetails")
+ .formParam("MaxItems", "1000")
+ .when().post("/").then().statusCode(200);
+
+ // A number too large for a long is a number all the same, and 1000 is still the bound.
+ iam("GetAccountAuthorizationDetails")
+ .formParam("MaxItems", "9223372036854775808")
+ .when().post("/").then().statusCode(400)
+ .body(CODE, equalTo("ValidationError"))
+ .body(MESSAGE, equalTo("1 validation error detected: Value '9223372036854775808' at"
+ + " 'maxItems' failed to satisfy constraint: Member must have value less than"
+ + " or equal to 1000"));
+ }
+
+ /** A marker sent empty breaks its minimum and its pattern, and both are reported. */
+ @Test
+ void anEmptyMarkerBreaksItsLengthAndItsPattern() {
+ iam("GetAccountAuthorizationDetails")
+ .formParam("Marker", "")
+ .when().post("/").then().statusCode(400)
+ .body(CODE, equalTo("ValidationError"))
+ .body(MESSAGE, containsString("2 validation errors detected: Value '' at 'marker'"
+ + " failed to satisfy constraint: Member must have length greater than or"
+ + " equal to 1"))
+ .body(MESSAGE, containsString("Member must satisfy regular expression pattern:"));
+ }
}
diff --git a/tools/aws/regen_iam_shapes.py b/tools/aws/regen_iam_shapes.py
index 3908057f50..56f0a93258 100644
--- a/tools/aws/regen_iam_shapes.py
+++ b/tools/aws/regen_iam_shapes.py
@@ -24,15 +24,23 @@ OUTPUT = REPO_ROOT / "src/main/resources/aws/iam-request-shapes.json"
MODEL = Path("iam/2010-05-08")
GENERATOR = "tools/aws/regen_iam_shapes.py"
-# The managed-policy family: every member a scalar, and no operation here checks a declared
-# constraint by hand today, so the vendored shapes add the refusals AWS answers without rewording
-# anything already answered. `AttachRolePolicy` and `DetachRolePolicy` are the exception and the
-# parity case: `IamService.validateRoleName` already answers `roleName` in Smithy's form.
+# One wave per group, each chosen so that no operation in it checks a declared constraint by hand,
+# which is what keeps the vendored shapes adding the refusals AWS answers rather than rewording an
+# answer already given.
+#
+# The managed-policy family, every member a scalar. `AttachRolePolicy` and `DetachRolePolicy` are
+# the exception and the parity case: `IamService.validateRoleName` already answers `roleName` in
+# Smithy's form.
+#
+# `GetAccountAuthorizationDetails` is the first operation read through the list walk. Its three
+# members are declared and none of them is read at all today: `Filter` is a list of an enum,
+# `MaxItems` a range and `Marker` a length and a pattern.
OPERATIONS = (
"AttachGroupPolicy", "AttachRolePolicy", "AttachUserPolicy",
"DetachGroupPolicy", "DetachRolePolicy", "DetachUserPolicy",
"GetPolicy", "DeletePolicy",
"CreatePolicyVersion", "GetPolicyVersion", "DeletePolicyVersion", "SetDefaultPolicyVersion",
+ "GetAccountAuthorizationDetails",
)