mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): word EventBridge destination and certificate address refusals like SES (#8819)
* fix(ses): word EventBridge destination and certificate address refusals like SES
This commit is contained in:
1 parent
cdb1cffa76
commit
8bf636b000
5 files changed
+63
-18
No files matched your search
@@ -62,6 +62,8 @@ public class SesConfigurationSetService implements SesTaggable {
|
||||
private static final Pattern EVENT_DESTINATION_NAME_CHARS = Pattern.compile("^[A-Za-z0-9_-]+$");
|
||||
private static final int MAX_EVENT_DESTINATION_NAME_LENGTH = 64;
|
||||
private static final String INVALID_SNS_DESTINATION = "InvalidSNSDestination";
|
||||
private static final String EVENT_BUS_RESOURCE_PREFIX = "event-bus/";
|
||||
private static final String DEFAULT_EVENT_BUS_RESOURCE = EVENT_BUS_RESOURCE_PREFIX + "default";
|
||||
private static final Pattern SNS_TOPIC_NAME = Pattern.compile("[A-Za-z0-9_-]{1,256}(\\.fifo)?");
|
||||
// The pattern SES declares for the stored value, quoted in the violation it answers on v2.
|
||||
private static final Pattern STORED_SNS_TOPIC_ARN = Pattern.compile(
|
||||
@@ -751,9 +753,11 @@ public class SesConfigurationSetService implements SesTaggable {
|
||||
+ "> should have the form <arn:aws:sns:region:[account-id]:[topic-name]>", 400); // partition-literal: AWS's fixed wording
|
||||
}
|
||||
|
||||
// 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.
|
||||
// SES publishes email events only to the default EventBridge bus of the configuration set's
|
||||
// account and region. Probed 2026-11-18: each way the ARN can miss that has its own message.
|
||||
// The probe broke one thing per call, so the order of the checks is Floci's. "Wrongly formatted"
|
||||
// was seen for an SNS topic ARN only; the other shapes it answers here are Floci's reading. A
|
||||
// missing or blank value never reached SES (the AWS CLI refuses it), so that message is Floci's.
|
||||
private static void validateEventBridgeDestination(
|
||||
EventBridgeDestination eventBridge, String accountId, String region) {
|
||||
String busArn = eventBridge.getEventBusArn();
|
||||
@@ -765,22 +769,27 @@ public class SesConfigurationSetService implements SesTaggable {
|
||||
try {
|
||||
arn = AwsArnUtils.parse(busArn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn is not a valid ARN: " + busArn + ".", 400);
|
||||
throw new AwsException("InvalidParameterValue", "Invalid event bus ARN provided.", 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())) {
|
||||
|| !arn.resource().startsWith(EVENT_BUS_RESOURCE_PREFIX)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn must be a valid default event bus ARN: "
|
||||
+ busArn + ".", 400);
|
||||
"Invalid Event Bridge destination, event-bus ARN is wrongly formatted", 400);
|
||||
}
|
||||
if (!arn.accountId().equals(accountId) || !arn.region().equals(region)) {
|
||||
if (!arn.accountId().equals(accountId)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"EventBridgeDestination EventBusArn must match the configuration set's account and Region: "
|
||||
+ busArn + ".", 400);
|
||||
"Invalid Event Bridge destination, cross account is not supported.", 400);
|
||||
}
|
||||
if (!arn.region().equals(region)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid Event Bridge destination, must be in region <" + region + ">.", 400);
|
||||
}
|
||||
if (!DEFAULT_EVENT_BUS_RESOURCE.equals(arn.resource())) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid Event Bridge destination, must be default bus.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -325,8 +325,10 @@ public class SesIdentityCertificateService {
|
||||
+ emailIdentity + ">.");
|
||||
}
|
||||
} else if (!fromAddress.equals(emailIdentity)) {
|
||||
// The model requires an exact match; SES's wording for a mismatch was not probed.
|
||||
throw badRequest("FromAddress <" + fromAddress + "> does not match the email identity <"
|
||||
// The model requires an exact match, so the comparison is case-sensitive (not probed).
|
||||
// The wording was probed 2026-11-18 on AssociateEmailIdentityCertificate, where it is
|
||||
// reported ahead of the 404 for an identity that does not exist.
|
||||
throw badRequest("FromAddress <" + fromAddress + "> must match the email identity <"
|
||||
+ emailIdentity + ">.");
|
||||
}
|
||||
return fromAddress;
|
||||
|
||||
@@ -266,6 +266,7 @@ class SesConfigurationSetEventDestinationTest {
|
||||
withEventBridge("arn:aws:events:us-east-1:111111111111:event-bus/default"),
|
||||
ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("Invalid Event Bridge destination, cross account is not supported.", ex.getMessage());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@@ -276,6 +277,7 @@ class SesConfigurationSetEventDestinationTest {
|
||||
withEventBridge("arn:aws:events:us-west-2:000000000000:event-bus/default"),
|
||||
ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("Invalid Event Bridge destination, must be in region <us-east-1>.", ex.getMessage());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
}
|
||||
|
||||
@@ -300,6 +302,7 @@ class SesConfigurationSetEventDestinationTest {
|
||||
withEventBridge(
|
||||
"arn:aws:events:us-east-1:000000000000:event-bus/custom-bus"), ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("Invalid Event Bridge destination, must be default bus.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -309,6 +312,34 @@ class SesConfigurationSetEventDestinationTest {
|
||||
withEventBridge(
|
||||
"arn:aws:sns:us-east-1:000000000000:event-bus/default"), ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("Invalid Event Bridge destination, event-bus ARN is wrongly formatted", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventBridgeNonBusResource_throws() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> SesConfigurationSetService.validateEventDestination(
|
||||
withEventBridge("arn:aws:events:us-east-1:000000000000:rule/floci-rule"), ACCOUNT_ID, REGION));
|
||||
assertEquals("Invalid Event Bridge destination, event-bus ARN is wrongly formatted", ex.getMessage());
|
||||
}
|
||||
|
||||
// SES was probed with one fault per call, so these two pin the order Floci chose.
|
||||
@Test
|
||||
void eventBridgeAccountIsCheckedBeforeRegionAndBus() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> SesConfigurationSetService.validateEventDestination(
|
||||
withEventBridge("arn:aws:events:us-west-2:111111111111:event-bus/custom-bus"),
|
||||
ACCOUNT_ID, REGION));
|
||||
assertEquals("Invalid Event Bridge destination, cross account is not supported.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventBridgeRegionIsCheckedBeforeBus() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> SesConfigurationSetService.validateEventDestination(
|
||||
withEventBridge("arn:aws:events:us-west-2:000000000000:event-bus/custom-bus"),
|
||||
ACCOUNT_ID, REGION));
|
||||
assertEquals("Invalid Event Bridge destination, must be in region <us-east-1>.", ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -317,6 +348,7 @@ class SesConfigurationSetEventDestinationTest {
|
||||
() -> SesConfigurationSetService.validateEventDestination(
|
||||
withEventBridge("not-an-arn"), ACCOUNT_ID, REGION));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals("Invalid event bus ARN provided.", ex.getMessage());
|
||||
}
|
||||
|
||||
private static EventDestination withEventBridge(String busArn) {
|
||||
|
||||
+4
-2
@@ -422,7 +422,8 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
|
||||
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid Event Bridge destination, must be default bus."));
|
||||
|
||||
// The rejected destination must not have been stored.
|
||||
given()
|
||||
@@ -478,7 +479,8 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
|
||||
.put("/v2/email/configuration-sets/" + cs + "/event-destinations/ed-eb-default")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid Event Bridge destination, must be default bus."));
|
||||
|
||||
// The stored destination must still point at the default event bus.
|
||||
given()
|
||||
|
||||
@@ -96,15 +96,15 @@ class SesIdentityCertificateServiceTest {
|
||||
|
||||
assertEquals(List.of("alice@example.org"),
|
||||
fromAddresses(service.list("alice@example.org", null, null, REGION)));
|
||||
assertBadRequest("FromAddress <bob@example.org> does not match the email identity <alice@example.org>.",
|
||||
assertBadRequest("FromAddress <bob@example.org> must match the email identity <alice@example.org>.",
|
||||
() -> service.associate("alice@example.org", "bob@example.org", CERT_ARN, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emailIdentityFromAddressMustMatchExactly() {
|
||||
assertBadRequest("FromAddress <Alice@example.org> does not match the email identity <alice@example.org>.",
|
||||
assertBadRequest("FromAddress <Alice@example.org> must match the email identity <alice@example.org>.",
|
||||
() -> service.associate("alice@example.org", "Alice@example.org", CERT_ARN, REGION));
|
||||
assertBadRequest("FromAddress <ALICE@example.org> does not match the email identity <alice@example.org>.",
|
||||
assertBadRequest("FromAddress <ALICE@example.org> must match the email identity <alice@example.org>.",
|
||||
() -> service.disassociate("alice@example.org", "ALICE@example.org", REGION));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user