feat(acm): map CertificateExport and CertificateTransparencyLoggingPreference onto the certificate options (#3111)

The AWS::CertificateManager::Certificate provisioner accepted both properties
and ignored them, so every certificate a stack created carried the ACM
defaults. Both now become the certificate's Options, with the CloudFormation
defaults (export DISABLED, transparency logging ENABLED) when absent, and a
value other than ENABLED or DISABLED fails the resource before any ACM call.

Updates follow the registry schema: CertificateExport is createOnly, so a
change replaces the certificate through the existing delete-or-unwind path,
while a changed CertificateTransparencyLoggingPreference calls
UpdateCertificateOptions on the existing certificate and keeps its ARN.
Export is never sent to UpdateCertificateOptions, since ACM does not allow
changing it once the certificate exists.

CertificateAuthorityArn stays ignored; private CA is not emulated.
This commit is contained in:
Mario Toffia authored and GitHub committed 2026-09-05 18:42:39 -05:00
1 parent 6be9c1ee26
commit 615056999e
4 files changed
+661 -53

No files matched your search

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.acm.AcmService;
import io.github.hectorvent.floci.services.acm.model.Certificate;
import io.github.hectorvent.floci.services.acm.model.CertificateOptions;
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
import io.github.hectorvent.floci.services.acm.model.ValidationMethod;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
@@ -21,11 +22,17 @@ import java.util.Set;
* <p>The certificate is ISSUED as soon as it is requested. Real ACM waits for DNS or email
* validation and CloudFormation waits with it; the emulator has nothing to validate, so
* {@code DomainValidationOptions} is accepted and ignored.
*
* <p>{@code CertificateExport} and {@code CertificateTransparencyLoggingPreference} become the
* certificate's options. The first is createOnly in the registry schema, so a change replaces the
* certificate; the second updates in place through {@code UpdateCertificateOptions}, as
* CloudFormation does.
*/
@ApplicationScoped
public class AcmCfnProvisioner implements CfnResourceProvisioner {
private static final Logger LOG = Logger.getLogger(AcmCfnProvisioner.class);
private static final Set<String> OPTION_VALUES = Set.of("ENABLED", "DISABLED");
private final AcmService acmService;
@@ -42,25 +49,30 @@ public class AcmCfnProvisioner implements CfnResourceProvisioner {
public void provision(StackResource r, JsonNode props, ProvisionContext ctx) {
String domainName = ctx.resolveOptional(props, "DomainName");
if (domainName == null || domainName.isBlank()) {
throw new IllegalArgumentException("AWS::CertificateManager::Certificate requires DomainName");
throw new AwsException("ValidationError", "AWS::CertificateManager::Certificate requires DomainName", 400);
}
List<String> sans = ctx.resolveStringList(props, "SubjectAlternativeNames");
String method = ctx.resolveOptional(props, "ValidationMethod");
ValidationMethod validationMethod = method == null ? ValidationMethod.DNS : ValidationMethod.valueOf(method);
KeyAlgorithm keyAlgorithm = KeyAlgorithm.fromAwsName(ctx.resolveOptional(props, "KeyAlgorithm"));
Map<String, String> tags = ctx.resolveTags(props, "Tags");
String export = optionValue(ctx, props, "CertificateExport", "DISABLED");
String transparencyLogging = optionValue(ctx, props, "CertificateTransparencyLoggingPreference", "ENABLED");
CertificateOptions options = new CertificateOptions(transparencyLogging, export);
// DomainName, SubjectAlternativeNames and KeyAlgorithm are createOnly in the schema: a change
// to any of them replaces the certificate, and there is no generic replacement flow, so the
// previous one is deleted here once the new one exists. Anything else updates in place.
// DomainName, SubjectAlternativeNames, KeyAlgorithm and CertificateExport are createOnly in
// the schema: a change to any of them replaces the certificate, and there is no generic
// replacement flow, so the previous one is deleted here once the new one exists. Anything
// else updates in place.
Certificate existing = ctx.isUpdate() ? findExisting(ctx.priorPhysicalId(), ctx.region()) : null;
String arn;
if (existing != null && sameCreateOnlyProperties(existing, domainName, sans, keyAlgorithm)) {
if (existing != null && sameCreateOnlyProperties(existing, domainName, sans, keyAlgorithm, export)) {
arn = existing.getArn();
reconcileTags(arn, tags, ctx.region());
reconcileTransparencyLogging(existing, transparencyLogging, ctx.region());
} else {
arn = acmService.requestCertificate(domainName, sans, validationMethod, null,
keyAlgorithm, null, null, tags, ctx.region()).getArn();
keyAlgorithm, null, options, tags, ctx.region()).getArn();
if (existing != null) {
deletePriorOrUnwind(r, existing.getArn(), arn, ctx.region());
}
@@ -106,7 +118,8 @@ public class AcmCfnProvisioner implements CfnResourceProvisioner {
}
private static boolean sameCreateOnlyProperties(Certificate existing, String domainName,
List<String> sans, KeyAlgorithm keyAlgorithm) {
List<String> sans, KeyAlgorithm keyAlgorithm,
String export) {
Set<String> desiredNames = new LinkedHashSet<>();
desiredNames.add(domainName);
desiredNames.addAll(sans);
@@ -115,7 +128,40 @@ public class AcmCfnProvisioner implements CfnResourceProvisioner {
: new LinkedHashSet<>(existing.getSubjectAlternativeNames());
return domainName.equals(existing.getDomainName())
&& desiredNames.equals(storedNames)
&& keyAlgorithm == existing.getKeyAlgorithm();
&& keyAlgorithm == existing.getKeyAlgorithm()
&& export.equals(storedOptions(existing).export());
}
/**
* An ENABLED or DISABLED option, defaulted the way CloudFormation documents when absent. Blank
* counts as absent: the engine resolves {@code AWS::NoValue} to an empty string.
*/
private static String optionValue(ProvisionContext ctx, JsonNode props, String name, String defaultValue) {
String value = ctx.resolveOptional(props, name);
if (value == null || value.isBlank()) {
return defaultValue;
}
if (!OPTION_VALUES.contains(value)) {
throw new AwsException("ValidationError", "AWS::CertificateManager::Certificate " + name
+ " must be ENABLED or DISABLED, not " + value, 400);
}
return value;
}
/** An imported certificate carries no options; the service reads that as the defaults, so this does too. */
private static CertificateOptions storedOptions(Certificate existing) {
return existing.getCertOptions() != null ? existing.getCertOptions() : CertificateOptions.defaultOptions();
}
/**
* Runs after the tag reconcile, which carries the validation: this call can only fail when the
* certificate is gone, so a rejected tag never leaves the option changed on a rolled-back update.
* Export is never sent here: ACM refuses to change it, so a changed value replaces the certificate.
*/
private void reconcileTransparencyLogging(Certificate existing, String desired, String region) {
if (!desired.equals(storedOptions(existing).certificateTransparencyLoggingPreference())) {
acmService.updateCertificateOptions(existing.getArn(), new CertificateOptions(desired, null), region);
}
}
private void reconcileTags(String arn, Map<String, String> desired, String region) {