fix(ec2): keep Ipv6CidrBlock and IcmpTypeCode on network ACL entries (#6680)

This commit is contained in:
lex00 authored and GitHub committed 2026-10-26 23:24:00 -04:00
1 parent e8ef0b147e
commit 9e14ffe92a
8 files changed
+249 -8

No files matched your search

@@ -100,12 +100,16 @@ public class Ec2NetworkAclCfnProvisioner implements CfnResourceProvisioner {
String toValue = ctx.resolveOptional(portRange, "To");
Integer from = fromValue != null ? Integer.valueOf(fromValue) : null;
Integer to = toValue != null ? Integer.valueOf(toValue) : null;
JsonNode icmp = props != null && props.hasNonNull("Icmp") ? props.get("Icmp") : null;
String protocol = ctx.resolveOptional(props, "Protocol");
ec2Service.createNetworkAclEntry(ctx.region(), aclId, ruleNumber,
protocol != null ? protocol : "-1",
ctx.resolveOptional(props, "RuleAction"),
egress,
ctx.resolveOptional(props, "CidrBlock"),
ctx.resolveOptional(props, "Ipv6CidrBlock"),
ctx.resolveOptionalInt(icmp, "Type"),
ctx.resolveOptionalInt(icmp, "Code"),
// RuleNumber, Egress and NetworkAclId are the createOnly key, so re-provisioning
// the same key is an update. replace=false would raise NetworkAclEntryAlreadyExists
// on every stack update.
@@ -4356,6 +4356,8 @@ public class Ec2QueryHandler {
private Response handleNetworkAclEntry(MultivaluedMap<String, String> p, String region, String action) {
String fromStr = p.getFirst("PortRange.From");
String toStr = p.getFirst("PortRange.To");
String icmpType = p.getFirst("Icmp.Type");
String icmpCode = p.getFirst("Icmp.Code");
service.createNetworkAclEntry(region,
p.getFirst("NetworkAclId"),
Integer.parseInt(p.getFirst("RuleNumber")),
@@ -4363,6 +4365,9 @@ public class Ec2QueryHandler {
p.getFirst("RuleAction"),
Boolean.parseBoolean(p.getFirst("Egress")),
p.getFirst("CidrBlock"),
p.getFirst("Ipv6CidrBlock"),
icmpType != null ? Integer.valueOf(icmpType) : null,
icmpCode != null ? Integer.valueOf(icmpCode) : null,
fromStr != null ? Integer.valueOf(fromStr) : null,
toStr != null ? Integer.valueOf(toStr) : null,
"ReplaceNetworkAclEntry".equals(action));
@@ -5475,7 +5480,14 @@ public class Ec2QueryHandler {
.elem("protocol", e.getProtocol())
.elem("ruleAction", e.getRuleAction())
.elem("egress", String.valueOf(e.isEgress()))
.elem("cidrBlock", e.getCidrBlock());
.elem("cidrBlock", e.getCidrBlock())
.elem("ipv6CidrBlock", e.getIpv6CidrBlock());
if (e.getIcmpType() != null || e.getIcmpCode() != null) {
xml.start("icmpTypeCode")
.elem("code", e.getIcmpCode() != null ? String.valueOf(e.getIcmpCode()) : null)
.elem("type", e.getIcmpType() != null ? String.valueOf(e.getIcmpType()) : null)
.end("icmpTypeCode");
}
if (e.getPortRangeFrom() != null || e.getPortRangeTo() != null) {
xml.start("portRange")
.elem("from", String.valueOf(e.getPortRangeFrom()))
@@ -1659,7 +1659,8 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
public void createNetworkAclEntry(String region, String networkAclId, int ruleNumber, String protocol,
String ruleAction, boolean egress, String cidrBlock, Integer from, Integer to,
String ruleAction, boolean egress, String cidrBlock, String ipv6CidrBlock,
Integer icmpType, Integer icmpCode, Integer from, Integer to,
boolean replace) {
synchronized (lockFor(key(region, networkAclId))) {
NetworkAcl acl = getRequiredNetworkAcl(region, networkAclId);
@@ -1672,6 +1673,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
List<NetworkAclEntry> next = new ArrayList<>(acl.getEntries());
next.removeIf(e -> e.getRuleNumber() == ruleNumber && e.isEgress() == egress);
NetworkAclEntry entry = naclEntry(ruleNumber, protocol, ruleAction, egress, cidrBlock);
entry.setIpv6CidrBlock(ipv6CidrBlock);
// The model documents an ICMP type and code as having no effect on any other protocol,
// so only ICMP and ICMPv6 entries keep one for DescribeNetworkAcls to return.
if (isIcmpProtocol(protocol)) {
entry.setIcmpType(icmpType);
entry.setIcmpCode(icmpCode);
}
entry.setPortRangeFrom(from);
entry.setPortRangeTo(to);
next.add(entry);
@@ -1680,6 +1688,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
}
}
private static boolean isIcmpProtocol(String protocol) {
return protocol != null && switch (protocol.toLowerCase(Locale.ROOT)) {
case "1", "58", "icmp", "icmpv6" -> true;
default -> false;
};
}
public void deleteNetworkAclEntry(String region, String networkAclId, int ruleNumber, boolean egress) {
synchronized (lockFor(key(region, networkAclId))) {
NetworkAcl acl = getRequiredNetworkAcl(region, networkAclId);
@@ -12,6 +12,9 @@ public class NetworkAclEntry {
private String ruleAction;
private boolean egress;
private String cidrBlock;
private String ipv6CidrBlock;
private Integer icmpType;
private Integer icmpCode;
private Integer portRangeFrom;
private Integer portRangeTo;
@@ -32,6 +35,15 @@ public class NetworkAclEntry {
public String getCidrBlock() { return cidrBlock; }
public void setCidrBlock(String cidrBlock) { this.cidrBlock = cidrBlock; }
public String getIpv6CidrBlock() { return ipv6CidrBlock; }
public void setIpv6CidrBlock(String ipv6CidrBlock) { this.ipv6CidrBlock = ipv6CidrBlock; }
public Integer getIcmpType() { return icmpType; }
public void setIcmpType(Integer icmpType) { this.icmpType = icmpType; }
public Integer getIcmpCode() { return icmpCode; }
public void setIcmpCode(Integer icmpCode) { this.icmpCode = icmpCode; }
public Integer getPortRangeFrom() { return portRangeFrom; }
public void setPortRangeFrom(Integer portRangeFrom) { this.portRangeFrom = portRangeFrom; }