fix(config): validate recorder selector list cardinality (#8269)

* fix(config): validate recorder selector list cardinality
* test(config): reuse shared SDK client setup
This commit is contained in:
Jackson Price authored and GitHub committed 2026-11-14 01:35:09 -04:00
1 parent f9eb910b62
commit c6b41a4627
4 files changed
+166

No files matched your search

+6
View File
@@ -40,6 +40,12 @@
| `StopConfigurationRecorder` | Stop recording configuration changes |
| `DescribeConfigurationRecorderStatus` | Get the status of configuration recorders. Whether a recorder is recording, and when it last started and stopped, persist with the recorder, so a started recorder is still recording after a restart |
`DescribeConfigurationRecorders` and `DescribeConfigurationRecorderStatus` accept at
most one entry in `ConfigurationRecorderNames`. More than one entry returns HTTP 400
`ValidationException`, including repeated names and requests made before any recorder exists.
An omitted or empty list selects all recorders; one unknown name returns
`NoSuchConfigurationRecorderException`.
### Delivery Channel
| Action | Description |
+6
View File
@@ -476,6 +476,12 @@
<version>${aws.sdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>config</artifactId>
<version>${aws.sdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>organizations</artifactId>
@@ -712,6 +712,7 @@ public class AwsConfigService {
}
public List<ConfigurationRecorder> describeConfigurationRecorders(String region, List<String> names, String arn) {
validateConfigurationRecorderNames(names);
ConfigurationRecorder recorder = configurationRecorders.get(region);
requireRecorderArn(arn, recorder);
if (recorder == null) {
@@ -732,6 +733,13 @@ public class AwsConfigService {
return List.of(recorder);
}
private static void validateConfigurationRecorderNames(List<String> names) {
if (names != null && names.size() > 1) {
throw new AwsException("ValidationException",
"You have specified more than one configuration recorder.", 400);
}
}
private static void requireRecorderArn(String arn, ConfigurationRecorder recorder) {
if (arn != null && (recorder == null || !arn.equals(recorder.arn()))) {
throw new AwsException("NoSuchConfigurationRecorderException",
@@ -780,6 +788,7 @@ public class AwsConfigService {
public List<ConfigurationRecorderStatus> describeConfigurationRecorderStatus(String region, List<String> names,
String arn) {
validateConfigurationRecorderNames(names);
ConfigurationRecorder recorder = configurationRecorders.get(region);
requireRecorderArn(arn, recorder);
if (recorder == null) {
@@ -0,0 +1,145 @@
package io.floci.aws.services.configservice;
import io.floci.aws.testing.AwsTestClients;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.config.ConfigClient;
import software.amazon.awssdk.services.config.model.ConfigurationRecorder;
import software.amazon.awssdk.services.config.model.ConfigurationRecorderStatus;
import software.amazon.awssdk.services.config.model.NoSuchConfigurationRecorderException;
import software.amazon.awssdk.services.config.model.ValidationException;
import software.amazon.awssdk.services.iam.IamClient;
import java.net.URI;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@QuarkusTest
class ConfigurationRecorderSelectorSdkIntegrationTest {
private static final String ACCOUNT = "000000097531";
@TestHTTPResource("/")
URI endpoint;
private ConfigClient config;
private IamClient iam;
private String name;
private boolean roleCreated;
private boolean recorderCreated;
@BeforeEach
void createOwnedRecorder() {
config = AwsTestClients.create(ConfigClient.builder(), ACCOUNT, "test", Region.US_EAST_1, endpoint);
iam = AwsTestClients.create(IamClient.builder(), ACCOUNT, "test", Region.US_EAST_1, endpoint);
name = "recorder-selector-" + Long.toString(System.nanoTime(), 36);
String roleArn = iam.createRole(request -> request.roleName(name).assumeRolePolicyDocument("""
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "config.amazonaws.com"},
"Action": "sts:AssumeRole"
}]
}
""")).role().arn();
roleCreated = true;
config.putConfigurationRecorder(request -> request.configurationRecorder(
ConfigurationRecorder.builder().name(name).roleARN(roleArn)
.recordingGroup(group -> group.allSupported(false)
.includeGlobalResourceTypes(false).resourceTypesWithStrings("AWS::S3::Bucket"))
.build()));
recorderCreated = true;
}
@AfterEach
void deleteOwnedResources() {
try {
if (recorderCreated) {
config.deleteConfigurationRecorder(request -> request.configurationRecorderName(name));
}
} finally {
try {
if (roleCreated) {
iam.deleteRole(request -> request.roleName(name));
}
} finally {
if (config != null) {
config.close();
}
if (iam != null) {
iam.close();
}
}
}
}
@ParameterizedTest
@EnumSource(RecorderOperation.class)
void omittedEmptyAndSingleNamesSelectTheOwnedRecorder(RecorderOperation operation) {
assertEquals(List.of(name), operation.read(config, null));
assertEquals(List.of(name), operation.read(config, List.of()));
assertEquals(List.of(name), operation.read(config, List.of(name)));
}
@ParameterizedTest
@EnumSource(RecorderOperation.class)
void multipleNamesAreValidationErrorsAndLeaveTheRecorderUnchanged(RecorderOperation operation) {
ConfigurationRecorder before = config.describeConfigurationRecorders(request ->
request.configurationRecorderNames(name)).configurationRecorders().getFirst();
ValidationException error = assertThrows(ValidationException.class,
() -> operation.read(config, List.of(name, name + "-missing")));
assertEquals(400, error.statusCode());
assertEquals("ValidationException", error.awsErrorDetails().errorCode());
ValidationException repeatedName = assertThrows(ValidationException.class,
() -> operation.read(config, List.of(name, name)));
assertEquals(400, repeatedName.statusCode());
assertEquals(List.of(name), operation.read(config, List.of(name)));
assertEquals(before, config.describeConfigurationRecorders(request ->
request.configurationRecorderNames(name)).configurationRecorders().getFirst());
}
@ParameterizedTest
@EnumSource(RecorderOperation.class)
void multipleNamesAreValidationErrorsWhenNoRecorderExists(RecorderOperation operation) {
config.deleteConfigurationRecorder(request -> request.configurationRecorderName(name));
recorderCreated = false;
assertEquals(List.of(), operation.read(config, null));
ValidationException error = assertThrows(ValidationException.class,
() -> operation.read(config, List.of(name, name + "-missing")));
assertEquals(400, error.statusCode());
assertEquals(List.of(), operation.read(config, null));
}
@ParameterizedTest
@EnumSource(RecorderOperation.class)
void oneMissingNameKeepsTheMissingRecorderError(RecorderOperation operation) {
NoSuchConfigurationRecorderException error = assertThrows(NoSuchConfigurationRecorderException.class,
() -> operation.read(config, List.of(name + "-missing")));
assertEquals(400, error.statusCode());
assertEquals(List.of(name), operation.read(config, List.of(name)));
}
enum RecorderOperation {
DESCRIPTIONS,
STATUS;
List<String> read(ConfigClient client, List<String> names) {
return switch (this) {
case DESCRIPTIONS -> client.describeConfigurationRecorders(request ->
request.configurationRecorderNames(names)).configurationRecorders().stream()
.map(ConfigurationRecorder::name).toList();
case STATUS -> client.describeConfigurationRecorderStatus(request ->
request.configurationRecorderNames(names)).configurationRecordersStatus().stream()
.map(ConfigurationRecorderStatus::name).toList();
};
}
}
}