feat(rds): Aurora custom cluster endpoints (#5090)

Serve CreateDBClusterEndpoint, DescribeDBClusterEndpoints,
ModifyDBClusterEndpoint and DeleteDBClusterEndpoint.

A custom endpoint is stored per Region with the rules from the API
reference and the Aurora user guide: type READER or ANY, a static or an
exclusion member list but not both, members that are instances of the
cluster, no writer in a READER endpoint, an RDS identifier stored lower
case and unique in the Region, and at most five per cluster. Its ARN
(cluster-endpoint:<id>) works with the tagging actions.

DescribeDBClusterEndpoints lists each cluster's built-in WRITER and
READER endpoints with its custom ones, and supports the cluster and
endpoint identifiers, the four documented filters and paging. Deleting a
cluster deletes its custom endpoints, and a deleted instance drops out of
the member lists.

Custom endpoints are modelled, not routed: one reports the cluster's own
endpoint host, so connections through it go where the cluster endpoint
sends them.

Closes #5072
This commit is contained in:
David authored and GitHub committed 2026-10-05 14:48:06 -04:00
1 parent 4be8309e8d
commit f157d354f2
8 files changed
+859 -1

No files matched your search

@@ -0,0 +1,232 @@
package io.github.hectorvent.floci.services.rds;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.URLENC;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
/**
* Aurora custom endpoints over the Query protocol: create, describe alongside the built-in
* writer and reader endpoints, modify, tag and delete, with the API reference's and the Aurora
* user guide's rules on types, member lists, identifiers and the per-cluster limit.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class RdsClusterEndpointIntegrationTest {
private static final String CLUSTER = "cep-cluster";
private static final String WRITER = "cep-writer";
private static final String READER = "cep-reader";
private static final String DESCRIBE_LIST =
"DescribeDBClusterEndpointsResponse.DescribeDBClusterEndpointsResult.DBClusterEndpoints.DBClusterEndpointList";
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=test/20261004/us-east-1/rds/aws4_request, "
+ "SignedHeaders=content-type;host, Signature=test";
private static RequestSpecification query(String action) {
return given().header("Authorization", AUTH)
.contentType(URLENC)
.formParam("Action", action)
.formParam("Version", "2014-10-31");
}
private static RequestSpecification createEndpoint(String id, String type) {
return query("CreateDBClusterEndpoint")
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("DBClusterEndpointIdentifier", id)
.formParam("EndpointType", type);
}
@Test
@Order(1)
void createsACustomEndpointOnAClusterWithAWriterAndAReader() {
query("CreateDBCluster")
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("Engine", "aurora-postgresql")
.formParam("EngineVersion", "16.3")
.formParam("MasterUsername", "admin")
.formParam("MasterUserPassword", "password123")
.when().post("/").then().statusCode(200);
for (String instance : new String[] {WRITER, READER}) {
query("CreateDBInstance")
.formParam("DBInstanceIdentifier", instance)
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("Engine", "aurora-postgresql")
.formParam("DBInstanceClass", "db.r6g.large")
.when().post("/").then().statusCode(200);
}
// The CLI sends the type in lower case, and the identifier is stored lower case.
createEndpoint("Reports-EP", "reader")
.formParam("StaticMembers.member.1", READER)
.formParam("Tags.Tag.1.Key", "team")
.formParam("Tags.Tag.1.Value", "analytics")
.when().post("/").then()
.statusCode(200)
.body(containsString("<CreateDBClusterEndpointResult>"))
.body(containsString("<DBClusterEndpointIdentifier>reports-ep</DBClusterEndpointIdentifier>"))
.body(containsString("<DBClusterIdentifier>" + CLUSTER + "</DBClusterIdentifier>"))
.body(containsString("<DBClusterEndpointResourceIdentifier>cluster-endpoint-"))
.body(containsString("<Endpoint>"))
.body(containsString("<Status>available</Status>"))
.body(containsString("<EndpointType>CUSTOM</EndpointType>"))
.body(containsString("<CustomEndpointType>READER</CustomEndpointType>"))
.body(containsString("<StaticMembers><member>" + READER + "</member></StaticMembers>"))
.body(containsString("<ExcludedMembers></ExcludedMembers>"))
.body(containsString(":cluster-endpoint:reports-ep</DBClusterEndpointArn>"));
}
@Test
@Order(2)
void describeListsTheBuiltInEndpointsWithTheCustomOneAndFilters() {
query("DescribeDBClusterEndpoints").formParam("DBClusterIdentifier", CLUSTER)
.when().post("/").then()
.statusCode(200)
.body(DESCRIBE_LIST + ".size()", equalTo(3))
.body(DESCRIBE_LIST + "[0].EndpointType", equalTo("WRITER"))
.body(DESCRIBE_LIST + "[1].EndpointType", equalTo("READER"))
.body(DESCRIBE_LIST + "[2].DBClusterEndpointIdentifier", equalTo("reports-ep"));
query("DescribeDBClusterEndpoints")
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("Filters.Filter.1.Name", "db-cluster-endpoint-type")
.formParam("Filters.Filter.1.Values.Value.1", "custom")
.when().post("/").then().statusCode(200)
.body(DESCRIBE_LIST + ".DBClusterEndpointIdentifier", equalTo("reports-ep"));
query("DescribeDBClusterEndpoints")
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("Filters.Filter.1.Name", "db-cluster-endpoint-custom-type")
.formParam("Filters.Filter.1.Values.Value.1", "any")
.when().post("/").then().statusCode(200)
.body(not(containsString("<DBClusterEndpointList>")));
query("DescribeDBClusterEndpoints").formParam("DBClusterEndpointIdentifier", "REPORTS-EP")
.when().post("/").then().statusCode(200)
.body(DESCRIBE_LIST + ".DBClusterEndpointIdentifier", equalTo("reports-ep"));
query("DescribeDBClusterEndpoints").formParam("DBClusterIdentifier", "cep-missing")
.when().post("/").then().statusCode(404)
.body(containsString("<Code>DBClusterNotFoundFault</Code>"));
}
@Test
@Order(3)
void createRefusesWhatTheApiAndUserGuideRuleOut() {
createEndpoint("reports-ep", "READER")
.when().post("/").then().statusCode(400)
.body(containsString("<Code>DBClusterEndpointAlreadyExistsFault</Code>"));
createEndpoint("writer-in-reader", "READER")
.formParam("StaticMembers.member.1", WRITER)
.when().post("/").then().statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
createEndpoint("both-lists", "ANY")
.formParam("StaticMembers.member.1", READER)
.formParam("ExcludedMembers.member.1", WRITER)
.when().post("/").then().statusCode(400)
.body(containsString("<Code>InvalidParameterCombination</Code>"));
createEndpoint("stranger", "ANY")
.formParam("StaticMembers.member.1", "cep-not-a-member")
.when().post("/").then().statusCode(404)
.body(containsString("<Code>DBInstanceNotFound</Code>"));
createEndpoint("writer-type", "WRITER")
.when().post("/").then().statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
createEndpoint("-bad-name", "ANY")
.when().post("/").then().statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
query("CreateDBClusterEndpoint")
.formParam("DBClusterIdentifier", "cep-missing")
.formParam("DBClusterEndpointIdentifier", "orphan")
.formParam("EndpointType", "ANY")
.when().post("/").then().statusCode(404)
.body(containsString("<Code>DBClusterNotFoundFault</Code>"));
}
@Test
@Order(4)
void aClusterHoldsAtMostFiveCustomEndpoints() {
for (int i = 2; i <= 5; i++) {
createEndpoint("extra-" + i, "ANY").when().post("/").then().statusCode(200);
}
createEndpoint("extra-6", "ANY")
.when().post("/").then().statusCode(403)
.body(containsString("<Code>DBClusterEndpointQuotaExceededFault</Code>"));
for (int i = 2; i <= 5; i++) {
query("DeleteDBClusterEndpoint").formParam("DBClusterEndpointIdentifier", "extra-" + i)
.when().post("/").then().statusCode(200);
}
}
@Test
@Order(5)
void modifySwitchesTheTypeAndListAndTagsFollowTheArn() {
query("ModifyDBClusterEndpoint")
.formParam("DBClusterEndpointIdentifier", "reports-ep")
.formParam("EndpointType", "ANY")
.formParam("ExcludedMembers.member.1", READER)
.when().post("/").then()
.statusCode(200)
.body(containsString("<ModifyDBClusterEndpointResult>"))
.body(containsString("<CustomEndpointType>ANY</CustomEndpointType>"))
.body(containsString("<StaticMembers></StaticMembers>"))
.body(containsString("<ExcludedMembers><member>" + READER + "</member></ExcludedMembers>"));
query("ModifyDBClusterEndpoint")
.formParam("DBClusterEndpointIdentifier", "cep-missing-ep")
.formParam("EndpointType", "ANY")
.when().post("/").then().statusCode(400)
.body(containsString("<Code>DBClusterEndpointNotFoundFault</Code>"));
query("ListTagsForResource")
.formParam("ResourceName", "arn:aws:rds:us-east-1:000000000000:cluster-endpoint:reports-ep")
.when().post("/").then().statusCode(200)
.body(containsString("<Value>analytics</Value>"));
}
@Test
@Order(6)
void aDeletedInstanceLeavesTheListsAndDeleteRemovesTheEndpoint() {
query("DeleteDBInstance").formParam("DBInstanceIdentifier", READER)
.when().post("/").then().statusCode(200);
query("DescribeDBClusterEndpoints").formParam("DBClusterEndpointIdentifier", "reports-ep")
.when().post("/").then().statusCode(200)
.body(containsString("<ExcludedMembers></ExcludedMembers>"));
query("DeleteDBClusterEndpoint").formParam("DBClusterEndpointIdentifier", "reports-ep")
.when().post("/").then()
.statusCode(200)
.body(containsString("<DeleteDBClusterEndpointResult>"))
.body(containsString("<Status>deleting</Status>"));
query("DescribeDBClusterEndpoints").formParam("DBClusterEndpointIdentifier", "reports-ep")
.when().post("/").then().statusCode(200)
.body(not(containsString("<DBClusterEndpointList>")));
query("DeleteDBClusterEndpoint").formParam("DBClusterEndpointIdentifier", "reports-ep")
.when().post("/").then().statusCode(400)
.body(containsString("<Code>DBClusterEndpointNotFoundFault</Code>"));
}
@Test
@Order(7)
void deletingTheClusterDeletesItsCustomEndpoints() {
createEndpoint("last-ep", "ANY").when().post("/").then().statusCode(200);
query("DeleteDBInstance").formParam("DBInstanceIdentifier", WRITER)
.when().post("/").then().statusCode(200);
query("DeleteDBCluster")
.formParam("DBClusterIdentifier", CLUSTER)
.formParam("SkipFinalSnapshot", "true")
.when().post("/").then().statusCode(200);
query("DescribeDBClusterEndpoints").formParam("DBClusterEndpointIdentifier", "last-ep")
.when().post("/").then().statusCode(200)
.body(not(containsString("<DBClusterEndpointList>")));
}
}
@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.ec2.model.Vpc;
import io.github.hectorvent.floci.services.ec2.model.VpcIpv6CidrBlockAssociation;
import io.github.hectorvent.floci.services.rds.model.DatabaseEngine;
import io.github.hectorvent.floci.services.rds.model.DbCluster;
import io.github.hectorvent.floci.services.rds.model.DbClusterEndpoint;
import io.github.hectorvent.floci.services.rds.model.DbClusterSnapshot;
import io.github.hectorvent.floci.services.rds.model.DbClusterParameterGroup;
import io.github.hectorvent.floci.services.rds.container.AutoPauseListener;
@@ -8391,6 +8392,42 @@ class RdsServiceTest {
assertEquals("GlobalClusterAlreadyExistsFault", taken.getErrorCode());
}
@Test
void customClusterEndpointFollowsTheClusterNamesWriterAndAddress() {
rdsService.createDbCluster("Mixed-Cluster", "aurora-postgresql", "16.3", "admin", "password", "appdb", false, null);
for (String member : List.of("Writer-1", "Reader-1")) {
rdsService.createDbInstance(member, "aurora-postgresql", "16.3",
"admin", "password", "appdb", "db.r5.large",
20, false, null, null, "Mixed-Cluster", null, false, false, null,
Map.of(), List.of(), null, null, true, DbInstanceSettings.defaults());
}
// The cluster is found under its own spelling, and a member named in other capitals is
// stored as the cluster spells it.
DbClusterEndpoint created = rdsService.createDbClusterEndpoint("us-east-1", "Mixed-Cluster", "reports",
"READER", List.of("READER-1"), null, Map.of());
assertEquals(List.of("Reader-1"), created.getStaticMembers());
// After a failover the new writer drops out of the READER endpoint, as Aurora adjusts it.
rdsService.failoverDbCluster("Mixed-Cluster", "Reader-1", "us-east-1");
DbClusterEndpoint afterFailover = rdsService.describeDbClusterEndpoints("us-east-1", null, "reports",
Map.of(), null, null).endpoints().getFirst();
assertEquals(List.of(), afterFailover.getStaticMembers());
// A modify that leaves the lists alone still succeeds, and a failback makes the member a
// reader of the endpoint again, since failover never removed it from the stored list.
DbClusterEndpoint retyped = rdsService.modifyDbClusterEndpoint("us-east-1", "reports", "READER", null, null);
assertEquals(List.of(), retyped.getStaticMembers());
rdsService.failoverDbCluster("Mixed-Cluster", "Writer-1", "us-east-1");
assertEquals(List.of("Reader-1"), rdsService.describeDbClusterEndpoints("us-east-1", null, "reports",
Map.of(), null, null).endpoints().getFirst().getStaticMembers());
// The address follows the cluster's endpoint rather than the one stored at create.
rdsService.getDbCluster("Mixed-Cluster").setEndpoint(new DbEndpoint("moved.example", 7099));
DbClusterEndpoint moved = rdsService.describeDbClusterEndpoints("us-east-1", null, "reports",
Map.of(), null, null).endpoints().getFirst();
assertEquals("moved.example", moved.getEndpoint());
}
@Test
void failoverDbClusterMovesTheWriterRole() {
rdsService.createDbCluster("aurora", "aurora-postgresql", "16.3", "admin", "password", "appdb", false, null);