fix(elbv2): reject gateway listener protocols (#6465)

* fix: reject explicit protocols on gateway load balancer listeners

Validate gateway listener Protocol before create publication or modify mutation. Preserve omitted-field updates and cover Query rejection and state preservation.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* test(elbv2): omit protocol in gateway listener fixture

Keep the successful gateway listener lifecycle fixture aligned with the accepted Protocol prohibition. Assert protocol preservation after an action-only update without introducing a default-protocol contract.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

* fix(elbv2): preserve gateway listener defaults

Default gateway listener responses to GENEVE and keep omitted protocol and port unset through CloudFormation create and update. Preserve application and network listener defaults. Cover direct Query and stack lifecycle behavior.

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>

---------

Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Andre Kurait authored and GitHub committed 2026-10-24 22:03:48 -04:00
1 parent 87cd8ead73
commit 3d2e17bbbd
7 files changed
+182 -24

No files matched your search

@@ -305,14 +305,21 @@ public class ElbV2CfnProvisioner implements CfnResourceProvisioner {
*/
private void provisionListener(StackResource r, JsonNode props, ProvisionContext ctx) {
String lbArn = ctx.resolveOptional(props, "LoadBalancerArn");
String protocol = ctx.resolveOrDefault(props, "Protocol", "HTTP");
int port = parseInt(ctx.resolveOptional(props, "Port"), "Port", 80);
Listener prior = ctx.isUpdate() ? priorListener(ctx) : null;
String effectiveLbArn = lbArn != null ? lbArn : prior != null ? prior.getLoadBalancerArn() : null;
LoadBalancer lb = effectiveLbArn == null ? null
: elbV2Service.describeLoadBalancers(ctx.region(), List.of(effectiveLbArn),
null, null, null).getFirst();
boolean gateway = lb != null && "gateway".equals(lb.getType());
String protocol = gateway ? ctx.resolveOptional(props, "Protocol")
: ctx.resolveOrDefault(props, "Protocol", "HTTP");
Integer port = gateway ? optionalInt(props, ctx, "Port")
: Integer.valueOf(parseInt(ctx.resolveOptional(props, "Port"), "Port", 80));
String sslPolicy = ctx.resolveOptional(props, "SslPolicy");
List<String> certificates = parseCertificates(props, ctx);
List<Action> defaultActions = parseActions(props != null ? props.get("DefaultActions") : null, ctx);
Listener listener;
Listener prior = ctx.isUpdate() ? priorListener(ctx) : null;
if (prior != null && (lbArn == null || lbArn.equals(prior.getLoadBalancerArn()))) {
listener = elbV2Service.modifyListener(ctx.region(), ctx.priorPhysicalId(), protocol, port, sslPolicy,
certificates, defaultActions, null);
@@ -604,7 +604,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
List<Action> defaultActions, List<String> alpnPolicy,
Map<String, String> initialTags) {
validatePort(port, "port");
requireGatewayListenerPort(requireLoadBalancer(region, lbArn), port);
requireGatewayListenerSettings(requireLoadBalancer(region, lbArn), protocol, port);
Map<String, Listener> regionListeners = listeners.computeIfAbsent(region, k -> new ConcurrentHashMap<>());
@@ -632,7 +632,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
listener.setListenerArn(listenerArn);
listener.setLoadBalancerArn(lbArn);
listener.setPort(port);
listener.setProtocol(protocol != null ? protocol : "HTTP");
listener.setProtocol(protocol != null ? protocol : ("gateway".equals(lbType) ? "GENEVE" : "HTTP"));
listener.setSslPolicy(sslPolicy);
listener.setCertificates(certificates != null ? new ArrayList<>(certificates) : new ArrayList<>());
listener.setDefaultActions(defaultActions != null ? new ArrayList<>(defaultActions) : new ArrayList<>());
@@ -747,7 +747,7 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
while (true) {
Listener initial = requireListener(region, listenerArn);
LoadBalancer initialLb = requireLoadBalancer(region, initial.getLoadBalancerArn());
requireGatewayListenerPort(initialLb, port);
requireGatewayListenerSettings(initialLb, protocol, port);
ListenerState initialState = listenerState(initial, initialLb);
requireAvailableListenerPort(listeners.getOrDefault(region, Map.of()), initial.getLoadBalancerArn(),
listenerArn, port != null ? port : initialState.port());
@@ -1230,11 +1230,15 @@ public class ElbV2Service implements ResourceProvider, ServerCertificateReferenc
}
}
private static void requireGatewayListenerPort(LoadBalancer loadBalancer, Integer port) {
private static void requireGatewayListenerSettings(LoadBalancer loadBalancer, String protocol, Integer port) {
if (port != null && "gateway".equals(loadBalancer.getType())) {
throw new AwsException("InvalidConfigurationRequest",
"You can't specify a port for a Gateway Load Balancer.", 400);
}
if (protocol != null && "gateway".equals(loadBalancer.getType())) {
throw new AwsException("InvalidConfigurationRequest",
"You can't specify a protocol for a Gateway Load Balancer.", 400);
}
}
private void requireCompatibleListenerProtocol(String listenerArn, Integer port, String protocol) {