fix(ses): match AWS tag ARN parsing and configuration set name errors (#5235)

* fix(ses): match AWS tag ARN parsing and configuration set name errors

The SES v2 tag endpoints rejected malformed ARNs with messages that were
never checked against AWS, refused ARNs whose service was not "ses", and
compared the region before checking the resource exists. Configuration
set names were rejected with an invented message on both APIs.

Probed against AWS in us-west-2:

- Every malformed ARN (missing partition, service, account or resource
  name, unknown type, ":" or "/" in the name) is BadRequestException
  "ResourceArn is not the expected format", including an unknown type,
  which was a 404.
- The partition and service are required but never compared.
- An invalid configuration-set name in the ARN is a message-less
  ValidationException after the account check.
- TagResource and UntagResource check existence before the region.
- An omitted ResourceArn on Tag/Untag is a message-less
  ValidationException. ListTagsForResource keeps a 400 where AWS
  answers 500.
- "ResourceArn=" is read raw, since @QueryParam binds an empty value
  as null.
- Configuration set names use AWS's three messages on every v1 and v2
  operation, including sends: must be specified, cannot exceed 64
  characters, and invalid characters.

* refactor(ses): share the configuration set name check and map tag domains by type

The v1 helper and the v2 CreateConfigurationSet handler now call the
service's validateName instead of repeating the empty-name check, and the
name pattern no longer restates the 64-character limit the length check
owns.

The seven taggable domain services implement SesTaggable, and SesService
keys them by ARN type in one map. That map replaces the type set and the
three dispatch switches, whose default arms could no longer be reached.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-07 14:27:36 -04:00
1 parent 74b3cecf78
commit 86371d86cb
16 files changed
+541 -103

No files matched your search

@@ -87,9 +87,7 @@ public class SesConfigurationSetController {
try {
JsonNode request = objectMapper.readTree(body);
String name = request.path("ConfigurationSetName").asText(null);
if (name == null || name.isBlank()) {
throw new AwsException("BadRequestException", "ConfigurationSetName is required.", 400);
}
SesConfigurationSetService.validateName(name);
ConfigurationSet cs = new ConfigurationSet(name);
List<Tag> parsedTags = parseTagsArray(request.path("Tags"));
if (parsedTags != null) {
@@ -48,11 +48,12 @@ import java.util.regex.Pattern;
* reasons) and the tenant delete-guard around {@link #remove}.
*/
@ApplicationScoped
public class SesConfigurationSetService {
public class SesConfigurationSetService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesConfigurationSetService.class);
private static final Pattern CONFIG_SET_NAME = Pattern.compile("^[A-Za-z0-9_-]{1,64}$");
private static final Pattern CONFIG_SET_NAME = Pattern.compile("^[A-Za-z0-9_-]+$");
private static final int MAX_CONFIG_SET_NAME_LENGTH = 64;
private static final Set<String> VDM_FEATURE_STATES = Set.of("ENABLED", "DISABLED");
private static final Pattern EVENT_DESTINATION_NAME_CHARS = Pattern.compile("^[A-Za-z0-9_-]+$");
@@ -85,7 +86,7 @@ public class SesConfigurationSetService {
throw new AwsException("InvalidParameterValue",
"ConfigurationSetName is required.", 400);
}
validateConfigurationSetName(configSet.getName());
validateName(configSet.getName());
SesTags.validate(configSet.getTags());
if (configSet.getSuppressionOptions() != null
&& configSet.getSuppressionOptions().getSuppressedReasons() != null) {
@@ -343,10 +344,12 @@ public class SesConfigurationSetService {
}
/** The ARN-dispatched tag operations, sharing the store behind {@code CreateConfigurationSet.Tags}. */
@Override
public List<Tag> listTags(String name, String region) {
return new ArrayList<>(requireForTags(name, region).getTags());
}
@Override
public void tag(String name, String region, List<Tag> newTags) {
ConfigurationSet cs = requireForTags(name, region);
cs.setTags(SesTags.merge(cs.getTags(), newTags));
@@ -354,6 +357,7 @@ public class SesConfigurationSetService {
LOG.infov("Tagged SES configuration set: {0} (region {1}, +{2} tags)", name, region, newTags.size());
}
@Override
public void untag(String name, String region, List<String> tagKeys) {
ConfigurationSet cs = requireForTags(name, region);
Set<String> toRemove = new HashSet<>(tagKeys);
@@ -384,7 +388,7 @@ public class SesConfigurationSetService {
/** For guards that must not trip the key derivation's name validation (the tenant gate). */
static boolean isValidName(String name) {
return name != null && CONFIG_SET_NAME.matcher(name).matches();
return name != null && name.length() <= MAX_CONFIG_SET_NAME_LENGTH && CONFIG_SET_NAME.matcher(name).matches();
}
// ──────────────────────── Domain-pure option setters ────────────────────────
@@ -723,20 +727,24 @@ public class SesConfigurationSetService {
return count;
}
private static void validateConfigurationSetName(String name) {
if (name == null || name.isBlank()) {
static void validateName(String name) {
if (name == null || name.isEmpty()) {
throw new AwsException("InvalidParameterValue",
"ConfigurationSetName is required.", 400);
"The configuration set name must be specified.", 400);
}
if (name.length() > MAX_CONFIG_SET_NAME_LENGTH) {
throw new AwsException("InvalidParameterValue",
"Configuration set name cannot exceed " + MAX_CONFIG_SET_NAME_LENGTH + " characters.", 400);
}
if (!CONFIG_SET_NAME.matcher(name).matches()) {
throw new AwsException("InvalidParameterValue",
"ConfigurationSetName must be 1-64 characters and may only contain "
+ "alphanumeric characters, underscores, and hyphens.", 400);
"Invalid configuration set name <" + name + ">: only alphanumeric ASCII characters, "
+ "'_', and '-' are allowed.", 400);
}
}
private static String configSetKey(String region, String name) {
validateConfigurationSetName(name);
validateName(name);
return "configSet::" + region + "::" + name;
}
}
@@ -41,7 +41,7 @@ import java.util.regex.Pattern;
* with the facade's address extractor injected as a callback.
*/
@ApplicationScoped
public class SesContactService {
public class SesContactService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesContactService.class);
@@ -110,6 +110,7 @@ public class SesContactService {
.orElseThrow(() -> contactListNotFound(name));
}
@Override
public List<Tag> listTags(String name, String region) {
ContactList list = contactListStore.get(contactListKey(region, name))
.orElseThrow(() -> tagTargetNotFound(name));
@@ -121,6 +122,7 @@ public class SesContactService {
* used by deletion, so tagging can't resurrect a concurrently deleted list or overwrite a
* concurrent mutation with a stale object.
*/
@Override
public void tag(String name, String region, List<Tag> newTags) {
String key = contactListKey(region, name);
synchronized (contactMutationLock) {
@@ -131,6 +133,7 @@ public class SesContactService {
LOG.infov("Tagged SES contact list: {0} in region {1} (+{2} tags)", name, region, newTags.size());
}
@Override
public void untag(String name, String region, List<String> tagKeys) {
String key = contactListKey(region, name);
synchronized (contactMutationLock) {
@@ -31,7 +31,7 @@ import java.util.Set;
* a domain used by the send path is not turned into a cross-service dependency.
*/
@ApplicationScoped
public class SesCvetService {
public class SesCvetService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesCvetService.class);
@@ -125,6 +125,7 @@ public class SesCvetService {
return cvetStore.get(cvetKey(region, templateName));
}
@Override
public List<Tag> listTags(String templateName, String region) {
CustomVerificationEmailTemplate template = cvetStore.get(cvetKey(region, templateName))
.orElseThrow(() -> tagTargetNotFound(templateName));
@@ -136,6 +137,7 @@ public class SesCvetService {
* lock so a concurrent update can't be overwritten with a stale object and a concurrent delete
* can't be resurrected.
*/
@Override
public void tag(String templateName, String region, List<Tag> newTags) {
String key = cvetKey(region, templateName);
synchronized (cvetMutationLock) {
@@ -148,6 +150,7 @@ public class SesCvetService {
templateName, region, newTags.size());
}
@Override
public void untag(String templateName, String region, List<String> tagKeys) {
String key = cvetKey(region, templateName);
synchronized (cvetMutationLock) {
@@ -25,7 +25,7 @@ import java.util.function.Function;
* checks pool existence through {@link #dedicatedIpPoolExists}.
*/
@ApplicationScoped
public class SesDedicatedIpService {
public class SesDedicatedIpService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesDedicatedIpService.class);
@@ -107,6 +107,7 @@ public class SesDedicatedIpService {
LOG.infov("Deleted SES dedicated IP pool: {0} in region {1}", poolName, region);
}
@Override
public List<Tag> listTags(String poolName, String region) {
DedicatedIpPool pool = dedicatedIpPoolStore.get(dedicatedIpPoolKey(region, poolName))
.orElseThrow(() -> tagTargetNotFound(poolName));
@@ -117,6 +118,7 @@ public class SesDedicatedIpService {
* Merges the incoming tags into the stored pool. The lookup and write share the mutation lock
* so tagging can't resurrect a concurrently deleted pool or lose a concurrent tag update.
*/
@Override
public void tag(String poolName, String region, List<Tag> newTags) {
String key = dedicatedIpPoolKey(region, poolName);
synchronized (poolMutationLock) {
@@ -128,6 +130,7 @@ public class SesDedicatedIpService {
LOG.infov("Tagged SES dedicated IP pool: {0} in region {1} (+{2} tags)", poolName, region, newTags.size());
}
@Override
public void untag(String poolName, String region, List<String> tagKeys) {
String key = dedicatedIpPoolKey(region, poolName);
synchronized (poolMutationLock) {
@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
* cascade around {@link #delete}.
*/
@ApplicationScoped
public class SesIdentityService {
public class SesIdentityService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesIdentityService.class);
@@ -427,10 +427,12 @@ public class SesIdentityService {
identityValue, notificationType, enabled);
}
@Override
public List<Tag> listTags(String identityValue, String region) {
return new ArrayList<>(requireForTags(identityValue, region).getTags());
}
@Override
public void tag(String identityValue, String region, List<Tag> newTags) {
Identity identity = requireForTags(identityValue, region);
identity.setTags(SesTags.merge(identity.getTags(), newTags));
@@ -438,6 +440,7 @@ public class SesIdentityService {
LOG.infov("Tagged SES identity: {0} (region {1}, +{2} tags)", identityValue, region, newTags.size());
}
@Override
public void untag(String identityValue, String region, List<String> tagKeys) {
Identity identity = requireForTags(identityValue, region);
Set<String> toRemove = new HashSet<>(tagKeys);
@@ -822,10 +822,7 @@ public class SesQueryHandler {
}
private Response handleCreateConfigurationSet(MultivaluedMap<String, String> params, String region) {
String name = getParam(params, "ConfigurationSet.Name");
if (name == null || name.isBlank()) {
throw new AwsException("InvalidParameterValue", "ConfigurationSet.Name is required.", 400);
}
String name = requireConfigurationSetName(params, "ConfigurationSet.Name");
ConfigurationSet configSet = new ConfigurationSet(name);
configSet.setReputationMetricsEnabled(false);
sesService.createConfigurationSet(configSet, region);
@@ -833,10 +830,7 @@ public class SesQueryHandler {
}
private Response handleDescribeConfigurationSet(MultivaluedMap<String, String> params, String region) {
String name = getParam(params, "ConfigurationSetName");
if (name == null || name.isBlank()) {
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
}
String name = requireConfigurationSetName(params, "ConfigurationSetName");
ConfigurationSet cs = configSetService.get(name, region);
List<String> attrs = extractMembers(params, "ConfigurationSetAttributeNames");
XmlBuilder xml = new XmlBuilder()
@@ -951,17 +945,14 @@ public class SesQueryHandler {
}
private Response handleDeleteConfigurationSet(MultivaluedMap<String, String> params, String region) {
String name = getParam(params, "ConfigurationSetName");
if (name == null || name.isBlank()) {
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
}
String name = requireConfigurationSetName(params, "ConfigurationSetName");
sesService.deleteConfigurationSet(name, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult("DeleteConfigurationSet", AwsNamespaces.SES)).build();
}
private Response handleCreateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestination.Name");
EventDestination dest = readEventDestination(params, "EventDestination");
configSetService.createEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
@@ -971,7 +962,7 @@ public class SesQueryHandler {
private Response handleUpdateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestination.Name");
EventDestination dest = readEventDestination(params, "EventDestination");
configSetService.updateEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
@@ -981,7 +972,7 @@ public class SesQueryHandler {
private Response handleDeleteConfigurationSetEventDestination(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String edName = requireParam(params, "EventDestinationName");
configSetService.deleteEventDestination(configSet, edName, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
@@ -990,7 +981,7 @@ public class SesQueryHandler {
private Response handleUpdateConfigurationSetSendingEnabled(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
boolean enabled = parseXsdBoolean(params, "Enabled");
configSetService.setSendingEnabled(configSet, enabled, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
@@ -999,7 +990,7 @@ public class SesQueryHandler {
private Response handleCreateConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String domain = getParam(params, "TrackingOptions.CustomRedirectDomain");
sesService.createConfigurationSetTrackingOptions(configSet, domain, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
@@ -1008,7 +999,7 @@ public class SesQueryHandler {
private Response handleUpdateConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String domain = getParam(params, "TrackingOptions.CustomRedirectDomain");
sesService.updateConfigurationSetTrackingOptions(configSet, domain, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
@@ -1017,7 +1008,7 @@ public class SesQueryHandler {
private Response handleDeleteConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
configSetService.deleteTrackingOptions(configSet, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
"DeleteConfigurationSetTrackingOptions", AwsNamespaces.SES)).build();
@@ -1025,7 +1016,7 @@ public class SesQueryHandler {
private Response handleUpdateConfigurationSetReputationMetricsEnabled(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
boolean enabled = parseXsdBoolean(params, "Enabled");
configSetService.setReputationMetricsEnabled(configSet, enabled, region);
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
@@ -1034,7 +1025,7 @@ public class SesQueryHandler {
private Response handlePutConfigurationSetDeliveryOptions(MultivaluedMap<String, String> params,
String region) {
String configSet = requireParam(params, "ConfigurationSetName");
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
String tlsPolicy = getParam(params, "DeliveryOptions.TlsPolicy");
// The V1 API accepts TlsPolicy Require/Optional (PascalCase, case-sensitive). Validate
// here so an invalid enum value yields the v1 ValidationError AWS returns rather than the
@@ -1513,6 +1504,12 @@ public class SesQueryHandler {
return dest;
}
private static String requireConfigurationSetName(MultivaluedMap<String, String> params, String name) {
String v = params.getFirst(name);
SesConfigurationSetService.validateName(v);
return v;
}
private static String requireParam(MultivaluedMap<String, String> params, String name) {
String v = params.getFirst(name);
if (v == null || v.isBlank()) {
@@ -136,6 +136,8 @@ public class SesService {
// Resolves the caller's account per request so send-event payloads report the sending account, not
// the fixed default. Null in the package-private test constructor (falls back to defaultAccountId).
private final RegionResolver regionResolver;
// The V2 tag endpoints' resource types, keyed by the ARN's type segment.
private final Map<String, SesTaggable> taggableDomains;
@Inject
public SesService(SesIdentityService identityService, SesCvetService cvetService,
@@ -162,6 +164,7 @@ public class SesService {
this.defaultAccountId = config.defaultAccountId();
this.baseUrl = config.effectiveBaseUrl();
this.regionResolver = regionResolver;
this.taggableDomains = taggableDomains();
}
SesService(SesIdentityService identityService,
@@ -192,6 +195,18 @@ public class SesService {
this.defaultAccountId = "000000000000";
this.baseUrl = "http://localhost:4566";
this.regionResolver = null;
this.taggableDomains = taggableDomains();
}
private Map<String, SesTaggable> taggableDomains() {
return Map.of(
"configuration-set", configSetService,
"template", templateService,
"identity", identityService,
"contact-list", contactService,
"custom-verification-email-template", cvetService,
"dedicated-ip-pool", dedicatedIpService,
"tenant", tenantService);
}
/**
@@ -1171,19 +1186,15 @@ public class SesService {
}
public List<Tag> listResourceTags(String arn, String region) {
if (arn == null) {
// AWS answers an omitted ResourceArn on this read with a 500 InternalFailure
// (probe-confirmed); Floci keeps a client error rather than mirror a server fault.
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
}
ResourceRef ref = parseSesArn(arn);
requireCallerAccount(ref);
List<Tag> tags = switch (ref.type()) {
case "configuration-set" -> configSetService.listTags(ref.name(), region);
case "template" -> templateService.listTags(ref.name(), region);
case "identity" -> identityService.listTags(ref.name(), region);
case "contact-list" -> contactService.listTags(ref.name(), region);
case "custom-verification-email-template" -> cvetService.listTags(ref.name(), region);
case "dedicated-ip-pool" -> dedicatedIpService.listTags(ref.name(), region);
case "tenant" -> tenantService.listTags(ref.name(), region);
default -> throw new AwsException("NotFoundException",
"Resource " + arn + " was not found.", 404);
};
requireValidResourceName(ref);
List<Tag> tags = taggableDomains.get(ref.type()).listTags(ref.name(), region);
// AWS checks existence against the signing region but keys the tag store by the literal
// ARN: a mismatched ARN region passes the existence check above yet addresses an ARN
// nothing was ever tagged under, so the result is empty (probe-confirmed across all six
@@ -1195,8 +1206,13 @@ public class SesService {
}
public void tagResource(String arn, String region, List<Tag> newTags) {
ResourceRef ref = parseSesArn(arn);
ResourceRef ref = parseSesArn(requireResourceArnMember(arn));
requireCallerAccount(ref);
requireValidResourceName(ref);
// Existence in the signing region is checked before the ARN's region is compared: a missing
// resource is a 404 even when the regions also differ (probe-confirmed).
SesTaggable domain = taggableDomains.get(ref.type());
domain.listTags(ref.name(), region);
if (!ref.region().equals(region)) {
throw new AwsException("BadRequestException", "Failed to tag resource", 400);
}
@@ -1204,44 +1220,27 @@ public class SesService {
// checks and then applies the empty merge as a no-op (probe-confirmed).
List<Tag> tags = newTags == null ? List.of() : newTags;
SesTags.validate(tags);
switch (ref.type()) {
case "configuration-set" -> configSetService.tag(ref.name(), region, tags);
case "template" -> templateService.tag(ref.name(), region, tags);
case "identity" -> identityService.tag(ref.name(), region, tags);
case "contact-list" -> contactService.tag(ref.name(), region, tags);
case "custom-verification-email-template" -> cvetService.tag(ref.name(), region, tags);
case "dedicated-ip-pool" -> dedicatedIpService.tag(ref.name(), region, tags);
case "tenant" -> tenantService.tag(ref.name(), region, tags);
default -> throw new AwsException("NotFoundException",
"Resource " + arn + " was not found.", 404);
}
domain.tag(ref.name(), region, tags);
}
public void untagResource(String arn, String region, List<String> tagKeys) {
ResourceRef ref = parseSesArn(arn);
ResourceRef ref = parseSesArn(requireResourceArnMember(arn));
requireCallerAccount(ref);
if (tagKeys == null || tagKeys.isEmpty()) {
// AWS rejects a missing/empty TagKeys member with a message-less ValidationException
// (probe-confirmed: only the error-type header, empty body), after the account guard
// and before the region guard. The null message is deliberate — it surfaces through
// Floci's standard error body as "message":null, which restJson1 SDKs parse the same
// way as AWS's empty body since they read x-amzn-errortype first.
// and before the name, existence and region checks. The null message is deliberate: it
// surfaces through Floci's standard error body as "message":null, which restJson1 SDKs
// parse the same way as AWS's empty body since they read x-amzn-errortype first.
throw new AwsException("ValidationException", null, 400);
}
requireValidResourceName(ref);
SesTaggable domain = taggableDomains.get(ref.type());
domain.listTags(ref.name(), region);
if (!ref.region().equals(region)) {
throw new AwsException("BadRequestException", "Failed to untag resource", 400);
}
switch (ref.type()) {
case "configuration-set" -> configSetService.untag(ref.name(), region, tagKeys);
case "template" -> templateService.untag(ref.name(), region, tagKeys);
case "identity" -> identityService.untag(ref.name(), region, tagKeys);
case "contact-list" -> contactService.untag(ref.name(), region, tagKeys);
case "custom-verification-email-template" -> cvetService.untag(ref.name(), region, tagKeys);
case "dedicated-ip-pool" -> dedicatedIpService.untag(ref.name(), region, tagKeys);
case "tenant" -> tenantService.untag(ref.name(), region, tagKeys);
default -> throw new AwsException("NotFoundException",
"Resource " + arn + " was not found.", 404);
}
domain.untag(ref.name(), region, tagKeys);
}
// name is everything after the type's first slash and may itself contain one: a tenant ARN's
@@ -1261,31 +1260,58 @@ public class SesService {
}
}
private static ResourceRef parseSesArn(String arn) {
if (arn == null || arn.isBlank()) {
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
// TagResource and UntagResource reject an omitted ResourceArn with the same message-less
// ValidationException as an omitted TagKeys (probe-confirmed).
private static String requireResourceArnMember(String arn) {
if (arn == null) {
throw new AwsException("ValidationException", null, 400);
}
return arn;
}
// A configuration-set name that breaks the naming rule is a message-less ValidationException,
// after the account check and before existence (probe-confirmed).
private static void requireValidResourceName(ResourceRef ref) {
if ("configuration-set".equals(ref.type()) && !SesConfigurationSetService.isValidName(ref.name())) {
throw new AwsException("ValidationException", null, 400);
}
}
/**
* AWS answers every malformed tag ARN with one message (probe-confirmed). The partition and
* service are never compared, only required: any value addresses the same resource. The region
* may be empty; it only meets the signing-region comparison.
*/
private ResourceRef parseSesArn(String arn) {
AwsArnUtils.Arn parsed;
try {
parsed = AwsArnUtils.parse(arn);
} catch (IllegalArgumentException e) {
throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);
throw invalidResourceArn();
}
if (!"ses".equals(parsed.service())) {
throw new AwsException("BadRequestException",
"ResourceArn must be a SES ARN: " + arn, 400);
}
if (parsed.region().isEmpty() || parsed.accountId().isEmpty()) {
throw new AwsException("BadRequestException",
"ResourceArn must include region and account: " + arn, 400);
if (parsed.partition().isEmpty() || parsed.service().isEmpty() || parsed.accountId().isEmpty()) {
throw invalidResourceArn();
}
String resource = parsed.resource();
int slash = resource.indexOf('/');
if (slash <= 0 || slash == resource.length() - 1) {
throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);
if (slash < 0) {
throw invalidResourceArn();
}
return new ResourceRef(parsed.accountId(), parsed.region(),
resource.substring(0, slash), resource.substring(slash + 1));
String type = resource.substring(0, slash);
String name = resource.substring(slash + 1);
if (!taggableDomains.containsKey(type) || name.isBlank()) {
throw invalidResourceArn();
}
// Identity names keep their pass-through: an email local part may legally hold either character.
if (!"identity".equals(type)
&& (name.contains(":") || (!"tenant".equals(type) && name.contains("/")))) {
throw invalidResourceArn();
}
return new ResourceRef(parsed.accountId(), parsed.region(), type, name);
}
private static AwsException invalidResourceArn() {
return new AwsException("BadRequestException", "ResourceArn is not the expected format", 400);
}
// ──────────────────────────── Suppression list ────────────────────────────
@@ -20,6 +20,7 @@ import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;
import org.jboss.logging.Logger;
import java.util.List;
@@ -63,9 +64,6 @@ public class SesTagController {
}
JsonNode request = objectMapper.readTree(body);
String arn = request.path("ResourceArn").asText(null);
if (arn == null || arn.isBlank()) {
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
}
List<Tag> tags = parseTagsArray(request.path("Tags"));
if (tags == null) {
throw new AwsException("BadRequestException", "Tags must be an array.", 400);
@@ -82,10 +80,10 @@ public class SesTagController {
@DELETE
@Path("/tags")
public Response untagResource(@Context HttpHeaders headers,
@QueryParam("ResourceArn") String arn,
public Response untagResource(@Context HttpHeaders headers, @Context UriInfo uriInfo,
@QueryParam("TagKeys") List<String> tagKeys) {
String region = regionResolver.resolveRegion(headers);
String arn = resourceArn(uriInfo);
try {
sesService.untagResource(arn, region, tagKeys);
LOG.infov("SES V2 UntagResource: {0}", arn);
@@ -97,9 +95,9 @@ public class SesTagController {
@GET
@Path("/tags")
public Response listTagsForResource(@Context HttpHeaders headers,
@QueryParam("ResourceArn") String arn) {
public Response listTagsForResource(@Context HttpHeaders headers, @Context UriInfo uriInfo) {
String region = regionResolver.resolveRegion(headers);
String arn = resourceArn(uriInfo);
try {
List<Tag> tags = sesService.listResourceTags(arn, region);
ObjectNode result = objectMapper.createObjectNode();
@@ -115,4 +113,10 @@ public class SesTagController {
throw remapV1Exception(e);
}
}
// A @QueryParam binds an empty value as null; read it raw so "ResourceArn=" stays a malformed ARN
// rather than an omitted one.
private static String resourceArn(UriInfo uriInfo) {
return uriInfo.getQueryParameters().getFirst("ResourceArn");
}
}
@@ -0,0 +1,18 @@
package io.github.hectorvent.floci.services.ses;
import io.github.hectorvent.floci.services.ses.model.Tag;
import java.util.List;
/**
* A domain whose resources the V2 tag endpoints address by ARN. Each method resolves the resource
* in {@code region} and fails with that domain's {@code NotFoundException} when it is missing.
*/
interface SesTaggable {
List<Tag> listTags(String name, String region);
void tag(String name, String region, List<Tag> newTags);
void untag(String name, String region, List<String> tagKeys);
}
@@ -46,7 +46,7 @@ import java.util.regex.Pattern;
* {@link SesTags#validate} rather than depending back on the facade.
*/
@ApplicationScoped
public class SesTemplateService {
public class SesTemplateService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesTemplateService.class);
@@ -212,10 +212,12 @@ public class SesTemplateService {
}
/** The ARN-dispatched tag operations, sharing the store behind {@code CreateEmailTemplate.Tags}. */
@Override
public List<Tag> listTags(String name, String region) {
return new ArrayList<>(requireForTags(name, region).getTags());
}
@Override
public void tag(String name, String region, List<Tag> newTags) {
EmailTemplate template = requireForTags(name, region);
template.setTags(SesTags.merge(template.getTags(), newTags));
@@ -223,6 +225,7 @@ public class SesTemplateService {
LOG.infov("Tagged SES template: {0} (region {1}, +{2} tags)", name, region, newTags.size());
}
@Override
public void untag(String name, String region, List<String> tagKeys) {
EmailTemplate template = requireForTags(name, region);
Set<String> toRemove = new HashSet<>(tagKeys);
@@ -47,7 +47,7 @@ import java.util.regex.Pattern;
* {@code DeleteTenant} callback. Tenant-scoped sending is a separate follow-up.
*/
@ApplicationScoped
public class SesTenantService {
public class SesTenantService implements SesTaggable {
private static final Logger LOG = Logger.getLogger(SesTenantService.class);
@@ -255,6 +255,7 @@ public class SesTenantService {
}
/** The ARN-dispatched tag operations; {@code resourceRemainder} is the ARN's {@code <name>/<tenantId>} part. */
@Override
public List<Tag> listTags(String resourceRemainder, String region) {
Tenant tenant = tenantForTagArn(resourceRemainder, region);
// AWS returns a tenant's tags ordered by key (probe-confirmed).
@@ -263,12 +264,14 @@ public class SesTenantService {
.toList();
}
@Override
public void tag(String resourceRemainder, String region, List<Tag> newTags) {
mutateTags(resourceRemainder, region, tags -> SesTags.merge(tags, newTags));
LOG.infov("Tagged SES tenant <{0}> (region {1}, +{2} tags)",
resourceRemainder, region, newTags.size());
}
@Override
public void untag(String resourceRemainder, String region, List<String> tagKeys) {
Set<String> toRemove = new HashSet<>(tagKeys);
mutateTags(resourceRemainder, region, tags -> {