fix(rds): restrict custom endpoint mutations to Aurora (#5206)

* fix(rds): restrict cluster endpoints to Aurora

* fix(rds): preserve legacy cluster endpoints

* fix(rds): align cluster endpoint restrictions
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-07 09:52:42 -04:00
1 parent 9d49e619c1
commit d8b170a144
2 files changed
+48

No files matched your search

@@ -9339,6 +9339,7 @@ public class RdsService implements Resettable, ResourceProvider {
}
String id = requireClusterEndpointIdentifier(endpointId);
DbCluster cluster = getDbCluster(clusterId, effectiveRegion);
requireAuroraCluster(cluster);
if (cluster.getStatus() != null && cluster.getStatus() != DbInstanceStatus.AVAILABLE) {
throw new AwsException("InvalidDBClusterStateFault",
"DB cluster " + cluster.getDbClusterIdentifier() + " is not in available state.", 400);
@@ -9385,6 +9386,7 @@ public class RdsService implements Resettable, ResourceProvider {
String effectiveRegion = effectiveRegion(region);
DbClusterEndpoint endpoint = requireClusterEndpoint(effectiveRegion, endpointId);
DbCluster cluster = getDbCluster(endpoint.getDbClusterIdentifier(), effectiveRegion);
requireAuroraCluster(cluster);
String customType = isBlank(endpointType) ? endpoint.getCustomEndpointType() : requireCustomEndpointType(endpointType);
boolean listsGiven = staticMembers != null || excludedMembers != null;
List<String> newStatic = listsGiven ? clusterMembersNamed(cluster, staticMembers) : endpoint.getStaticMembers();
@@ -9467,6 +9469,13 @@ public class RdsService implements Resettable, ResourceProvider {
to < matching.size() ? Integer.toString(to) : null);
}
private static void requireAuroraCluster(DbCluster cluster) {
if (!isAuroraEngine(cluster.getEngineIdentifier())) {
throw new AwsException("InvalidParameterValue",
"Custom endpoints are supported only for Aurora DB clusters.", 400);
}
}
private static boolean matchesFilter(Map<String, List<String>> filters, String name, String value) {
List<String> wanted = filters != null ? filters.get(name) : null;
if (wanted == null || wanted.isEmpty()) {
@@ -62,6 +62,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -8428,6 +8429,44 @@ class RdsServiceTest {
assertEquals("moved.example", moved.getEndpoint());
}
@Test
void customClusterEndpointMutationsRequireAurora() {
rdsService.createDbCluster("plain", "postgres", "17.5", "admin", "password", "appdb", false, null);
AwsException createError = assertThrows(AwsException.class, () ->
rdsService.createDbClusterEndpoint("us-east-1", "plain", "reports", "ANY",
List.of(), List.of(), Map.of()));
assertEquals("InvalidParameterValue", createError.getErrorCode());
assertEquals(Set.of("WRITER", "READER"), rdsService.describeDbClusterEndpoints(
"us-east-1", "plain", null, Map.of(), null, null).endpoints().stream()
.map(DbClusterEndpoint::getEndpointType)
.collect(Collectors.toSet()));
DbCluster aurora = rdsService.createDbCluster(
"aurora", "aurora-postgresql", "16.3", "admin", "password", "appdb", false, null);
rdsService.createDbClusterEndpoint("us-east-1", "aurora", "legacy", "ANY",
List.of(), List.of(), Map.of());
aurora.setEngineIdentifier("postgres");
AwsException modifyError = assertThrows(AwsException.class, () ->
rdsService.modifyDbClusterEndpoint("us-east-1", "legacy", "READER", null, null));
assertEquals("InvalidParameterValue", modifyError.getErrorCode());
List<DbClusterEndpoint> existing = rdsService.describeDbClusterEndpoints(
"us-east-1", "aurora", null, Map.of(), null, null).endpoints();
assertEquals(Set.of("WRITER", "READER", "CUSTOM"), existing.stream()
.map(DbClusterEndpoint::getEndpointType)
.collect(Collectors.toSet()));
assertEquals("deleting", rdsService.deleteDbClusterEndpoint("us-east-1", "legacy").getStatus());
aurora.setEngineIdentifier(null);
AwsException legacyCreateError = assertThrows(AwsException.class, () ->
rdsService.createDbClusterEndpoint("us-east-1", "aurora", "restored", "ANY",
List.of(), List.of(), Map.of()));
assertEquals("InvalidParameterValue", legacyCreateError.getErrorCode());
assertEquals(2, rdsService.describeDbClusterEndpoints(
"us-east-1", "aurora", null, Map.of(), null, null).endpoints().size());
}
@Test
void failoverDbClusterMovesTheWriterRole() {
rdsService.createDbCluster("aurora", "aurora-postgresql", "16.3", "admin", "password", "appdb", false, null);