fix(cloudfront): preserve distribution WebACLId (#8707)

CloudFront now reads WebACLId, the member name the CloudFront API uses, on CreateDistribution and UpdateDistribution, and writes it under that name in GetDistributionConfig, GetDistribution and ListDistributions, where the summary now carries the stored value instead of an empty one. An empty WebACLId clears the association, and the earlier WebAclId spelling is still accepted on input when WebACLId is absent.

Part of #8645
This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-11-17 05:21:56 -04:00
1 parent 8b2d21498b
commit 3c54534a3d
2 files changed
+132 -8

No files matched your search

@@ -13,6 +13,7 @@ import org.jboss.logging.Logger;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -1900,7 +1901,7 @@ public class CloudFrontController {
.elem("HttpVersion", cfg.getHttpVersion() != null ? cfg.getHttpVersion() : "http2")
.elem("PriceClass", cfg.getPriceClass() != null ? cfg.getPriceClass() : "PriceClass_All")
.elem("IsIPV6Enabled", cfg.isIPV6Enabled())
.elem("WebAclId", cfg.getWebAclId() != null ? cfg.getWebAclId() : "");
.elem("WebACLId", cfg.getWebAclId() != null ? cfg.getWebAclId() : "");
List<Origin> origins = cfg.getOrigins();
xml.raw(xmlQuantityItems("Origins", "Origin", origins != null ? origins.size() : 0,
@@ -2367,6 +2368,7 @@ public class CloudFrontController {
}
private String xmlDistributionSummary(Distribution d) {
DistributionConfig cfg = d.getConfig();
XmlBuilder xml = new XmlBuilder()
.start("DistributionSummary")
.elem("Id", d.getId())
@@ -2383,9 +2385,9 @@ public class CloudFrontController {
.elem("PriceClass", d.getConfig() != null && d.getConfig().getPriceClass() != null
? d.getConfig().getPriceClass() : "PriceClass_All")
.elem("IsIPV6Enabled", d.getConfig() != null && d.getConfig().isIPV6Enabled())
.elem("WebAclId", "");
.elem("WebACLId", cfg != null && cfg.getWebAclId() != null
? cfg.getWebAclId() : "");
DistributionConfig cfg = d.getConfig();
List<Origin> origins = cfg != null ? cfg.getOrigins() : null;
xml.raw(xmlQuantityItems("Origins", "Origin",
origins != null ? origins.size() : 0,
@@ -2665,7 +2667,8 @@ public class CloudFrontController {
values.getOrDefault("PriceClass", "PriceClass_All"));
cfg.setIPV6Enabled("true".equalsIgnoreCase(
values.getOrDefault("IsIPV6Enabled", "true")));
cfg.setWebAclId(values.get("WebAclId"));
cfg.setWebAclId(values.containsKey("WebACLId")
? values.get("WebACLId") : values.get("WebAclId"));
cfg.setContinuousDeploymentPolicyId(
values.get("ContinuousDeploymentPolicyId"));
cfg.setStaging("true".equalsIgnoreCase(
@@ -2744,6 +2747,7 @@ public class CloudFrontController {
"HttpVersion",
"PriceClass",
"IsIPV6Enabled",
"WebACLId",
"WebAclId",
"ContinuousDeploymentPolicyId",
"Staging" -> true;
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@@ -36,6 +37,8 @@ class CloudFrontDistributionConfigMembersTest {
"//*[local-name()='Logging']/*[local-name()='Bucket']";
private static final String LOGGING_PREFIX =
"//*[local-name()='Logging']/*[local-name()='Prefix']";
private static final String WEB_ACL_ID =
"//*[local-name()='WebACLId']";
private final CloudFrontService cloudFrontService;
@@ -141,10 +144,10 @@ class CloudFrontDistributionConfigMembersTest {
/**
* A DistributionConfig request body, which is what an SDK or the Terraform provider
* actually sends. {@code loggingBlock} goes in verbatim so a caller that omits Logging
* and a caller that supplies it share one shape.
* actually sends. {@code additionalMembers} goes in verbatim so optional config
* members can be tested through the same request shape.
*/
private static String distributionConfigBody(String originId, String loggingBlock) {
private static String distributionConfigBody(String originId, String additionalMembers) {
return """
<DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
<CallerReference>%s</CallerReference>
@@ -161,7 +164,7 @@ class CloudFrontDistributionConfigMembersTest {
<ViewerProtocolPolicy>allow-all</ViewerProtocolPolicy>
</DefaultCacheBehavior>
</DistributionConfig>
""".formatted(originId, loggingBlock, originId, originId);
""".formatted(originId, additionalMembers, originId, originId);
}
/** POSTs a config body and returns the id of the distribution it created. */
@@ -248,4 +251,121 @@ class CloudFrontDistributionConfigMembersTest {
.body(hasXPath(LOGGING_BUCKET, equalTo("update-logs.s3.amazonaws.com")))
.body(hasXPath(LOGGING_PREFIX, equalTo("update/")));
}
@Test
void webAclIdRoundTripsThroughCreateUpdateAndDistributionReads() {
String originId = "origin-web-acl-" + UUID.randomUUID();
String firstAcl = "arn:aws:wafv2:us-east-1:000000000000:global/webacl/edge/first";
String secondAcl = "arn:aws:wafv2:us-east-1:000000000000:global/webacl/edge/second";
String created = given()
.contentType(ContentType.XML)
.body(distributionConfigBody(originId,
"<WebACLId>" + firstAcl + "</WebACLId>"))
.when()
.post(DISTRIBUTIONS)
.then()
.statusCode(201)
.body(hasXPath(WEB_ACL_ID, equalTo(firstAcl)))
.extract().asString();
String id = XmlParser.extractFirst(created, "Id", null);
String summaryAcl = "//*[local-name()='DistributionSummary']"
+ "[*[local-name()='Id' and text()='" + id + "']]"
+ "/*[local-name()='WebACLId']";
given().when().get(API + id + "/config").then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo(firstAcl)));
given().when().get(API + id).then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo(firstAcl)));
given().when().get(DISTRIBUTIONS).then()
.statusCode(200)
.body(hasXPath(summaryAcl, equalTo(firstAcl)));
String etag = given().when().get(API + id + "/config").then()
.statusCode(200).extract().header("ETag");
given().contentType(ContentType.XML).header("If-Match", etag)
.body(distributionConfigBody(originId,
"<WebACLId>" + secondAcl + "</WebACLId>"))
.when()
.put(API + id + "/config")
.then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo(secondAcl)));
given().when().get(DISTRIBUTIONS).then()
.statusCode(200)
.body(hasXPath(summaryAcl, equalTo(secondAcl)));
etag = given().when().get(API + id + "/config").then()
.statusCode(200).extract().header("ETag");
given().contentType(ContentType.XML).header("If-Match", etag)
.body(distributionConfigBody(originId, "<WebACLId></WebACLId>"))
.when()
.put(API + id + "/config")
.then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
given().when().get(API + id + "/config").then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
given().when().get(API + id).then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
given().when().get(DISTRIBUTIONS).then()
.statusCode(200)
.body(hasXPath(summaryAcl, equalTo("")));
}
@Test
void webAclIdDefaultsToEmptyWhenOmitted() {
String id = postDistribution(distributionConfigBody(
"origin-no-web-acl-" + UUID.randomUUID(), ""));
String summaryAcl = "//*[local-name()='DistributionSummary']"
+ "[*[local-name()='Id' and text()='" + id + "']]"
+ "/*[local-name()='WebACLId']";
given().when().get(API + id + "/config").then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
given().when().get(DISTRIBUTIONS).then()
.statusCode(200)
.body(hasXPath(summaryAcl, equalTo("")));
}
@Test
void legacyWebAclIdUpdateRetainsAssociationAndCanonicalValueTakesPrecedence() {
String originId = "origin-legacy-web-acl-" + UUID.randomUUID();
String firstAcl = "arn:aws:wafv2:us-east-1:000000000000:global/webacl/edge/first";
String legacyAcl = "arn:aws:wafv2:us-east-1:000000000000:global/webacl/edge/legacy";
String id = postDistribution(distributionConfigBody(originId,
"<WebACLId>" + firstAcl + "</WebACLId>"));
String etag = given().when().get(API + id + "/config").then()
.statusCode(200).extract().header("ETag");
given().contentType(ContentType.XML).header("If-Match", etag)
.body(distributionConfigBody(originId,
"<WebAclId>" + legacyAcl + "</WebAclId>"))
.when()
.put(API + id + "/config")
.then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo(legacyAcl)));
given().when().get(API + id + "/config").then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo(legacyAcl)));
etag = given().when().get(API + id + "/config").then()
.statusCode(200).extract().header("ETag");
given().contentType(ContentType.XML).header("If-Match", etag)
.body(distributionConfigBody(originId,
"<WebACLId></WebACLId><WebAclId>" + legacyAcl + "</WebAclId>"))
.when()
.put(API + id + "/config")
.then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
given().when().get(API + id + "/config").then()
.statusCode(200)
.body(hasXPath(WEB_ACL_ID, equalTo("")));
}
}