mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ses): validate EventBridge default bus ARNs (#4677)
* fix(ses): validate EventBridge default bus ARNs Signed-off-by: boulea7 <zln1905391059@163.com> * fix(ses): reject EventBridge bus account and Region mismatches Signed-off-by: boulea7 <zln1905391059@163.com> --------- Signed-off-by: boulea7 <zln1905391059@163.com>
This commit is contained in:
1 parent
8ff1eae121
commit
d267ba3a9d
8 files changed
+652
-34
No files matched your search
+3
-2
@@ -455,7 +455,8 @@ public class SesConfigurationSetController {
|
||||
throw new AwsException("BadRequestException", "EventDestination is required.", 400);
|
||||
}
|
||||
EventDestination dest = objectMapper.treeToValue(edNode, EventDestination.class);
|
||||
configSetService.createEventDestination(configurationSetName, edName, dest, region);
|
||||
configSetService.createEventDestination(configurationSetName, edName, dest,
|
||||
regionResolver.getAccountId(), region);
|
||||
LOG.infov("SES V2 CreateConfigurationSetEventDestination: {0} on {1}", edName, configurationSetName);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -499,7 +500,7 @@ public class SesConfigurationSetController {
|
||||
}
|
||||
EventDestination dest = objectMapper.treeToValue(edNode, EventDestination.class);
|
||||
configSetService.updateEventDestination(configurationSetName, eventDestinationName,
|
||||
dest, region);
|
||||
dest, regionResolver.getAccountId(), region);
|
||||
LOG.infov("SES V2 UpdateConfigurationSetEventDestination: {0} on {1}",
|
||||
eventDestinationName, configurationSetName);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
|
||||
+43
-5
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
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.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -8,6 +9,7 @@ import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.CloudWatchDimensionConfiguration;
|
||||
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.DeliveryOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.EventBridgeDestination;
|
||||
import io.github.hectorvent.floci.services.ses.model.EventDestination;
|
||||
import io.github.hectorvent.floci.services.ses.model.TrackingOptions;
|
||||
import io.github.hectorvent.floci.services.ses.model.SuppressionOptions;
|
||||
@@ -473,9 +475,9 @@ public class SesConfigurationSetService {
|
||||
// ──────────────────────────── Event destinations ────────────────────────────
|
||||
|
||||
public void createEventDestination(String configSetName, String eventDestinationName,
|
||||
EventDestination dest, String region) {
|
||||
EventDestination dest, String accountId, String region) {
|
||||
validateEventDestinationName(eventDestinationName);
|
||||
validateEventDestination(dest);
|
||||
validateEventDestination(dest, accountId, region);
|
||||
ConfigurationSet cs = get(configSetName, region);
|
||||
if (indexOfEventDestination(cs.getEventDestinations(), eventDestinationName) >= 0) {
|
||||
throw new AwsException("AlreadyExists",
|
||||
@@ -494,9 +496,9 @@ public class SesConfigurationSetService {
|
||||
}
|
||||
|
||||
public void updateEventDestination(String configSetName, String eventDestinationName,
|
||||
EventDestination dest, String region) {
|
||||
EventDestination dest, String accountId, String region) {
|
||||
validateEventDestinationName(eventDestinationName);
|
||||
validateEventDestination(dest);
|
||||
validateEventDestination(dest, accountId, region);
|
||||
ConfigurationSet cs = get(configSetName, region);
|
||||
int index = indexOfEventDestination(cs.getEventDestinations(), eventDestinationName);
|
||||
if (index < 0) {
|
||||
@@ -549,7 +551,7 @@ public class SesConfigurationSetService {
|
||||
}
|
||||
}
|
||||
|
||||
static void validateEventDestination(EventDestination dest) {
|
||||
static void validateEventDestination(EventDestination dest, String accountId, String region) {
|
||||
if (dest == null) {
|
||||
throw new AwsException("InvalidParameterValue", "EventDestination is required.", 400);
|
||||
}
|
||||
@@ -616,6 +618,42 @@ public class SesConfigurationSetService {
|
||||
"Invalid Pinpoint application ARN provided: "
|
||||
+ dest.getPinpointDestination().getApplicationArn() + ".", 400);
|
||||
}
|
||||
if (dest.getEventBridgeDestination() != null) {
|
||||
validateEventBridgeDestination(dest.getEventBridgeDestination(), accountId, region);
|
||||
}
|
||||
}
|
||||
|
||||
// SES publishes email events only to the default EventBridge bus, so the
|
||||
// EventBusArn member must name event-bus/default of the events service in the
|
||||
// configuration set's account and region. All supported AWS partitions are accepted.
|
||||
private static void validateEventBridgeDestination(
|
||||
EventBridgeDestination eventBridge, String accountId, String region) {
|
||||
String busArn = eventBridge.getEventBusArn();
|
||||
if (busArn == null || busArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination requires a non-blank EventBusArn.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn;
|
||||
try {
|
||||
arn = AwsArnUtils.parse(busArn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn is not a valid ARN: " + busArn + ".", 400);
|
||||
}
|
||||
if (!arn.partition().matches(AwsArnUtils.PARTITION_REGEX)
|
||||
|| arn.region().isBlank()
|
||||
|| !arn.accountId().matches("[0-9]{12}")
|
||||
|| !"events".equals(arn.service())
|
||||
|| !"event-bus/default".equals(arn.resource())) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn must be a valid default event bus ARN: "
|
||||
+ busArn + ".", 400);
|
||||
}
|
||||
if (!arn.accountId().equals(accountId) || !arn.region().equals(region)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn must match the configuration set's account and Region: "
|
||||
+ busArn + ".", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static int countDestinations(EventDestination dest) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
|
||||
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;
|
||||
@@ -57,6 +58,7 @@ public class SesQueryHandler {
|
||||
private final SesConfigurationSetService configSetService;
|
||||
private final SesPolicyService policyService;
|
||||
private final SesSentEmailService sentEmailService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
@@ -65,7 +67,8 @@ public class SesQueryHandler {
|
||||
SesCvetService cvetService, SesAccountService accountService,
|
||||
SesConfigurationSetService configSetService,
|
||||
SesPolicyService policyService,
|
||||
SesSentEmailService sentEmailService, ObjectMapper objectMapper) {
|
||||
SesSentEmailService sentEmailService, RegionResolver regionResolver,
|
||||
ObjectMapper objectMapper) {
|
||||
this.sesService = sesService;
|
||||
this.receiptRuleService = receiptRuleService;
|
||||
this.identityService = identityService;
|
||||
@@ -75,6 +78,7 @@ public class SesQueryHandler {
|
||||
this.configSetService = configSetService;
|
||||
this.policyService = policyService;
|
||||
this.sentEmailService = sentEmailService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@@ -948,7 +952,7 @@ public class SesQueryHandler {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String edName = requireParam(params, "EventDestination.Name");
|
||||
EventDestination dest = readEventDestination(params, "EventDestination");
|
||||
configSetService.createEventDestination(configSet, edName, dest, region);
|
||||
configSetService.createEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"CreateConfigurationSetEventDestination", AwsNamespaces.SES)).build();
|
||||
}
|
||||
@@ -958,7 +962,7 @@ public class SesQueryHandler {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String edName = requireParam(params, "EventDestination.Name");
|
||||
EventDestination dest = readEventDestination(params, "EventDestination");
|
||||
configSetService.updateEventDestination(configSet, edName, dest, region);
|
||||
configSetService.updateEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"UpdateConfigurationSetEventDestination", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user