feat(iam): read every modelled operation's constraints from the model (#6965)

The vendored file carried 52 of IAM's operations and carries 162 now, which
is every one of the 164 that declares a required member, a length, a pattern,
an enum or a range, bar the two account alias operations: those answer their
single member in AWS's own wording, so there is nothing left for the walk to
read on them.

What takes the last of them in is a walk that reads a Query map and anything
nested under one. A map arrives as entries numbered under its own name,
`ReplacementValues.entry.1.key` and `.entry.1.value`, and an entry's value is
named under the key that entry carried, `replacementValues.Department.values`,
which is how both maps this service answered by hand already named one and how
the JSON protocols name a map's value here. An entry is read off its key, so
one numbered with a value and no key is not an entry the map could hold. A
structure's field may be a list, a list's member may hold a list of its own
and a map's value may be a structure, so `AcquireRole`,
`PutAccountProperties`, `CreateDelegationRequest` and both simulators are read
with the rest, and the file refuses to load only for a shape of a type the
walk would pass over unread.

The two hand-written map checks come off with that. `AcquireRole`'s answers do
not move at all: the count of 30, each entry's required `Values` and the 20
values one entry admits read exactly as its own check read them, named by the
key the entry was sent under, which is what the tests it already had pin.
`PutAccountProperties` keeps the set it answered for a key, `Map keys must
satisfy constraint: [...]`, with the minimum length of 1 the model declares
now inside it where the hand-written set listed the maximum and the pattern
alone, and a value outside its bounds is answered in the words every other
member carries rather than the `must have length between 1 and 1024` that
check wrote. The `Namespace/PropertyName` rule stays exactly where it was,
being a rule the service applies after the format is good rather than a
constraint the model declares.

Two reductions keep an answer that is AWS's own rather than rewording it, both
through the hook the shared driver already takes. Eight operations answer a
member the request leaves out with "The request must contain the parameter
CertificateBody.", the wording this emulator answers for a missing Query
parameter in several services, so their shapes are vendored without the
model's required list and keep that refusal while their lengths and patterns
are read. Seventeen more are vendored without a member they answer in a
wording of their own: a service-linked role's principal and suffix, an empty
`ServiceNamespaces`, `statusType` on all four operations that take it,
`Encoding` on `GetSSHPublicKey`, the simulators' empty `ActionNames`,
`PolicyInputList` and `PolicySourceArn`, and `TagKeys` on the eight untag
operations.

Nine wordings this service wrote for itself go with the checks that wrote
them: the three password-policy ranges, the name refusal that spelled out its
own bounds and the group, server certificate and instance profile names beside
it, the path refusal, the authentication code, the virtual MFA device name and
the serial number. Each is answered by the model's own violation now, through
the one writer this package already had.

A member whose shape fixes one length is answered for that length rather than
for a bound it sits under, `Member must have length equal to 6`. That is the
wording a report's 36-character job id already answered by hand, which is why
the three report readers can be read from the model at all, and it reaches
STS through the same writer, whose `TokenCode` and `SigningAlgorithm` each fix
one length too.

Two test fixtures carried values AWS refuses and now carry values it takes.
`SignedIamUsers` named a user with a prefix plus a whole UUID, which reaches
66 characters where `userNameType` declares 64, and the two sibling fixtures
that named one the same way follow it onto the shorter suffix. The SDK suite
registered a SAML provider with a 375-character metadata document where AWS
declares 1000, so each of its two documents is padded to that bound on its
own.

`docs/services/iam.md` carries each reading, the maps among them.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-29 20:32:48 -05:00
1 parent 361b3177b8
commit 98a3d2a346
27 files changed
+2638 -482

No files matched your search

@@ -56,6 +56,26 @@ class QueryConstraintCheckTest {
}
""";
private static final String MAP_MODEL = """
{
"operations": {"Acquire": "AcquireRequest"},
"shapes": {
"AcquireRequest": {"type": "structure", "required": ["Values"], "members": {
"Values": "valueMap", "Nested": "nestedType", "Entries": "entryList"}},
"valueMap": {"type": "map", "key": "keyType", "value": "valueType", "max": 2},
"nestedType": {"type": "structure", "members": {
"Arn": "arnType", "Parameters": "nameList"}},
"entryList": {"type": "list", "member": "entryType"},
"entryType": {"type": "structure", "members": {
"Name": "keyType", "Values": "nameList"}},
"nameList": {"type": "list", "member": "keyType", "max": 2},
"keyType": {"type": "string", "min": 1, "max": 4},
"valueType": {"type": "string", "max": 3, "pattern": "[a-z]*"},
"arnType": {"type": "string", "min": 20, "max": 2048}
}
}
""";
private static final String ARN = "arn:aws:iam::000000000000:role/r";
private static QueryConstraintCheck check() throws Exception {
@@ -66,6 +86,10 @@ class QueryConstraintCheckTest {
return QueryConstraintCheck.of(MAPPER.readTree(LIST_MODEL));
}
private static QueryConstraintCheck maps() throws Exception {
return QueryConstraintCheck.of(MAPPER.readTree(MAP_MODEL));
}
private static MultivaluedMap<String, String> params(String... pairs) {
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
for (int pair = 0; pair < pairs.length; pair += 2) {
@@ -197,60 +221,59 @@ class QueryConstraintCheckTest {
}
/**
* A map is read from numbered entries whose key is a value of its own, and this package answers
* one today against the whole map rather than against an entry, so an operation carrying one is
* refused when the file loads rather than passed over without its constraints. So is anything
* nested deeper than a list of structures or a structure of scalars.
* Every member of every operation is read whatever it nests, so what the file refuses to load
* is a shape of a type this walk would pass over without reading: letting one through would
* answer a 200 for a request nothing checked. A shape that holds itself is read once rather
* than forever, which is what lets the walk go all the way down.
*/
@Test
void anOperationCarryingAMapOrDeeperNestingIsRefusedWhenTheFileLoads() throws Exception {
JsonNode map = MAPPER.readTree("""
void aShapeOfATypeTheWalkCannotReadIsRefusedWhenTheFileLoads() throws Exception {
JsonNode unread = MAPPER.readTree("""
{
"operations": {"Put": "PutRequest"},
"shapes": {
"PutRequest": {"type": "structure", "members": {"Properties": "propertyMap"}},
"propertyMap": {"type": "map", "key": "nameType", "value": "nameType"},
"nameType": {"type": "string", "min": 1}
"PutRequest": {"type": "structure", "members": {"Body": "blobType"}},
"blobType": {"type": "blob"}
}
}
""");
IllegalStateException refused =
assertThrows(IllegalStateException.class, () -> QueryConstraintCheck.of(map));
assertTrue(refused.getMessage().contains("Put's Properties is a map"), refused.getMessage());
assertThrows(IllegalStateException.class, () -> QueryConstraintCheck.of(unread));
assertTrue(refused.getMessage().contains("Put's Body is a blob"), refused.getMessage());
JsonNode listOfLists = MAPPER.readTree("""
JsonNode nestedUnread = MAPPER.readTree("""
{
"operations": {"Put": "PutRequest"},
"shapes": {
"PutRequest": {"type": "structure", "members": {"Rows": "rowList"}},
"rowList": {"type": "list", "member": "nameList"},
"nameList": {"type": "list", "member": "nameType"},
"nameType": {"type": "string", "min": 1}
}
}
""");
IllegalStateException nested =
assertThrows(IllegalStateException.class, () -> QueryConstraintCheck.of(listOfLists));
assertTrue(nested.getMessage().contains("Put's Rows is a list of list"), nested.getMessage());
JsonNode structureInStructure = MAPPER.readTree("""
{
"operations": {"Put": "PutRequest"},
"shapes": {
"PutRequest": {"type": "structure", "members": {"Target": "targetType"}},
"targetType": {"type": "structure", "members": {"Inner": "innerType"}},
"innerType": {"type": "structure", "members": {"Name": "nameType"}},
"nameType": {"type": "string", "min": 1}
"rowList": {"type": "list", "member": "rowType"},
"rowType": {"type": "structure", "members": {"At": "stampType"}},
"stampType": {"type": "timestamp"}
}
}
""");
IllegalStateException deeper = assertThrows(IllegalStateException.class,
() -> QueryConstraintCheck.of(structureInStructure));
assertTrue(deeper.getMessage().contains("Put's Target.Inner is a structure"),
deeper.getMessage());
() -> QueryConstraintCheck.of(nestedUnread));
assertTrue(deeper.getMessage().contains("Put's Rows.At is a timestamp"), deeper.getMessage());
JsonNode holdsItself = MAPPER.readTree("""
{
"operations": {"Put": "PutRequest"},
"shapes": {
"PutRequest": {"type": "structure", "members": {"Node": "nodeType"}},
"nodeType": {"type": "structure", "members": {
"Name": "nameType", "Children": "nodeList"}},
"nodeList": {"type": "list", "member": "nodeType"},
"nameType": {"type": "string", "min": 1}
}
}
""");
assertEquals(List.of("Value '' at 'node.name' failed to satisfy constraint: Member must"
+ " have length greater than or equal to 1"),
QueryConstraintCheck.of(holdsItself).violations("Put", params("Node.Name", "")));
}
/**
@@ -276,6 +299,17 @@ class QueryConstraintCheckTest {
"the bare numbered form is a member too");
}
/**
* A scalar member's value lives at its own name, so an index the request numbered only under a
* deeper key is no member of the list: nothing reads a value there, and reading one would
* answer an empty string the request never sent.
*/
@Test
void anIndexNumberedOnlyUnderADeeperKeyIsNoMemberOfAListOfScalars() throws Exception {
assertEquals(List.of(), lists().violations("Vend", params(
"Audience.member.1", "ok", "Target.Arn", ARN, "Names.member.1.Nested", "x")));
}
/**
* The count is held to the list's own bounds, with the value left out of the message: quoting it
* would echo every member of the list back. A list of no members is how an absent list arrives
@@ -445,4 +479,90 @@ class QueryConstraintCheckTest {
"SigningAlgorithm", "RS256", "Tags.member.1.Key", "Team")),
"a tag is a list of structures, named under the index the request spelled");
}
/**
* A map's entries arrive numbered under its own name, and an entry's value is named under the
* key that entry carries rather than under the number it was sent with. The key and the value
* each carry their own shape, so an entry can break both, and the map's own bounds hold the
* count with the value left out of the message.
*/
@Test
void aMapsValueIsNamedUnderTheKeyTheEntryCarries() throws Exception {
assertEquals(List.of(), maps().violations("Acquire",
params("Values.entry.1.key", "k", "Values.entry.1.value", "ok")));
assertEquals(List.of(
"Value 'toolong' at 'values' failed to satisfy constraint: Map keys must satisfy"
+ " constraint: [Member must have length less than or equal to 4, Member"
+ " must have length greater than or equal to 1]",
"Value 'NOPE' at 'values.toolong' failed to satisfy constraint: Member must"
+ " have length less than or equal to 3",
"Value 'NOPE' at 'values.toolong' failed to satisfy constraint: Member must"
+ " satisfy regular expression pattern: [a-z]*"),
maps().violations("Acquire",
params("Values.entry.1.key", "toolong", "Values.entry.1.value", "NOPE")));
assertEquals(List.of("Value at 'values' failed to satisfy constraint: Member must have"
+ " length less than or equal to 2"),
maps().violations("Acquire", params(
"Values.entry.1.key", "a", "Values.entry.1.value", "x",
"Values.entry.2.key", "b", "Values.entry.2.value", "y",
"Values.entry.3.key", "c", "Values.entry.3.value", "z")));
}
/** A map the request names nowhere is the required member reading as null. */
@Test
void aMapNamedNowhereIsTheRequiredMemberReadingAsNull() throws Exception {
assertEquals(List.of("Value null at 'values' failed to satisfy constraint: Member must not"
+ " be null"), maps().violations("Acquire", params()));
}
/**
* An entry is read off its key, so one numbered with a value and no key of its own is not an
* entry the map could hold: it is neither counted nor answered, and a map of nothing else is
* the required member reading as null.
*/
@Test
void anEntryNumberedWithNoKeyIsNoEntryAtAll() throws Exception {
assertEquals(List.of("Value null at 'values' failed to satisfy constraint: Member must not"
+ " be null"), maps().violations("Acquire", params("Values.entry.1.value", "ok")));
assertEquals(List.of(), maps().violations("Acquire", params(
"Values.entry.1.key", "k", "Values.entry.1.value", "ok",
"Values.entry.2.value", "x", "Values.entry.3.value", "y")),
"an entry with no key is not one of the two the map admits either");
}
/** The bare form the protocol also accepts, {@code Values.1.key}, reads the same way. */
@Test
void aMapEntryIsReadWithoutTheEntrySegmentToo() throws Exception {
assertEquals(List.of("Value 'toolong' at 'values' failed to satisfy constraint: Map keys"
+ " must satisfy constraint: [Member must have length less than or equal to 4,"
+ " Member must have length greater than or equal to 1]"),
maps().violations("Acquire", params("Values.1.key", "toolong", "Values.1.value", "x")));
}
/**
* A structure's field may be a list, and a list's member a structure holding one, each read
* under the name the request gives it and named the way the walk names a list anywhere.
*/
@Test
void aListInsideAStructureAndInsideAListsMemberAreBothRead() throws Exception {
assertEquals(List.of(
"Value 'toolong' at 'nested.parameters.1.member' failed to satisfy constraint:"
+ " Member must have length less than or equal to 4"),
maps().violations("Acquire", params(
"Values.entry.1.key", "k", "Values.entry.1.value", "ok",
"Nested.Parameters.member.1", "toolong")));
assertEquals(List.of(
"Value at 'entries.1.member.values' failed to satisfy constraint: Member must have"
+ " length less than or equal to 2"),
maps().violations("Acquire", params(
"Values.entry.1.key", "k", "Values.entry.1.value", "ok",
"Entries.member.1.Name", "n",
"Entries.member.1.Values.member.1", "a",
"Entries.member.1.Values.member.2", "b",
"Entries.member.1.Values.member.3", "c")));
}
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.bouncycastle.asn1.x500.X500Name;
@@ -207,9 +208,7 @@ class AssumeRoleWithSamlValidationIntegrationTest {
@Test
void duplicateProviderCreationIsRejected() {
String metadata = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
+ ISSUER + "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\"><ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data><ds:X509Certificate>"
+ certificateBase64 + "</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
String metadata = SamlMetadata.forEntity(ISSUER, certificateBase64);
given().contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateSAMLProvider").formParam("Name", PROVIDER_NAME)
.formParam("SAMLMetadataDocument", metadata)
@@ -303,9 +302,7 @@ class AssumeRoleWithSamlValidationIntegrationTest {
}
private static void registerProvider() {
String metadata = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\"" + ISSUER
+ "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\"><ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data><ds:X509Certificate>"
+ certificateBase64 + "</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
String metadata = SamlMetadata.forEntity(ISSUER, certificateBase64);
given().contentType("application/x-www-form-urlencoded").formParam("Action", "CreateSAMLProvider")
.formParam("Name", PROVIDER_NAME).formParam("SAMLMetadataDocument", metadata)
.header("Authorization", auth("iam")).when().post("/").then().statusCode(200);
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.core.common.AwsQueryController;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -723,7 +724,7 @@ class IamIntegrationTest {
void getAccessKeyLastUsedReturnsNeverUsedShape() {
given()
.formParam("Action", "GetAccessKeyLastUsed")
.formParam("AccessKeyId", "AKIAEXAMPLE")
.formParam("AccessKeyId", "AKIAIOSFODNN7EXAMPLE")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request")
.when()
@@ -792,8 +793,7 @@ class IamIntegrationTest {
@Order(54)
void getSamlProviderDoesNotCrossAccountBoundaries() {
String providerName = "cross-account-saml-" + System.nanoTime();
String metadata = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\"https://idp.example.test/"
+ providerName + "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\"><ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data><ds:X509Certificate>Y2VydA==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
String metadata = SamlMetadata.forEntity("https://idp.example.test/" + providerName);
String ownerAuth = "AWS4-HMAC-SHA256 Credential=111111111111/20260227/us-east-1/iam/aws4_request";
String otherAccountAuth = "AWS4-HMAC-SHA256 Credential=222222222222/20260227/us-east-1/iam/aws4_request";
given().formParam("Action", "CreateSAMLProvider").formParam("Name", providerName)
@@ -1728,8 +1728,10 @@ class IamIntegrationTest {
.when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'roleName' failed to satisfy constraint: Member must have length greater than or equal to 1"));
.body("ErrorResponse.Error.Message", equalTo("2 validation errors detected: Value at"
+ " 'roleName' failed to satisfy constraint: Member must have length greater"
+ " than or equal to 1; Value at 'roleName' failed to satisfy constraint:"
+ " Member must satisfy regular expression pattern: [\\w+=,.@-]+"));
given()
.formParam("Action", "CreateRole")
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.Totp;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -977,11 +978,7 @@ class IamListPaginationIntegrationTest {
}
private static String samlMetadata(String entityId) {
return "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
+ entityId + "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\">"
+ "<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
+ "<ds:X509Certificate>cGFnaW5n</ds:X509Certificate></ds:X509Data></ds:KeyInfo>"
+ "</md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
return SamlMetadata.forEntity(entityId, "cGFnaW5n");
}
/** One fixture per paginated operation, each listing at least two items where it can. */
@@ -10,8 +10,8 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
/**
* The declared constraints the managed-policy family and {@code GetAccountAuthorizationDetails} are
* now read against, from the model rather than from a hand-written check. What they change is the
* The declared constraints every operation is read against, from the model rather than from a
* hand-written check. What they change is the
* status: a value that breaks a declared constraint used to reach the store and answer
* {@code NoSuchEntity}, or on the second of those to be answered with a 200, where AWS's validation
* layer runs ahead of the operation and answers {@code ValidationError}, which is the ordering
@@ -175,13 +175,16 @@ class IamRequestConstraintsIntegrationTest {
+ " Value at 'roleName' failed to satisfy constraint: Member must satisfy"
+ " regular expression pattern: [\\w+=,.@-]+"));
// The same empty name on an operation this wave leaves alone, reported the older way.
// And the same empty name on `CreateRole`, which is read from the model as well now, so
// both constraints are reported there too where the hand-written check stopped at one.
iam("CreateRole")
.formParam("RoleName", "")
.formParam("AssumeRolePolicyDocument", TRUST_POLICY)
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 1"));
.body(MESSAGE, equalTo("2 validation errors detected: Value at 'roleName' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 1;"
+ " Value at 'roleName' failed to satisfy constraint: Member must satisfy"
+ " regular expression pattern: [\\w+=,.@-]+"));
}
/**
@@ -305,4 +308,78 @@ class IamRequestConstraintsIntegrationTest {
+ " equal to 1"))
.body(MESSAGE, containsString("Member must satisfy regular expression pattern:"));
}
/**
* A map's key is held to every rule its shape declares, answered as a set under the map's own
* name, and its value is held to its shape under the key the entry carried. The key's own
* length and pattern were read before this, by a hand-written check the model now answers for;
* an empty value reached the store.
*/
@Test
void aMapsKeyAndValueAreEachHeldToTheirShape() {
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", "1-not-a-key")
.formParam("Properties.entry.1.value", "v")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value at 'properties' failed to"
+ " satisfy constraint: Map keys must satisfy constraint: [Member must have"
+ " length less than or equal to 50, Member must have length greater than or"
+ " equal to 1, Member must satisfy regular expression pattern:"
+ " ^[A-Za-z][A-Za-z0-9/_-]*$]"));
iam("PutAccountProperties")
.formParam("Properties.entry.1.key", "Ok/Value")
.formParam("Properties.entry.1.value", "")
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value at 'properties.Ok/Value'"
+ " failed to satisfy constraint: Member must have length greater than or"
+ " equal to 1"));
// A map the request names nowhere is the required member reading as null.
iam("PutAccountProperties")
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value null at 'properties' failed"
+ " to satisfy constraint: Member must not be null"));
}
/**
* A map whose value is a structure holding a list is read all the way down, which is the
* deepest request this service models: {@code AcquireRole} numbers its replacement values as
* entries and each entry's structure carries a list of its own. An entry the request numbered
* with a key is an entry, so what the structure under it requires is answered inside it, named
* under that key, which is the answer the hand-written check this replaces already gave.
*/
@Test
void aMapValuesStructureAndTheListInsideItAreRead() {
iam("AcquireRole")
.formParam("TemplateArn", "arn:aws:iam::000000000000:policy-template/t")
.formParam("ReplacementValues.entry.1.key", "Department")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value null at"
+ " 'replacementValues.Department.values' failed to satisfy constraint: Member"
+ " must not be null"));
}
/**
* A structure's field may be a list, and its members structures of their own. The name of a
* policy parameter is 5 characters at least, which nothing read before.
*/
@Test
void aListInsideAStructureIsReadUnderTheNamesTheRequestGives() {
iam("CreateDelegationRequest")
.formParam("Description", "a delegation")
.formParam("RequestorWorkflowId", "wf-0001")
.formParam("NotificationChannel", "channel")
.formParam("SessionDuration", "3600")
.formParam("Permissions.PolicyTemplateArn", "arn:aws:iam::000000000000:policy/t")
.formParam("Permissions.Parameters.member.1.Name", "abc")
.formParam("Permissions.Parameters.member.1.Type", "string")
.when().post("/").then().statusCode(400)
.body(CODE, equalTo("ValidationError"))
.body(MESSAGE, equalTo("1 validation error detected: Value at"
+ " 'permissions.parameters.1.member.name' failed to satisfy constraint:"
+ " Member must have length greater than or equal to 5"));
}
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.github.hectorvent.floci.testutil.AwsRequestSigner;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
@@ -304,13 +305,8 @@ class IamResourceScopedPolicyEnforcementIntegrationTest {
.statusCode(200);
}
/** The shape {@code SAMLProviderLifecycleIntegrationTest} already establishes as acceptable. */
private static String samlMetadata(String entityId) {
return "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
+ entityId + "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\">"
+ "<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
+ "<ds:X509Certificate>c2NvcGVk</ds:X509Certificate></ds:X509Data></ds:KeyInfo>"
+ "</md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
return SamlMetadata.forEntity(entityId, "c2NvcGVk");
}
private String createUser(String name, String... extraParams) {
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -25,11 +26,8 @@ class IamTagValidationIntegrationTest {
private static final String POLICY_DOCUMENT = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\","
+ "\"Action\":\"s3:GetObject\",\"Resource\":\"*\"}]}";
private static final String THUMBPRINT = "9e99a48a9960b14926bb7f3b02e22da2b0ab7280";
private static final String SAML_METADATA = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\""
+ " entityID=\"https://idp.example.test/untag-key\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\">"
+ "<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
+ "<ds:X509Certificate>dW50YWc=</ds:X509Certificate></ds:X509Data></ds:KeyInfo>"
+ "</md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
private static final String SAML_METADATA =
SamlMetadata.forEntity("https://idp.example.test/untag-key", "dW50YWc=");
private static RequestSpecification iam(String action) {
return given().header("Authorization", IAM_AUTH).formParam("Action", action);
@@ -300,9 +300,11 @@ class OrganizationsAccessReportIntegrationTest {
.formParam("EntityPath", "o-a1b2c3d4e5")
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'entityPath' failed to satisfy constraint: Member must have length"
+ " greater than or equal to 19"));
.body("ErrorResponse.Error.Message", equalTo("2 validation errors detected: Value"
+ " at 'entityPath' failed to satisfy constraint: Member must have length"
+ " greater than or equal to 19; Value at 'entityPath' failed to satisfy"
+ " constraint: Member must satisfy regular expression pattern:"
+ " ^o-[0-9a-z]{10,32}\\/r-[0-9a-z]{4,32}[0-9a-z-\\/]*"));
iam(MANAGEMENT_ACCOUNT, "GenerateOrganizationsAccessReport")
.formParam("EntityPath", "o-a1b2c3d4e5/x-0000/not a path")
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.testing.SamlMetadata;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -21,11 +22,7 @@ class SAMLProviderLifecycleIntegrationTest {
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";
private static String metadataFor(String entityId, String certBase64) {
return "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\" entityID=\""
+ entityId + "\"><md:IDPSSODescriptor><md:KeyDescriptor use=\"signing\">"
+ "<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
+ "<ds:X509Certificate>" + certBase64 + "</ds:X509Certificate></ds:X509Data></ds:KeyInfo>"
+ "</md:KeyDescriptor></md:IDPSSODescriptor></md:EntityDescriptor>";
return SamlMetadata.forEntity(entityId, certBase64);
}
private static RequestSpecification iam(String action) {
@@ -78,19 +75,25 @@ class SAMLProviderLifecycleIntegrationTest {
* An omitted SAMLMetadataDocument is a no-op (above), but an explicitly empty one is
* invalid input, the same as CreateSAMLProvider already rejects it as: the two are
* distinguishable at the wire level (parameter absent vs. present with an empty value),
* and only the former should be treated as "nothing to update."
* and only the former should be treated as "nothing to update." An empty one is refused ahead
* of that by the document's own minimum length.
*/
@Test
void updateSamlProviderWithAnExplicitlyEmptyMetadataDocumentReturnsInvalidInput() {
String name = "update-empty-metadata-saml-" + System.nanoTime();
String arn = createProvider(name, "https://idp.example.test/not-emptied", "bm90ZW1wdGllZA==");
// The document declares a minimum of 1000 characters, so an empty one never reaches the
// parse that would call it invalid input: it is the constraint that refuses it.
iam("UpdateSAMLProvider")
.formParam("SAMLProviderArn", arn)
.formParam("SAMLMetadataDocument", "")
.when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"));
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at"
+ " 'sAMLMetadataDocument' failed to satisfy constraint: Member must have"
+ " length greater than or equal to 1000"));
iam("GetSAMLProvider").formParam("SAMLProviderArn", arn)
.when().post("/").then()
@@ -103,9 +106,11 @@ class SAMLProviderLifecycleIntegrationTest {
String name = "update-bad-metadata-saml-" + System.nanoTime();
String arn = createProvider(name, "https://idp.example.test/ok", "b2s=");
// Long enough to clear the document's own minimum, so what refuses it is the parse.
iam("UpdateSAMLProvider")
.formParam("SAMLProviderArn", arn)
.formParam("SAMLMetadataDocument", "<not-a-valid-saml-document/>")
.formParam("SAMLMetadataDocument",
"<not-a-valid-saml-document/>" + "<!-- " + "x".repeat(1000) + " -->")
.when().post("/").then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"));
@@ -221,10 +221,10 @@ class ServiceSpecificCredentialIntegrationTest {
.when().post("/").then().statusCode(400)
.body(containsString("ValidationError"))
.body(containsString("credentialAgeDays"))
// The range report builds its message across two string literals, so a sweep
// for the phrase missed it while every other one was prefixed.
// The range comes from the model now, in the words every other range violation
// carries, where this operation wrote one of its own.
.body(containsString("1 validation error detected"))
.body(containsString("Member must be between"));
.body(containsString("Member must have value"));
}
// And both ends of the range are accepted, so the bounds are not off by one.
@@ -73,7 +73,7 @@ class StsRequestConstraintsIntegrationTest {
.body(MESSAGE, equalTo("2 validation errors detected: Value 'bad#serial' at"
+ " 'serialNumber' failed to satisfy constraint: Member must satisfy regular"
+ " expression pattern: [\\w+=/:,.@-]*; Value '12345' at 'tokenCode' failed to"
+ " satisfy constraint: Member must have length greater than or equal to 6"));
+ " satisfy constraint: Member must have length equal to 6"));
sts("GetSessionToken")
.formParam("TokenCode", "abcdef")
@@ -187,7 +187,7 @@ class StsRequestConstraintsIntegrationTest {
.when().post("/").then().statusCode(400)
.body(MESSAGE, equalTo("1 validation error detected: Value 'HS25' at"
+ " 'signingAlgorithm' failed to satisfy constraint: Member must have length"
+ " greater than or equal to 5"))
+ " equal to 5"))
.body(MESSAGE, not(containsString("enum value set")));
}
@@ -268,7 +268,8 @@ class WebIdentityTokenIntegrationTest {
/**
* {@code jwtAlgorithmType} publishes a fixed length of 5 and no enum, so the length is the
* declared constraint and the two values the Reference names are read from it.
* declared constraint, answered for the length it fixes rather than for a bound a value sits
* under, and the two values the Reference names are read from it.
*/
@Test
void aSigningAlgorithmIsHeldToItsLengthAndThenToTheTwoValues() {
@@ -276,7 +277,7 @@ class WebIdentityTokenIntegrationTest {
token("RS25").when().post("/").then().statusCode(400)
.body(MESSAGE, containsString("Value 'RS25' at 'signingAlgorithm' failed to satisfy"
+ " constraint: Member must have length greater than or equal to 5"));
+ " constraint: Member must have length equal to 5"));
token("HS256").when().post("/").then().statusCode(400)
.body(MESSAGE, containsString("Value 'HS256' at 'signingAlgorithm' failed to satisfy"
@@ -64,7 +64,9 @@ public final class DynamoDbAuthorizationFixtures {
}
public String user(String policy) {
return userNamed(prefix + UUID.randomUUID(), policy);
// Eight characters of a UUID rather than a whole one: a user name is held to the 64
// characters its shape declares, which a prefix plus a whole UUID can break.
return userNamed(prefix + UUID.randomUUID().toString().substring(0, 8), policy);
}
/** A user whose name the caller chooses, for a policy that has to name it. */
@@ -16,7 +16,9 @@ public final class LogsAuthorizationFixtures {
public static String user(PartitionCleanup cleanup, int port, String account, String prefix,
String policyName, String statements) {
String name = prefix + UUID.randomUUID();
// Eight characters of a UUID rather than a whole one: a user name is held to the 64
// characters its shape declares, which a prefix plus a whole UUID can break.
String name = prefix + UUID.randomUUID().toString().substring(0, 8);
String root = EnforcementFixtures.auth(account, "iam");
String key = EnforcementFixtures.createUser(cleanup, port, root, name).accessKeyId();
given().port(port).header("Authorization", root).formParam("Action", "PutUserPolicy")
@@ -0,0 +1,52 @@
package io.github.hectorvent.floci.testing;
/**
* The SAML metadata document a test registers a provider with. AWS declares
* {@code SAMLMetadataDocument} at a minimum of 1000 characters, which a document carrying nothing
* but an entity id and one signing key does not reach, so the filler comment brings it to that
* length. The document is built here rather than copied into each test: six of them registered a
* provider with a document of their own, and the constraints read off the model hold every one of
* them to the same bound.
*/
public final class SamlMetadata {
/** The minimum the model declares for the document. */
public static final int MINIMUM_LENGTH = 1000;
private static final String DEFAULT_CERTIFICATE = "Y2VydA==";
private SamlMetadata() {
}
/** The document for {@code entityId}, carrying a stand-in signing certificate. */
public static String forEntity(String entityId) {
return forEntity(entityId, DEFAULT_CERTIFICATE);
}
/** The same, carrying {@code certificateBase64} as the signing certificate. */
public static String forEntity(String entityId, String certificateBase64) {
String document = "<md:EntityDescriptor xmlns:md=\"urn:oasis:names:tc:SAML:2.0:metadata\""
+ " entityID=\"" + entityId + "\"><md:IDPSSODescriptor>"
+ "<md:KeyDescriptor use=\"signing\">"
+ "<ds:KeyInfo xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\"><ds:X509Data>"
+ "<ds:X509Certificate>" + certificateBase64 + "</ds:X509Certificate>"
+ "</ds:X509Data></ds:KeyInfo></md:KeyDescriptor></md:IDPSSODescriptor>";
String end = "</md:EntityDescriptor>";
return document + padding(document.length() + end.length()) + end;
}
/**
* A comment long enough to bring the document to the model's minimum, which parses as nothing
* at all: the document's entity id and signing certificate are what the service reads.
*/
private static String padding(int length) {
int wanted = MINIMUM_LENGTH - length;
if (wanted <= 0) {
return "";
}
String open = "<!-- ";
String close = " -->";
int filler = Math.max(1, wanted - open.length() - close.length());
return open + "x".repeat(filler) + close;
}
}
@@ -46,10 +46,15 @@ public final class SignedIamUsers {
* Creates a user named {@code namePrefix} plus a random suffix, with one access key and the
* inline policy {@code policyName} holding {@code policyDocument}. If a later step fails, the
* parts already made are removed before the failure is rethrown.
*
* <p>The suffix is eight characters of a UUID rather than a whole one, which keeps the name
* inside the 64 characters {@code userNameType} declares: the constraints read ahead of the
* operation hold it to the bound AWS holds it to, where a prefix plus a whole UUID reaches 66
* and is refused before the user is made.
*/
public static User createUser(URI endpoint, String namePrefix, String policyName, String policyDocument)
throws Exception {
String name = namePrefix + UUID.randomUUID();
String name = namePrefix + UUID.randomUUID().toString().substring(0, 8);
iam(endpoint, "CreateUser", Map.of("UserName", name)).then().statusCode(200);
User user = new User(endpoint, name, policyName, null, null);
try {