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

@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
import io.github.hectorvent.floci.services.redshiftserverless.model.EndpointAccess;
import io.github.hectorvent.floci.services.redshiftserverless.model.ResourcePolicy;
import jakarta.enterprise.context.ApplicationScoped;
@@ -27,16 +28,19 @@ public class RedshiftServerlessAdminJsonHandler {
private static final List<String> TRACK_NAMES = RedshiftServerlessService.TRACK_NAMES;
private final ObjectMapper objectMapper;
private final RedshiftServerlessCustomDomainService customDomains;
private final RedshiftServerlessEndpointAccessService endpointAccess;
private final RedshiftServerlessResourcePolicyService resourcePolicies;
@Inject
public RedshiftServerlessAdminJsonHandler(ObjectMapper objectMapper,
RedshiftServerlessResourcePolicyService resourcePolicies,
RedshiftServerlessEndpointAccessService endpointAccess) {
RedshiftServerlessEndpointAccessService endpointAccess,
RedshiftServerlessCustomDomainService customDomains) {
this.objectMapper = objectMapper;
this.resourcePolicies = resourcePolicies;
this.endpointAccess = endpointAccess;
this.customDomains = customDomains;
}
Supplier<Response> operation(String action, JsonNode request, String region) {
@@ -48,7 +52,7 @@ public class RedshiftServerlessAdminJsonHandler {
ServerlessSupport.text(request, "resourceArn"), region));
case "DeleteResourcePolicy" -> () -> {
resourcePolicies.deleteResourcePolicy(ServerlessSupport.text(request, "resourceArn"), region);
return Response.ok(objectMapper.createObjectNode()).build();
return emptyResponse();
};
case "GetTrack" -> () -> getTrack(ServerlessSupport.text(request, "trackName"));
case "ListTracks" -> () -> listTracks(request);
@@ -71,6 +75,25 @@ public class RedshiftServerlessAdminJsonHandler {
ServerlessSupport.stringList(request, "vpcSecurityGroupIds"), region));
case "DeleteEndpointAccess" -> () -> endpointResponse(endpointAccess.deleteEndpointAccess(
ServerlessSupport.text(request, "endpointName"), region));
case "CreateCustomDomainAssociation" -> () -> customDomainResponse(
customDomains.createCustomDomainAssociation(
ServerlessSupport.text(request, "workgroupName"),
ServerlessSupport.text(request, "customDomainName"),
ServerlessSupport.text(request, "customDomainCertificateArn"), region));
case "GetCustomDomainAssociation" -> () -> customDomainResponse(
customDomains.getCustomDomainAssociation(ServerlessSupport.text(request, "workgroupName"),
ServerlessSupport.text(request, "customDomainName"), region));
case "ListCustomDomainAssociations" -> () -> listCustomDomains(request, region);
case "UpdateCustomDomainAssociation" -> () -> customDomainResponse(
customDomains.updateCustomDomainAssociation(
ServerlessSupport.text(request, "workgroupName"),
ServerlessSupport.text(request, "customDomainName"),
ServerlessSupport.text(request, "customDomainCertificateArn"), region));
case "DeleteCustomDomainAssociation" -> () -> {
customDomains.deleteCustomDomainAssociation(ServerlessSupport.text(request, "workgroupName"),
ServerlessSupport.text(request, "customDomainName"), region);
return emptyResponse();
};
default -> null;
};
}
@@ -154,6 +177,31 @@ public class RedshiftServerlessAdminJsonHandler {
return node;
}
// ── Custom domain association ──────────────────────────────────────────
private Response listCustomDomains(JsonNode request, String region) {
PaginatedResult<CustomDomainAssociation> page = customDomains.listCustomDomainAssociations(
ServerlessSupport.text(request, "customDomainName"),
ServerlessSupport.text(request, "customDomainCertificateArn"), region,
ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode items = response.putArray("associations");
page.items().forEach(association -> items.add(customDomainNode(association)));
putNextToken(response, page);
return Response.ok(response).build();
}
private Response customDomainResponse(CustomDomainAssociation association) {
return Response.ok(customDomainNode(association)).build();
}
private ObjectNode customDomainNode(CustomDomainAssociation association) {
ObjectNode node = objectMapper.createObjectNode();
ServerlessSupport.populateCustomDomain(node, association);
node.put("workgroupName", association.getWorkgroupName());
return node;
}
// ── Tracks, managed workgroups and reservations ────────────────────────
/**
@@ -201,6 +249,10 @@ public class RedshiftServerlessAdminJsonHandler {
// ── Shared ─────────────────────────────────────────────────────────────
private Response emptyResponse() {
return Response.ok(objectMapper.createObjectNode()).build();
}
private static void putNextToken(ObjectNode response, PaginatedResult<?> page) {
if (page.nextToken() != null) {
response.put("nextToken", page.nextToken());
@@ -0,0 +1,205 @@
package io.github.hectorvent.floci.services.redshiftserverless;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.Resettable;
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.redshiftserverless.model.CustomDomainAssociation;
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.time.Instant;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* Redshift Serverless custom domain associations. An association is recorded and echoed: Floci
* serves no traffic on the domain, but reads the ACM certificate to report expiry when available.
*
* <p>An association belongs to a workgroup but lives in its own store, so deleting the workgroup
* needs no hook here. Each read checks that the workgroup is still there and drops the association
* otherwise.
*/
@ApplicationScoped
public class RedshiftServerlessCustomDomainService implements Resettable {
private static final int PAGE_SIZE = 100;
private final AccountAwareStorageBackend<CustomDomainAssociation> associations;
private final RedshiftServerlessService serverless;
private final AcmService acmService;
@Inject
public RedshiftServerlessCustomDomainService(StorageFactory storageFactory,
RedshiftServerlessService serverless,
AcmService acmService) {
this.associations = storageFactory.create("redshiftserverless",
"redshiftserverless-customdomains.json",
new TypeReference<Map<String, CustomDomainAssociation>>() {});
this.serverless = serverless;
this.acmService = acmService;
}
public synchronized CustomDomainAssociation createCustomDomainAssociation(
String workgroupName, String customDomainName, String certificateArn, String region) {
Workgroup workgroup = serverless.findWorkgroup(workgroupName, region)
.orElseThrow(() -> ServerlessSupport.notFound("The workgroup " + workgroupName + " was not found."));
CustomDomainAssociation forWorkgroup = findForWorkgroup(workgroupName, region).orElse(null);
if (forWorkgroup != null) {
if (customDomainName.equals(forWorkgroup.getCustomDomainName())) {
throw ServerlessSupport.conflict("The custom domain " + customDomainName
+ " is already associated with the workgroup " + workgroupName + ".");
}
throw ServerlessSupport.conflict("The workgroup " + workgroupName
+ " already has a custom domain associated with it.");
}
CustomDomainAssociation existing = findByDomain(customDomainName, region);
if (existing != null) {
throw ServerlessSupport.conflict("The custom domain " + customDomainName
+ " is already associated with the workgroup " + existing.getWorkgroupName() + ".");
}
CustomDomainAssociation association = new CustomDomainAssociation();
association.setWorkgroupName(workgroupName);
association.setOwnerId(workgroup.getWorkgroupId());
association.setCustomDomainName(customDomainName);
association.setCustomDomainCertificateArn(certificateArn);
associations.put(storageKey(region, workgroupName, customDomainName), association);
return withCertificateExpiry(association, region);
}
public synchronized CustomDomainAssociation getCustomDomainAssociation(
String workgroupName, String customDomainName, String region) {
return withCertificateExpiry(require(workgroupName, customDomainName, region), region);
}
public synchronized Optional<CustomDomainAssociation> findForWorkgroup(String workgroupName, String region) {
return live(region).stream()
.filter(association -> association.getWorkgroupName().equals(workgroupName))
.findFirst()
.map(association -> withCertificateExpiry(association, region));
}
public synchronized PaginatedResult<CustomDomainAssociation> listCustomDomainAssociations(
String customDomainName, String certificateArn, String region, Integer maxResults, String nextToken) {
if (maxResults != null && (maxResults < 1 || maxResults > PAGE_SIZE)) {
throw ServerlessSupport.validation("maxResults must be between 1 and " + PAGE_SIZE);
}
int limit = maxResults != null ? maxResults : PAGE_SIZE;
List<CustomDomainAssociation> matching = live(region).stream()
.filter(association -> customDomainName == null
|| customDomainName.equals(association.getCustomDomainName()))
.filter(association -> certificateArn == null
|| certificateArn.equals(association.getCustomDomainCertificateArn()))
.sorted(Comparator.comparing(CustomDomainAssociation::getWorkgroupName)
.thenComparing(CustomDomainAssociation::getCustomDomainName))
.map(association -> withCertificateExpiry(association, region))
.toList();
return Pagination.paginate(matching,
association -> association.getWorkgroupName() + "|" + association.getCustomDomainName(),
limit, nextToken, "custom-domain",
token -> new AwsException("InvalidPaginationException", "Invalid nextToken.", 400));
}
/** Points the association at another certificate, the only member AWS lets an update change. */
public synchronized CustomDomainAssociation updateCustomDomainAssociation(
String workgroupName, String customDomainName, String certificateArn, String region) {
CustomDomainAssociation updated = new CustomDomainAssociation(require(workgroupName, customDomainName, region));
updated.setCustomDomainCertificateArn(certificateArn);
updated.setCustomDomainCertificateExpiryTime(null);
associations.put(storageKey(region, workgroupName, customDomainName), updated);
return withCertificateExpiry(updated, region);
}
public synchronized void deleteCustomDomainAssociation(String workgroupName, String customDomainName,
String region) {
require(workgroupName, customDomainName, region);
associations.delete(storageKey(region, workgroupName, customDomainName));
}
@Override
public void clear() {
associations.clear();
}
private CustomDomainAssociation require(String workgroupName, String customDomainName, String region) {
CustomDomainAssociation association = find(workgroupName, customDomainName, region);
if (association == null) {
throw ServerlessSupport.notFound("The custom domain " + customDomainName
+ " is not associated with the workgroup " + workgroupName + ".");
}
return association;
}
/** The association, or null when there is none or its workgroup is gone, in which case it is dropped. */
private CustomDomainAssociation find(String workgroupName, String customDomainName, String region) {
String key = storageKey(region, workgroupName, customDomainName);
CustomDomainAssociation association = associations.get(key).orElse(null);
if (association != null && !isOnSameWorkgroup(association, region)) {
associations.delete(key);
return null;
}
return association;
}
/** The region's associations whose workgroup is still there; any other is deleted as it is found. */
private List<CustomDomainAssociation> live(String region) {
return ServerlessSupport.live(associations, region,
association -> isOnSameWorkgroup(association, region),
association -> storageKey(region, association.getWorkgroupName(), association.getCustomDomainName()));
}
/** A workgroup recreated under the same name has a new id, so it never inherits its predecessor's domains. */
private boolean isOnSameWorkgroup(CustomDomainAssociation association, String region) {
return serverless.findWorkgroup(association.getWorkgroupName(), region)
.map(workgroup -> Objects.equals(workgroup.getWorkgroupId(), association.getOwnerId()))
.orElse(false);
}
/** The live association claiming this custom domain in the region, or null when none does. */
private CustomDomainAssociation findByDomain(String customDomainName, String region) {
return live(region).stream()
.filter(association -> customDomainName.equals(association.getCustomDomainName()))
.findFirst()
.orElse(null);
}
private Instant certificateExpiryTime(String certificateArn, String region) {
if (certificateArn == null || certificateArn.isBlank()) {
return null;
}
String certRegion = region;
if (AwsArnUtils.isArn(certificateArn)) {
String arnRegion = AwsArnUtils.parse(certificateArn).region();
if (arnRegion != null && !arnRegion.isBlank()) {
certRegion = arnRegion;
}
}
try {
Certificate certificate = acmService.describeCertificate(certificateArn, certRegion);
return certificate != null ? certificate.getNotAfter() : null;
} catch (AwsException ignored) {
// A missing certificate in ACM leaves the expiry time unknown.
return null;
}
}
private CustomDomainAssociation withCertificateExpiry(CustomDomainAssociation association, String region) {
CustomDomainAssociation copy = new CustomDomainAssociation(association);
copy.setCustomDomainCertificateExpiryTime(certificateExpiryTime(copy.getCustomDomainCertificateArn(), region));
return copy;
}
private static String storageKey(String region, String workgroupName, String customDomainName) {
return region + "::" + workgroupName + "::" + customDomainName;
}
}
@@ -44,17 +44,20 @@ public class RedshiftServerlessJsonHandler {
private final RedshiftIamDbUserResolver iamDbUserResolver;
private final RedshiftServerlessUsageLimitService usageLimits;
private final RedshiftServerlessAdminJsonHandler admin;
private final RedshiftServerlessCustomDomainService customDomains;
@Inject
public RedshiftServerlessJsonHandler(RedshiftServerlessService service, ObjectMapper objectMapper,
RedshiftIamDbUserResolver iamDbUserResolver,
RedshiftServerlessUsageLimitService usageLimits,
RedshiftServerlessAdminJsonHandler admin) {
RedshiftServerlessAdminJsonHandler admin,
RedshiftServerlessCustomDomainService customDomains) {
this.service = service;
this.objectMapper = objectMapper;
this.iamDbUserResolver = iamDbUserResolver;
this.usageLimits = usageLimits;
this.admin = admin;
this.customDomains = customDomains;
}
public Response handle(String action, JsonNode request, String region) {
@@ -163,11 +166,11 @@ public class RedshiftServerlessJsonHandler {
parseWorkgroupSettings(request),
parseTagList(request.path("tags"), "tags"),
region);
return workgroupResponse(workgroup);
return workgroupResponse(workgroup, region);
}
private Response handleGetWorkgroup(JsonNode request, String region) {
return workgroupResponse(service.getWorkgroup(ServerlessSupport.text(request, "workgroupName"), region));
return workgroupResponse(service.getWorkgroup(ServerlessSupport.text(request, "workgroupName"), region), region);
}
private Response handleListWorkgroups(JsonNode request, String region) {
@@ -175,7 +178,7 @@ public class RedshiftServerlessJsonHandler {
region, ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"));
ObjectNode response = objectMapper.createObjectNode();
ArrayNode items = response.putArray("workgroups");
page.items().forEach(workgroup -> items.add(workgroupNode(workgroup)));
page.items().forEach(workgroup -> items.add(workgroupNode(workgroup, region)));
if (page.nextToken() != null) {
response.put("nextToken", page.nextToken());
}
@@ -184,11 +187,11 @@ public class RedshiftServerlessJsonHandler {
private Response handleUpdateWorkgroup(JsonNode request, String region) {
return workgroupResponse(service.updateWorkgroup(
ServerlessSupport.text(request, "workgroupName"), parseWorkgroupSettings(request), region));
ServerlessSupport.text(request, "workgroupName"), parseWorkgroupSettings(request), region), region);
}
private Response handleDeleteWorkgroup(JsonNode request, String region) {
return workgroupResponse(service.deleteWorkgroup(ServerlessSupport.text(request, "workgroupName"), region));
return workgroupResponse(service.deleteWorkgroup(ServerlessSupport.text(request, "workgroupName"), region), region);
}
/**
@@ -420,24 +423,26 @@ public class RedshiftServerlessJsonHandler {
return node;
}
private Response workgroupResponse(Workgroup workgroup) {
private Response workgroupResponse(Workgroup workgroup, String region) {
ObjectNode response = objectMapper.createObjectNode();
response.set("workgroup", workgroupNode(workgroup));
response.set("workgroup", workgroupNode(workgroup, region));
return Response.ok(response).build();
}
/**
* Members the emulator does not model ({@code workgroupVersion}, {@code patchVersion},
* {@code crossAccountVpcs}, the custom domain members and {@code endpoint.vpcEndpoints}) are
* {@code crossAccountVpcs} and {@code endpoint.vpcEndpoints}) are
* omitted rather than invented; all of them are optional in the API model.
*/
private ObjectNode workgroupNode(Workgroup workgroup) {
private ObjectNode workgroupNode(Workgroup workgroup, String region) {
ObjectNode node = objectMapper.createObjectNode();
node.put("workgroupName", workgroup.getWorkgroupName());
node.put("workgroupId", workgroup.getWorkgroupId());
node.put("workgroupArn", workgroup.getWorkgroupArn());
node.put("namespaceName", workgroup.getNamespaceName());
node.put("status", workgroup.getStatus());
customDomains.findForWorkgroup(workgroup.getWorkgroupName(), region)
.ifPresent(association -> ServerlessSupport.populateCustomDomain(node, association));
if (workgroup.getBaseCapacity() != null) {
node.put("baseCapacity", workgroup.getBaseCapacity());
}
@@ -1,8 +1,10 @@
package io.github.hectorvent.floci.services.redshiftserverless;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
import java.time.Instant;
import java.time.ZoneOffset;
@@ -26,6 +28,15 @@ final class ServerlessSupport {
private ServerlessSupport() {
}
static void populateCustomDomain(ObjectNode node, CustomDomainAssociation association) {
node.put("customDomainCertificateArn", association.getCustomDomainCertificateArn());
if (association.getCustomDomainCertificateExpiryTime() != null) {
node.put("customDomainCertificateExpiryTime",
ISO_8601.format(association.getCustomDomainCertificateExpiryTime()));
}
node.put("customDomainName", association.getCustomDomainName());
}
static AwsException validation(String message) {
return new AwsException("ValidationException", message, 400);
}
@@ -0,0 +1,72 @@
package io.github.hectorvent.floci.services.redshiftserverless.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
/**
* A custom domain bound to a Redshift Serverless workgroup. The certificate expiry time is read from
* ACM when the certificate exists in the emulator.
*/
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomDomainAssociation {
private String workgroupName;
private String customDomainName;
private String customDomainCertificateArn;
private Instant customDomainCertificateExpiryTime;
private String ownerId;
public CustomDomainAssociation() {
}
public CustomDomainAssociation(CustomDomainAssociation other) {
this.ownerId = other.ownerId;
this.workgroupName = other.workgroupName;
this.customDomainName = other.customDomainName;
this.customDomainCertificateArn = other.customDomainCertificateArn;
this.customDomainCertificateExpiryTime = other.customDomainCertificateExpiryTime;
}
public String getWorkgroupName() {
return workgroupName;
}
public void setWorkgroupName(String workgroupName) {
this.workgroupName = workgroupName;
}
public String getCustomDomainName() {
return customDomainName;
}
public void setCustomDomainName(String customDomainName) {
this.customDomainName = customDomainName;
}
public String getCustomDomainCertificateArn() {
return customDomainCertificateArn;
}
public void setCustomDomainCertificateArn(String customDomainCertificateArn) {
this.customDomainCertificateArn = customDomainCertificateArn;
}
public Instant getCustomDomainCertificateExpiryTime() {
return customDomainCertificateExpiryTime;
}
public void setCustomDomainCertificateExpiryTime(Instant customDomainCertificateExpiryTime) {
this.customDomainCertificateExpiryTime = customDomainCertificateExpiryTime;
}
public String getOwnerId() {
return ownerId;
}
public void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
}