feat(redshift-serverless): add custom domain association actions (#5766)

* feat(redshift-serverless): add custom domain association actions

Add CreateCustomDomainAssociation, GetCustomDomainAssociation,
ListCustomDomainAssociations, UpdateCustomDomainAssociation and
DeleteCustomDomainAssociation. An association is recorded and echoed; Floci
serves no traffic on the domain and reads no ACM certificate. It is tied to the
workgroup by the workgroup's generated id, so a workgroup recreated under the
same name does not inherit it.

The domain name and certificate ARN patterns, lengths and the required members
come from the AWS model through RedshiftServerlessRequestShapes, so the service
carries no validation of its own.

* fix(redshift-serverless): address review findings for custom domains

- Expose custom domain name and certificate ARN in workgroup responses.
- Ensure custom domain names are unique across workgroups in a region.
- Remove ambiguous Pagination.paginate overload in favor of paginateNamespaced.
- Add domain name and certificate ARN validation patterns and length checks.
- Enforce validation for required parameters in custom domain operations.

* fix(redshift-serverless): enforce single custom domain per workgroup and populate certificate expiry

* fix(redshift-serverless): read certificate expiry dynamically and share custom domain serialization
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-16 21:18:45 -04:00
1 parent 92be67d2df
commit 7cab804d22
11 files changed
+626 -19

No files matched your search

@@ -7,6 +7,8 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.acm.AcmService;
import io.github.hectorvent.floci.services.acm.model.Certificate;
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
import jakarta.ws.rs.core.Response;
@@ -14,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,17 +36,22 @@ import static org.mockito.Mockito.when;
class RedshiftServerlessAdministrationHandlerTest {
private static final String REGION = "us-east-1";
private static final String ACCOUNT_ID = "123456789012";
private static final String CERTIFICATE_ARN =
"arn:aws:acm:us-east-1:123456789012:certificate/11111111-2222-3333-4444-555555555555";
private static final String REPLACEMENT_CERTIFICATE_ARN =
"arn:aws:acm:us-east-1:123456789012:certificate/99999999-2222-3333-4444-555555555555";
private final ObjectMapper mapper = new ObjectMapper();
private RedshiftServerlessJsonHandler handler;
private RedshiftServerlessService serverlessService;
private Certificate testCert;
@BeforeEach
@SuppressWarnings({"unchecked", "rawtypes"})
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
for (String file : List.of("namespaces", "workgroups", "snapshots", "usagelimits", "resourcepolicies",
"endpointaccess")) {
"endpointaccess", "customdomains")) {
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
@@ -65,11 +73,26 @@ class RedshiftServerlessAdministrationHandlerTest {
when(config.storage().persistentPath()).thenReturn(System.getProperty("java.io.tmpdir"));
serverlessService =
new RedshiftServerlessService(storageFactory, regionResolver, endpoints, runtime, config);
AcmService acmService = mock(AcmService.class);
testCert = new Certificate();
testCert.setArn(CERTIFICATE_ARN);
testCert.setNotAfter(Instant.parse("2028-06-15T12:00:00Z"));
when(acmService.describeCertificate(eq(CERTIFICATE_ARN), any())).thenReturn(testCert);
Certificate replacementCert = new Certificate();
replacementCert.setArn(REPLACEMENT_CERTIFICATE_ARN);
replacementCert.setNotAfter(Instant.parse("2029-01-01T00:00:00Z"));
when(acmService.describeCertificate(eq(REPLACEMENT_CERTIFICATE_ARN), any())).thenReturn(replacementCert);
RedshiftServerlessCustomDomainService customDomains =
new RedshiftServerlessCustomDomainService(storageFactory, serverlessService, acmService);
handler = new RedshiftServerlessJsonHandler(serverlessService, mapper, mock(RedshiftIamDbUserResolver.class),
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, serverlessService),
new RedshiftServerlessAdminJsonHandler(mapper,
new RedshiftServerlessResourcePolicyService(storageFactory, serverlessService, mapper),
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService)));
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService),
customDomains),
customDomains);
}
@Test
@@ -265,6 +288,173 @@ class RedshiftServerlessAdministrationHandlerTest {
assertFalse(secondPage.has("nextToken"));
}
@Test
void customDomainAssociationIsKeyedByWorkgroupAndDomain() {
workgroup("domain-ns", "domain-wg");
JsonNode wgBefore = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
assertFalse(wgBefore.has("customDomainName"));
assertFalse(wgBefore.has("customDomainCertificateArn"));
assertFalse(wgBefore.has("customDomainCertificateExpiryTime"));
String request = "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}";
JsonNode created = ok("CreateCustomDomainAssociation", request);
assertEquals("db.example.com", created.get("customDomainName").textValue());
assertEquals("domain-wg", created.get("workgroupName").textValue());
assertEquals(CERTIFICATE_ARN, created.get("customDomainCertificateArn").textValue());
assertEquals("2028-06-15T12:00:00.000Z", created.get("customDomainCertificateExpiryTime").textValue());
JsonNode wgWithDomain = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
assertEquals("db.example.com", wgWithDomain.get("customDomainName").textValue());
assertEquals(CERTIFICATE_ARN, wgWithDomain.get("customDomainCertificateArn").textValue());
assertEquals("2028-06-15T12:00:00.000Z", wgWithDomain.get("customDomainCertificateExpiryTime").textValue());
JsonNode listWg = ok("ListWorkgroups", "{}").get("workgroups");
boolean foundInList = false;
for (JsonNode wg : listWg) {
if ("domain-wg".equals(wg.get("workgroupName").textValue())) {
assertEquals("db.example.com", wg.get("customDomainName").textValue());
assertEquals(CERTIFICATE_ARN, wg.get("customDomainCertificateArn").textValue());
assertEquals("2028-06-15T12:00:00.000Z", wg.get("customDomainCertificateExpiryTime").textValue());
foundInList = true;
}
}
assertTrue(foundInList);
testCert.setNotAfter(Instant.parse("2030-01-01T00:00:00Z"));
JsonNode renewed = ok("GetCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}");
assertEquals("2030-01-01T00:00:00.000Z", renewed.get("customDomainCertificateExpiryTime").textValue());
testCert.setNotAfter(Instant.parse("2028-06-15T12:00:00Z"));
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation", request));
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"other.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
assertTrue(errorMessage("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"other.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}")
.contains("already has a custom domain"));
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"-bad\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"third.example.com\","
+ "\"customDomainCertificateArn\":\"not-an-arn\"}"));
assertEquals("ResourceNotFoundException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"nope\",\"customDomainName\":\"x.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
String replacement = REPLACEMENT_CERTIFICATE_ARN;
JsonNode updated = ok("UpdateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\","
+ "\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"" + replacement + "\"}");
assertEquals(replacement, updated.get("customDomainCertificateArn").textValue());
assertEquals("2029-01-01T00:00:00.000Z", updated.get("customDomainCertificateExpiryTime").textValue());
JsonNode got = ok("GetCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}");
assertEquals(replacement, got.get("customDomainCertificateArn").textValue());
assertEquals("2029-01-01T00:00:00.000Z", got.get("customDomainCertificateExpiryTime").textValue());
JsonNode wgUpdated = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
assertEquals("db.example.com", wgUpdated.get("customDomainName").textValue());
assertEquals(replacement, wgUpdated.get("customDomainCertificateArn").textValue());
assertEquals("2029-01-01T00:00:00.000Z", wgUpdated.get("customDomainCertificateExpiryTime").textValue());
JsonNode associationsList = ok("ListCustomDomainAssociations", "{\"customDomainName\":\"db.example.com\"}")
.get("associations");
assertEquals(1, associationsList.size());
assertEquals("2029-01-01T00:00:00.000Z", associationsList.get(0).get("customDomainCertificateExpiryTime").textValue());
assertEquals(0, ok("ListCustomDomainAssociations", "{\"customDomainName\":\"x.example.com\"}")
.get("associations").size());
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("ListCustomDomainAssociations", "{\"maxResults\":0}"));
assertEquals("ValidationException", errorType("ListCustomDomainAssociations", "{\"maxResults\":101}"));
assertEquals("InvalidPaginationException", errorType("ListCustomDomainAssociations", "{\"nextToken\":\"bad-token\"}"));
JsonNode trackToken = ok("ListTracks", "{\"maxResults\":1}");
assertEquals("InvalidPaginationException", errorType("ListCustomDomainAssociations",
"{\"nextToken\":\"" + trackToken.get("nextToken").textValue() + "\"}"));
assertEquals(0, ok("DeleteCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}").size());
assertEquals("ResourceNotFoundException", errorType("GetCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}"));
JsonNode wgAfterDelete = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
assertFalse(wgAfterDelete.has("customDomainName"));
assertFalse(wgAfterDelete.has("customDomainCertificateArn"));
assertFalse(wgAfterDelete.has("customDomainCertificateExpiryTime"));
}
@Test
void customDomainNameCannotBeClaimedByMultipleWorkgroups() {
workgroup("domain-ns-a", "domain-wg-a");
workgroup("domain-ns-b", "domain-wg-b");
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg-a\",\"customDomainName\":\"shared.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg-b\",\"customDomainName\":\"shared.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
assertTrue(errorMessage("CreateCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg-b\",\"customDomainName\":\"shared.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}")
.contains("domain-wg-a"));
}
@Test
void customDomainOperationsValidateInputs() {
workgroup("val-ns", "val-wg");
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\"}"));
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\"}"));
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
"{\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\"}"));
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\"}"));
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
"{\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\""
+ CERTIFICATE_ARN + "\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\",\"customDomainCertificateArn\":\""
+ CERTIFICATE_ARN + "\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"-bad\",\"customDomainCertificateArn\":\""
+ CERTIFICATE_ARN + "\"}"));
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"not-an-arn\"}"));
for (String badDomain : List.of("", "-bad.com", "bad-.com", "bad_domain.com", "a".repeat(254) + ".com")) {
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"" + badDomain
+ "\",\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"), badDomain);
}
for (String badArn : List.of("", "short", "arn:aws:s3:::mybucket", "arn:aws:acm:bad")) {
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\","
+ "\"customDomainCertificateArn\":\"" + badArn + "\"}"), badArn);
}
}
@Test
void tracksAreTheTwoAwsReleaseTracks() {
JsonNode track = ok("GetTrack", "{\"trackName\":\"trailing\"}").get("track");
@@ -328,18 +518,24 @@ class RedshiftServerlessAdministrationHandlerTest {
}
@Test
void aWorkgroupRecreatedUnderTheSameNameDoesNotInheritEndpoints() {
void aWorkgroupRecreatedUnderTheSameNameDoesNotInheritEndpointsOrDomains() {
workgroup("recreate-wg-ns", "recreate-wg");
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
ok("DeleteWorkgroup", "{\"workgroupName\":\"recreate-wg\"}");
ok("CreateWorkgroup", "{\"workgroupName\":\"recreate-wg\",\"namespaceName\":\"recreate-wg-ns\"}");
assertEquals("ResourceNotFoundException", errorType("GetEndpointAccess", "{\"endpointName\":\"old-ep\"}"));
assertEquals("ResourceNotFoundException", errorType("GetCustomDomainAssociation",
"{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\"}"));
assertEquals(0, ok("ListEndpointAccess", "{\"workgroupName\":\"recreate-wg\"}").get("endpoints").size());
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\","
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
}
@Test
@@ -679,6 +679,34 @@ class RedshiftServerlessIntegrationTest {
.body("endpoint.endpointStatus", equalTo("DELETING"));
}
@Test
void customDomainAssociationRoundTripsOverTheWire() {
call("CreateNamespace", "{\"namespaceName\":\"domain-ns\",\"adminUsername\":\"admin\"}").statusCode(200);
call("CreateWorkgroup", "{\"workgroupName\":\"domain-wg\",\"namespaceName\":\"domain-ns\"}").statusCode(200);
String certificate = "arn:aws:acm:us-east-1:000000000000:certificate/11111111-2222-3333-4444-555555555555";
call("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\","
+ "\"customDomainCertificateArn\":\"" + certificate + "\"}")
.statusCode(200)
.body("customDomainName", equalTo("db.example.com"));
call("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"bad_domain\","
+ "\"customDomainCertificateArn\":\"" + certificate + "\"}")
.statusCode(400)
.body("__type", equalTo("ValidationException"));
call("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}")
.statusCode(200)
.body("workgroup.customDomainName", equalTo("db.example.com"))
.body("workgroup.customDomainCertificateArn", equalTo(certificate));
call("ListCustomDomainAssociations", "{\"customDomainName\":\"db.example.com\"}")
.statusCode(200)
.body("associations", hasSize(1));
call("DeleteCustomDomainAssociation",
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}").statusCode(200);
call("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}")
.statusCode(200)
.body("workgroup.customDomainName", nullValue());
}
private static io.restassured.response.ValidatableResponse call(String action, String body) {
return given()
.header("X-Amz-Target", TARGET_PREFIX + action)
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.acm.AcmService;
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
import io.github.hectorvent.floci.services.redshift.TempCredential;
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
@@ -86,16 +87,21 @@ class RedshiftServerlessJsonHandlerTest {
stubAdministrationStores(storageFactory);
RedshiftServerlessService service =
new RedshiftServerlessService(storageFactory, regionResolver, endpoints, runtime, config);
AcmService acmService = mock(AcmService.class);
RedshiftServerlessCustomDomainService customDomains =
new RedshiftServerlessCustomDomainService(storageFactory, service, acmService);
handler = new RedshiftServerlessJsonHandler(service, mapper, iamDbUserResolver,
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, service),
new RedshiftServerlessAdminJsonHandler(mapper,
new RedshiftServerlessResourcePolicyService(storageFactory, service, mapper),
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service)));
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service),
customDomains),
customDomains);
}
@SuppressWarnings({"unchecked", "rawtypes"})
private static void stubAdministrationStores(StorageFactory storageFactory) {
for (String file : List.of("resourcepolicies", "endpointaccess")) {
for (String file : List.of("resourcepolicies", "endpointaccess", "customdomains")) {
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));