mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ses): return Easy DKIM signing hosted zone (#5068)
* fix(ses): expose DKIM signing hosted zone * fix(ses): keep DKIM signing hosted zone constant * fix(ses): align signing zone tests with review
This commit is contained in:
1 parent
fb202cce6a
commit
58ac05433a
8 files changed
+68
-3
No files matched your search
@@ -1041,6 +1041,10 @@ public final class TestFixtures {
|
||||
if (tokens == null || tokens.isEmpty()) {
|
||||
throw new IllegalStateException("CreateEmailIdentity did not return DKIM tokens for " + domain);
|
||||
}
|
||||
String signingHostedZone = identity.dkimAttributes().signingHostedZone();
|
||||
if (signingHostedZone == null || signingHostedZone.isBlank()) {
|
||||
throw new IllegalStateException("CreateEmailIdentity did not return SigningHostedZone for " + domain);
|
||||
}
|
||||
|
||||
try (Route53Client route53 = route53Client()) {
|
||||
CreateHostedZoneResponse zone = route53.createHostedZone(CreateHostedZoneRequest.builder()
|
||||
@@ -1056,7 +1060,7 @@ public final class TestFixtures {
|
||||
.type(RRType.CNAME)
|
||||
.ttl(300L)
|
||||
.resourceRecords(ResourceRecord.builder()
|
||||
.value(token + ".dkim.amazonses.com")
|
||||
.value(token + "." + signingHostedZone)
|
||||
.build())
|
||||
.build())
|
||||
.build())
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityResponse;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class SesSigningHostedZoneTest {
|
||||
|
||||
@Test
|
||||
void createAndGetReturnTheSameSigningHostedZone() {
|
||||
String domain = TestFixtures.uniqueName("compat-ses-signing-zone") + ".floci.test";
|
||||
try (SesV2Client ses = TestFixtures.sesV2Client()) {
|
||||
CreateEmailIdentityResponse created = ses.createEmailIdentity(CreateEmailIdentityRequest.builder()
|
||||
.emailIdentity(domain).build());
|
||||
try {
|
||||
assertThat(created.dkimAttributes().signingHostedZone()).isNotBlank();
|
||||
GetEmailIdentityResponse fetched = ses.getEmailIdentity(GetEmailIdentityRequest.builder()
|
||||
.emailIdentity(domain).build());
|
||||
assertThat(fetched.dkimAttributes().signingHostedZone())
|
||||
.isEqualTo(created.dkimAttributes().signingHostedZone());
|
||||
} finally {
|
||||
ses.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(domain).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -483,6 +483,14 @@ The contact lists (`ListContactLists`, `ListContacts`), the dedicated-IP lists (
|
||||
|
||||
DKIM follows AWS's domain-centric model. A **domain** identity carries DKIM tokens (generated at verification, stable across `VerifyDomainDkim` calls); its `DkimVerificationStatus` tracks **DNS record detection** — it transitions to `Success` when the expected `<token>._domainkey.<domain>` CNAMEs are present in the Route53 emulation, not when DKIM is enabled. An **email** identity has no DKIM of its own: its `DkimAttributes` (`SigningEnabled`, `Status`, `Tokens`) are inherited from its parent domain identity when one is registered. The parent is the exact domain after the `@` (verified against AWS): a verified `example.com` covers `user@example.com` but not `user@mail.example.com` unless `mail.example.com` is itself a registered identity. `SetIdentityDkimEnabled` / `PutEmailIdentityDkimAttributes` only toggle the signing flag (they no longer force the verification status); `PutEmailIdentityDkimSigningAttributes` sets the signing origin (`AWS_SES` Easy DKIM — regenerating tokens when the key length changes — or `EXTERNAL` BYODKIM).
|
||||
|
||||
SES v2 `CreateEmailIdentity` and `GetEmailIdentity` report `DkimAttributes.SigningHostedZone` for
|
||||
Easy DKIM identities. Floci reports the fixed emulator value `dkim.amazonses.com`, and
|
||||
Route53-backed DKIM detection uses that same constant to construct `<token>.<SigningHostedZone>`.
|
||||
The zone is not identity state or configurable; Floci does not reproduce AWS's region-
|
||||
and identity-specific hosted-zone assignment. Email identities inherit their registered domain's
|
||||
DKIM attributes. BYODKIM identities and email identities without a
|
||||
registered Easy DKIM domain do not report this SES-hosted zone.
|
||||
|
||||
S/MIME certificate associations are stored per region and never used: Floci does not sign mail. Associating validates the request as SES does (a domain identity needs a `FromAddress` in the domain or one of its subdomains, one certificate per address regardless of case) but, like SES, does not inspect the certificate. `ListEmailIdentityCertificates` reports `ACTIVE` while the association meets the [S/MIME certificate considerations](https://docs.aws.amazon.com/ses/latest/dg/send-email-authentication-smime.html#send-email-authentication-smime-certificate-considerations), plus the requirements a probe found SES also enforces (an end-entity certificate whose key usage includes `digitalSignature` and whose extended key usage includes `emailProtection`), checked against Floci's ACM and identity verification when the list is read, with the certificate's expiry as `CertificateExpiryTime`, and `FAILED` otherwise. There is no `PROVISIONING` phase, `DisassociateEmailIdentityCertificate` removes an association at once, and the certificate is not listed as in use by ACM. As on SES, `DeleteEmailIdentity` refuses an identity that still has a certificate associated, whatever its status. The v1 `DeleteIdentity` and `DeleteVerifiedEmailAddress` share the identities and refuse it too, with the same `BadRequestException` the tenant-association guard returns there; SES's v1 behaviour was not probed.
|
||||
|
||||
### IAM enforcement
|
||||
|
||||
@@ -579,6 +579,10 @@ public class SesIdentityController {
|
||||
tokens.add(token);
|
||||
}
|
||||
}
|
||||
if ("Domain".equals(src.getIdentityType()) && "AWS_SES".equals(src.getDkimSigningAttributesOrigin())
|
||||
&& !tokens.isEmpty()) {
|
||||
dkim.put("SigningHostedZone", SesIdentityService.DKIM_SIGNING_HOSTED_ZONE);
|
||||
}
|
||||
dkim.put("SigningAttributesOrigin", src.getDkimSigningAttributesOrigin());
|
||||
dkim.put("NextSigningKeyLength", src.getDkimNextSigningKeyLength());
|
||||
dkim.put("CurrentSigningKeyLength", src.getDkimCurrentSigningKeyLength());
|
||||
|
||||
@@ -45,6 +45,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@ApplicationScoped
|
||||
public class SesIdentityService implements SesTaggable {
|
||||
|
||||
static final String DKIM_SIGNING_HOSTED_ZONE = "dkim.amazonses.com";
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesIdentityService.class);
|
||||
|
||||
private static final Duration DKIM_LOOKUP_CACHE_TTL = Duration.ofSeconds(5);
|
||||
@@ -714,7 +716,7 @@ public class SesIdentityService implements SesTaggable {
|
||||
|
||||
private boolean hasExpectedDkimRecord(String domain, String token) {
|
||||
String expectedName = normalizeDnsName(token + "._domainkey." + domain);
|
||||
String expectedValue = normalizeDnsName(token + ".dkim.amazonses.com");
|
||||
String expectedValue = normalizeDnsName(token + "." + DKIM_SIGNING_HOSTED_ZONE);
|
||||
for (HostedZone zone : route53Service.listHostedZones(null, Integer.MAX_VALUE)) {
|
||||
for (ResourceRecordSet recordSet : route53Service.listResourceRecordSets(zone.getId(), null, null,
|
||||
Integer.MAX_VALUE)) {
|
||||
|
||||
+4
@@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
@@ -96,6 +97,7 @@ class SesDkimSigningActionsIntegrationTest {
|
||||
given().header("Authorization", V2_AUTH)
|
||||
.when().get("/v2/email/identities/" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.CurrentSigningKeyLength", equalTo("RSA_1024_BIT"))
|
||||
.body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com"))
|
||||
.body("DkimAttributes.Tokens", equalTo(after));
|
||||
}
|
||||
|
||||
@@ -197,6 +199,7 @@ class SesDkimSigningActionsIntegrationTest {
|
||||
.when().get("/v2/email/identities/" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"))
|
||||
.body("DkimAttributes.SigningAttributesOrigin", equalTo("EXTERNAL"))
|
||||
.body("DkimAttributes.SigningHostedZone", nullValue())
|
||||
.body("DkimAttributes.Tokens", hasSize(0));
|
||||
}
|
||||
|
||||
@@ -248,6 +251,7 @@ class SesDkimSigningActionsIntegrationTest {
|
||||
.when().get("/v2/email/identities/bob@" + domain).then().statusCode(200)
|
||||
.body("DkimAttributes.SigningEnabled", equalTo(true))
|
||||
.body("DkimAttributes.Status", equalTo("PENDING"))
|
||||
.body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com"))
|
||||
.body("DkimAttributes.Tokens", equalTo(domainTokens))
|
||||
.body("DkimAttributes.Tokens", not(hasSize(0)));
|
||||
}
|
||||
|
||||
+3
-1
@@ -30,7 +30,8 @@ class SesIdentityAttributesV2IntegrationTest {
|
||||
.when()
|
||||
.post("/v2/email/identities")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
.statusCode(200)
|
||||
.body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com"));
|
||||
|
||||
// With no MAIL FROM domain configured, AWS keeps the MailFromAttributes
|
||||
// block carrying only BehaviorOnMxFailure and omits the inner
|
||||
@@ -41,6 +42,7 @@ class SesIdentityAttributesV2IntegrationTest {
|
||||
.get("/v2/email/identities/v2-attrs.floci.test")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DkimAttributes.SigningHostedZone", equalTo("dkim.amazonses.com"))
|
||||
.body("MailFromAttributes.BehaviorOnMxFailure", equalTo("USE_DEFAULT_VALUE"))
|
||||
.body("MailFromAttributes.MailFromDomain", nullValue())
|
||||
.body("MailFromAttributes.MailFromDomainStatus", nullValue());
|
||||
|
||||
+9
@@ -102,6 +102,15 @@ class SesIdentityDkimLookupCacheTest {
|
||||
verify(route53Service, times(4)).listResourceRecordSets(eq("zone-1"), eq(null), eq(null), eq(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dnsDetectionUsesTheReportedSigningHostedZone() {
|
||||
Identity identity = storePendingDomainIdentity();
|
||||
stubRoute53(identity, buildMatchingRecords(identity));
|
||||
|
||||
assertEquals("Success", identities.getIdentityVerificationAttributes(DOMAIN, REGION)
|
||||
.getDkimVerificationStatus());
|
||||
}
|
||||
|
||||
private Identity storePendingDomainIdentity() {
|
||||
Identity identity = new Identity(DOMAIN, "Domain");
|
||||
identity.setVerificationStatus("Pending");
|
||||
|
||||
Reference in new issue
Block a user