fix(cloudfront): echo TrustedSigners in cache behaviors so the AWS provider does not segfault (#3015)

Creating an aws_cloudfront_distribution against floci crashes the Terraform/
pulumi AWS provider on read-back: DefaultCacheBehavior (and CacheBehavior) omit
the TrustedSigners object, but the provider does len(dcb.TrustedSigners.Items)
with no nil guard (flattenDefaultCacheBehavior), so an omitted object is a nil
pointer dereference (SIGSEGV) that kills the apply and orphans the distribution.

Floci models only the modern TrustedKeyGroups, but real AWS always echoes a
TrustedSigners object even when unused ({Enabled:false, Quantity:0}). Emit that
disabled form in both cache-behavior writers, next to TrustedKeyGroups.

Refs #2767 (the TrustedSigners crash; the ForwardedValues/MinTTL and
AllowedMethods.CachedMethods fidelity gaps listed there are left as follow-ups).

Adds a regression test asserting getDistribution's DefaultCacheBehavior echoes a
disabled TrustedSigners; it fails (object absent) before the fix.
This commit is contained in:
Matan Baruch authored and GitHub committed 2026-09-06 14:26:43 -05:00
1 parent 7b5c6e272d
commit 75e93e5e77
2 files changed
+47

No files matched your search

@@ -1968,6 +1968,7 @@ public class CloudFrontController {
.elem("ResponseHeadersPolicyId", dcb.getResponseHeadersPolicyId())
.elem("Compress", dcb.isCompress());
xml.raw(xmlTrustedSigners());
xml.raw(xmlTrustedKeyGroups(
dcb.isTrustedKeyGroupsEnabled(), dcb.getTrustedKeyGroups()));
@@ -1997,6 +1998,7 @@ public class CloudFrontController {
.elem("ResponseHeadersPolicyId", cb.getResponseHeadersPolicyId())
.elem("Compress", cb.isCompress());
xml.raw(xmlTrustedSigners());
xml.raw(xmlTrustedKeyGroups(
cb.isTrustedKeyGroupsEnabled(), cb.getTrustedKeyGroups()));
@@ -2068,6 +2070,18 @@ public class CloudFrontController {
return xml.end("TrustedKeyGroups").build();
}
// AWS always echoes a (usually empty) TrustedSigners object in every cache behavior. Floci models
// only the modern TrustedKeyGroups, but the Terraform AWS provider reads TrustedSigners.Items with
// no nil guard, so an omitted object segfaults it on read-back. Emit the disabled form AWS returns.
private String xmlTrustedSigners() {
return new XmlBuilder()
.start("TrustedSigners")
.elem("Enabled", false)
.elem("Quantity", 0)
.end("TrustedSigners")
.build();
}
private String xmlActiveTrustedKeyGroups(DistributionConfig config) {
List<KeyGroup> groups = service.activeTrustedKeyGroups(config);
XmlBuilder xml = new XmlBuilder()