fix(config): check requests against the modeled constraints (#8363)

The Config handler read each member with asText, asInt or path and
checked only some of them by hand, so an empty or over-long Arn on the
two recorder Describe calls answered
NoSuchConfigurationRecorderException, and an empty ResourceArn on the
three tag operations was accepted, as was an over-long one that isn't
a Config resource's ARN.

tools/aws/regen_config_shapes.py now vendors every Config operation's
request constraints from botocore, kept in sync by make aws-data-check,
and RequestConstraintCheck checks each served operation's request
before it runs. A violation is a ValidationException, which the model
documents for missing required fields and input that fails validation,
and a Limit out of range answers the InvalidLimitException its
operation models.

The hand-written checks the table covers are gone, putConfigRule's
included: ConfigCfnProvisioner now checks the rule it builds as a
PutConfigRule request before storing it, so a template property outside
the constraints fails the resource. A rule without a ConfigRuleName
keeps its InvalidParameterValueException, since the model doesn't
require the member.

The loop that drops blob and timestamp members moves into
request_shapes as drop_blob_and_timestamp_members, used by both the
Config and Kinesis generators. Both vendored files are unchanged.
This commit is contained in:
soreavis authored and GitHub committed 2026-11-14 19:35:00 -04:00
1 parent 08b2bae267
commit 6de963848b
21 files changed
+3506 -286

No files matched your search

@@ -9,6 +9,8 @@ import io.floci.aws.services.cloudformation.model.StackResource;
import io.floci.aws.services.configservice.AwsConfigService;
import io.floci.aws.services.configservice.model.ConfigRule;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@@ -124,6 +126,36 @@ class ConfigCfnProvisionerTest {
verifyNoInteractions(config);
}
@ParameterizedTest
@ValueSource(strings = {
"{\"Source\":{}}",
"{\"Source\":{\"Owner\":\"SOMEONE\"}}",
"{\"Source\":{\"Owner\":\"CUSTOM_LAMBDA\",\"SourceDetails\":[{\"MessageType\":\"Daily\"}]}}",
"{\"Source\":{\"Owner\":\"AWS\"},\"MaximumExecutionFrequency\":\"Hourly\"}",
"{\"Source\":{\"Owner\":\"AWS\"},\"EvaluationModes\":[{\"Mode\":\"BOTH\"}]}"})
void configRuleOutsideTheModeledConstraintsFailsBeforeCallingConfig(String props) throws Exception {
JsonNode template = mapper.readTree(props);
AwsException failure = assertThrows(AwsException.class,
() -> provisioner.provision(resource(), template, context()));
assertEquals("ValidationException", failure.getErrorCode());
verifyNoInteractions(config);
}
@Test
void configRuleViolationUsesTheConfigValidationMessage() {
ObjectNode props = mapper.createObjectNode().put("Description", "d".repeat(257));
props.set("Source", mapper.createObjectNode().put("Owner", "AWS"));
AwsException failure = assertThrows(AwsException.class,
() -> provisioner.provision(resource(), props, context()));
assertEquals("Invalid parameter at 'ConfigRule.Description' failed to satisfy constraint: "
+ "'Member must have length less than or equal to 256'", failure.getMessage());
verifyNoInteractions(config);
}
@Test
void scopeWithoutComplianceResourceTypesLeavesThemUnset() {
ObjectNode props = mapper.createObjectNode().put("ConfigRuleName", "tagged-only");
@@ -182,11 +182,23 @@ class AggregationAuthorizationIntegrationTest {
""")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
/** DescribeAggregationAuthorizations models InvalidLimitException for a Limit out of range. */
@Test
@Order(9)
void describeRejectsALimitAboveTheModeledMaximum() {
RestAssuredJsonUtils.awsAction("StarlingDoveService", "DescribeAggregationAuthorizations", """
{"Limit": 101}
""")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidLimitException"));
}
@Test
@Order(9)
@Order(10)
void unrelatedActionsStillReportInvalidAction() {
call("PutAggregationAuthorizations", authorizationBody())
.then()
@@ -245,15 +245,6 @@ class AwsConfigServiceAggregationAuthorizationTest {
assertTrue(service.storedTags(arn).isEmpty(), "the deleted pack's tags survived");
}
@Test
void rejectsAnAccountIdThatIsNotTwelveDigits() {
AwsConfigService service = service();
AwsException ex = assertThrows(AwsException.class,
() -> service.putAggregationAuthorization(REGION, "12345", "eu-west-1", null));
assertEquals("InvalidParameterValueException", ex.getErrorCode());
}
@Test
void rejectsAMissingAuthorizedRegion() {
AwsConfigService service = service();
@@ -263,15 +254,6 @@ class AwsConfigServiceAggregationAuthorizationTest {
assertEquals("InvalidParameterValueException", ex.getErrorCode());
}
@Test
void rejectsALimitAboveTheModeledMaximum() {
AwsConfigService service = service();
AwsException ex = assertThrows(AwsException.class,
() -> service.describeAggregationAuthorizations(REGION, 101, null));
assertEquals("InvalidLimitException", ex.getErrorCode());
}
@Test
void describePaginatesWithNextToken() {
AwsConfigService service = service();
@@ -424,7 +424,7 @@ class ComplianceEvaluationIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidResultTokenException"));
.body("__type", equalTo("ValidationException"));
}
@Test
@@ -476,7 +476,7 @@ class ComplianceEvaluationIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
@Test
@@ -192,7 +192,7 @@ class ConfigPaginationIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
@Test
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -284,7 +284,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("NoSuchConfigRuleException"));
.body("__type", equalTo("ValidationException"));
}
/**
@@ -324,7 +324,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
// Nothing was stored under any of the rejected names.
@@ -373,7 +373,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
StringBuilder tooManyTypes = new StringBuilder();
@@ -390,7 +390,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
given()
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules")
@@ -423,7 +423,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
@Test
@@ -439,7 +439,7 @@ class ConfigRuleIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
@Test
@@ -478,19 +478,20 @@ class ConfigRuleIntegrationTest {
}
/** PutConfigRule's TagsList (config/2014-11-12): at most 50 tags, Key 1-128, Value 0-256,
* rejected with the operation's modelled InvalidParameterValueException and nothing stored. */
* rejected with ValidationException and nothing stored. The model leaves Key optional, so a
* tag without one keeps the operation's modelled InvalidParameterValueException. */
@Test
@Order(101)
void putConfigRuleRejectsInvalidTagsWithoutCreatingTheRule() {
String fiftyOne = String.join(",", Collections.nCopies(51, "{\"Key\": \"k\", \"Value\": \"v\"}"));
List<String> invalid = List.of(
"{\"Value\": \"v\"}",
"{\"Key\": \"\", \"Value\": \"v\"}",
"{\"Key\": \"" + "k".repeat(129) + "\", \"Value\": \"v\"}",
"{\"Key\": \"k\", \"Value\": \"" + "v".repeat(257) + "\"}",
"{\"Key\": 7, \"Value\": \"v\"}",
fiftyOne);
for (String tags : invalid) {
Map<String, String> invalid = Map.of(
"{\"Value\": \"v\"}", "InvalidParameterValueException",
"{\"Key\": \"\", \"Value\": \"v\"}", "ValidationException",
"{\"Key\": \"" + "k".repeat(129) + "\", \"Value\": \"v\"}", "ValidationException",
"{\"Key\": \"k\", \"Value\": \"" + "v".repeat(257) + "\"}", "ValidationException",
"{\"Key\": 7, \"Value\": \"v\"}", "ValidationException",
fiftyOne, "ValidationException");
invalid.forEach((tags, errorCode) ->
post("PutConfigRule", """
{
"ConfigRule": {
@@ -501,8 +502,7 @@ class ConfigRuleIntegrationTest {
}
""".formatted(tags))
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
}
.body("__type", equalTo(errorCode)));
post("DescribeConfigRules", "{\"ConfigRuleNames\": [\"rule-bad-tags\"]}")
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigRuleException"));
@@ -531,7 +531,7 @@ class ConfigRuleIntegrationTest {
post("DeleteConfigRule", "{\"ConfigRuleName\": \"rule-keyonly-tag\"}").then().statusCode(200);
}
/** PutAggregationAuthorization takes the same TagsList and models the same error. */
/** PutAggregationAuthorization takes the same TagsList. */
@Test
@Order(103)
void putAggregationAuthorizationRejectsAnInvalidTag() {
@@ -540,7 +540,7 @@ class ConfigRuleIntegrationTest {
"Tags": [{"Key": "", "Value": "v"}]}
""")
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
post("DescribeAggregationAuthorizations", "{}")
.then().statusCode(200)
.body("AggregationAuthorizations.AuthorizedAccountId", not(hasItem("444455556666")));
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -146,6 +148,53 @@ class ConfigTaggingIntegrationTest {
.body("__type", equalTo("ResourceNotFoundException"));
}
/** ResourceArn is an AmazonResourceName, 1-1000 characters, on all three tag operations. */
@Test
@Order(6)
void aResourceArnOutsideItsModeledLengthIsAValidationException() {
Map<String, String> requests = Map.of(
"TagResource", "{\"ResourceArn\": \"%s\", \"Tags\": [{\"Key\": \"k\", \"Value\": \"v\"}]}",
"UntagResource", "{\"ResourceArn\": \"%s\", \"TagKeys\": [\"k\"]}",
"ListTagsForResource", "{\"ResourceArn\": \"%s\"}");
requests.forEach((action, body) -> {
RestAssuredJsonUtils.awsAction("StarlingDoveService", action, body.formatted(""))
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Invalid parameter at 'ResourceArn' failed to satisfy constraint: "
+ "'Member must have length greater than or equal to 1'"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", action, body.formatted("a".repeat(1001)))
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Invalid parameter at 'ResourceArn' failed to satisfy constraint: "
+ "'Member must have length less than or equal to 1000'"));
});
}
/** A missing required member and a member of the wrong JSON type fail before the operation runs;
* ListTagsForResource models InvalidLimitException for a Limit out of range. */
@Test
@Order(7)
void requestsOutsideTheModeledShapesFailBeforeTheOperationRuns() {
String arn = getConfigRuleArn("tag-test-rule");
RestAssuredJsonUtils.awsAction("StarlingDoveService", "UntagResource", """
{"ResourceArn": "%s"}
""".formatted(arn))
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Invalid parameter at 'TagKeys' failed to satisfy constraint: "
+ "'Member must not be null'"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "TagResource", """
{"ResourceArn": "%s", "Tags": {"Key": "k", "Value": "v"}}
""".formatted(arn))
.then().statusCode(400)
.body("__type", equalTo("ValidationException"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", "ListTagsForResource", """
{"ResourceArn": "%s", "Limit": 101}
""".formatted(arn))
.then().statusCode(400)
.body("__type", equalTo("InvalidLimitException"));
}
private String getConfigRuleArn(String ruleName) {
return given()
.header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules")
@@ -8,6 +8,8 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -432,8 +434,7 @@ class ConfigurationRecorderIntegrationTest {
.body("ConfigurationRecorders[0]", not(hasKey("recordingMode")));
}
/** PutConfigurationRecorder's Tags is a TagsList, and the operation models ValidationException,
* not the InvalidParameterValueException PutConfigRule answers. */
/** PutConfigurationRecorder's Tags is a TagsList, and the operation models ValidationException. */
@Test
@Order(19)
void putConfigurationRecorderRejectsAnInvalidTagWithoutStoringIt() {
@@ -592,4 +593,22 @@ class ConfigurationRecorderIntegrationTest {
.then().statusCode(400)
.body("__type", equalTo("NoSuchConfigurationRecorderException"));
}
/** Arn is an AmazonResourceName, 1-1000 characters, on both Describe calls. */
@Test
@Order(23)
void anArnOutsideItsModeledLengthIsAValidationException() {
for (String action : List.of("DescribeConfigurationRecorders", "DescribeConfigurationRecorderStatus")) {
RestAssuredJsonUtils.awsAction("StarlingDoveService", action, "{\"Arn\": \"\"}")
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Invalid parameter at 'Arn' failed to satisfy constraint: "
+ "'Member must have length greater than or equal to 1'"));
RestAssuredJsonUtils.awsAction("StarlingDoveService", action, "{\"Arn\": \"" + "a".repeat(1001) + "\"}")
.then().statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Invalid parameter at 'Arn' failed to satisfy constraint: "
+ "'Member must have length less than or equal to 1000'"));
}
}
}
@@ -1,20 +1,19 @@
package io.floci.aws.services.configservice;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* DescribeConfigRules' ConfigRuleNames member is modeled with {@code Maximum 25 items}
* (confirmed against botocore's config service-2.json). Every other array-size limit this
* PR touches (Scope.ComplianceResourceTypes, PutEvaluations, PutRetentionConfiguration's
* day range) is enforced; this one was not.
* (confirmed against botocore's config service-2.json), which ConfigRequestShapes checks
* before the handler reads the names.
*/
class DescribeConfigRulesLimitTest {
@@ -22,14 +21,17 @@ class DescribeConfigRulesLimitTest {
@Test
void rejectsMoreThanTwentyFiveRuleNames() {
AwsConfigService service = new AwsConfigService(new RegionResolver(REGION, "000000000000"), null);
List<String> tooMany = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
ConfigServiceJsonHandler handler = new ConfigServiceJsonHandler(
new AwsConfigService(new RegionResolver(REGION, "000000000000"), null), mapper);
ObjectNode request = mapper.createObjectNode();
ArrayNode tooMany = request.putArray("ConfigRuleNames");
for (int i = 0; i < 26; i++) {
tooMany.add("rule-" + i);
}
AwsException ex = assertThrows(AwsException.class,
() -> service.describeConfigRules(REGION, tooMany));
assertEquals("InvalidParameterValueException", ex.getErrorCode());
() -> handler.handle("DescribeConfigRules", request, REGION));
assertEquals("ValidationException", ex.getErrorCode());
}
}
@@ -69,7 +69,7 @@ class RetentionConfigurationIntegrationTest {
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"));
.body("__type", equalTo("ValidationException"));
}
@Test