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

@@ -15,6 +15,7 @@ import io.github.hectorvent.floci.services.elbv2.model.LoadBalancer;
import io.github.hectorvent.floci.services.elbv2.model.Rule;
import io.github.hectorvent.floci.services.elbv2.model.RuleCondition;
import io.github.hectorvent.floci.services.elbv2.model.TargetGroup;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -68,6 +69,61 @@ class ElbV2CfnProvisionerTest {
private final ElbV2CfnProvisioner provisioner = new ElbV2CfnProvisioner(elb);
private final ObjectMapper mapper = new ObjectMapper();
@BeforeEach
void defaultListenerLoadBalancer() {
LoadBalancer lb = new LoadBalancer();
lb.setType("application");
when(elb.describeLoadBalancers(eq(REGION), anyList(), isNull(), isNull(), isNull()))
.thenReturn(List.of(lb));
}
@ParameterizedTest
@ValueSource(booleans = {false, true})
void gatewayListenerLeavesProtocolAndPortUnset(boolean update) {
LoadBalancer lb = new LoadBalancer();
lb.setType("gateway");
when(elb.describeLoadBalancers(REGION, List.of(LB_ARN), null, null, null)).thenReturn(List.of(lb));
if (update) {
when(elb.describeListeners(REGION, null, List.of(LISTENER_ARN))).thenReturn(List.of(listener(LB_ARN)));
when(elb.modifyListener(eq(REGION), eq(LISTENER_ARN), isNull(), isNull(), isNull(),
anyList(), anyList(), isNull())).thenReturn(listener(LB_ARN));
} else {
when(elb.createListener(eq(REGION), eq(LB_ARN), isNull(), isNull(), isNull(),
anyList(), anyList(), isNull(), eq(Map.of()))).thenReturn(listener(LB_ARN));
}
StackResource resource = resource("AWS::ElasticLoadBalancingV2::Listener", "Listener");
provisioner.provision(resource, mapper.createObjectNode().put("LoadBalancerArn", LB_ARN),
ctx(update ? LISTENER_ARN : null));
assertEquals(LISTENER_ARN, resource.getPhysicalId());
assertEquals(LISTENER_ARN, resource.getAttributes().get("ListenerArn"));
if (update) {
verify(elb).modifyListener(eq(REGION), eq(LISTENER_ARN), isNull(), isNull(), isNull(),
anyList(), anyList(), isNull());
} else {
verify(elb).createListener(eq(REGION), eq(LB_ARN), isNull(), isNull(), isNull(),
anyList(), anyList(), isNull(), eq(Map.of()));
}
}
@ParameterizedTest
@ValueSource(strings = {"HTTP", ""})
void gatewayListenerPassesExplicitProtocolToService(String protocol) {
LoadBalancer lb = new LoadBalancer();
lb.setType("gateway");
when(elb.describeLoadBalancers(REGION, List.of(LB_ARN), null, null, null)).thenReturn(List.of(lb));
when(elb.createListener(eq(REGION), eq(LB_ARN), eq(protocol), isNull(), isNull(),
anyList(), anyList(), isNull(), eq(Map.of()))).thenReturn(listener(LB_ARN));
StackResource resource = resource("AWS::ElasticLoadBalancingV2::Listener", "Listener");
provisioner.provision(resource, mapper.createObjectNode().put("LoadBalancerArn", LB_ARN)
.put("Protocol", protocol), ctx());
verify(elb).createListener(eq(REGION), eq(LB_ARN), eq(protocol), isNull(), isNull(),
anyList(), anyList(), isNull(), eq(Map.of()));
}
private ProvisionContext ctx() {
return ctx(null);
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elbv2;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
@@ -161,12 +162,14 @@ class ElbV2DefaultAttributesIntegrationTest {
void aGatewayListenerRetainsItsControlPlaneWithoutAPort() {
String arn = createLoadBalancer("attrs-gwlb-listener", "gateway", "10.120.");
try {
String listener = given().header("Authorization", AUTH).formParam("Action", "CreateListener")
.formParam("LoadBalancerArn", arn).formParam("Protocol", "GENEVE")
Response created = given().header("Authorization", AUTH).formParam("Action", "CreateListener")
.formParam("LoadBalancerArn", arn)
.formParam("DefaultActions.member.1.Type", "fixed-response")
.formParam("DefaultActions.member.1.FixedResponseConfig.StatusCode", "200")
.when().post("/").then().statusCode(200).extract()
.path("CreateListenerResponse.CreateListenerResult.Listeners.member.ListenerArn");
.response();
String listener = created.path("CreateListenerResponse.CreateListenerResult.Listeners.member.ListenerArn");
assertEquals("GENEVE", created.path("CreateListenerResponse.CreateListenerResult.Listeners.member.Protocol"));
given().header("Authorization", AUTH).formParam("Action", "ModifyListener")
.formParam("ListenerArn", listener)
.formParam("DefaultActions.member.1.Type", "fixed-response")
@@ -186,6 +189,55 @@ class ElbV2DefaultAttributesIntegrationTest {
}
}
@Test
void aGatewayListenerStackPreservesOmittedSettingsOnUpdate() {
String arn = createLoadBalancer("attrs-gwlb-stack", "gateway", "10.121.");
String stack = "gateway-listener-settings";
String template = """
{"Resources":{"Listener":{"Type":"AWS::ElasticLoadBalancingV2::Listener",
"Properties":{"LoadBalancerArn":"%s","DefaultActions":[{"Type":"fixed-response",
"FixedResponseConfig":{"StatusCode":"%s"}}]}}}}
""";
try {
given().formParam("Action", "CreateStack").formParam("StackName", stack)
.formParam("TemplateBody", template.formatted(arn, "200"))
.when().post("/").then().statusCode(200);
given().formParam("Action", "DescribeStacks").formParam("StackName", stack)
.when().post("/").then().statusCode(200)
.body("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus", equalTo("CREATE_COMPLETE"));
String listener = given().header("Authorization", AUTH).formParam("Action", "DescribeListeners")
.formParam("LoadBalancerArn", arn).when().post("/").then().statusCode(200)
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Protocol", equalTo("GENEVE"))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Port.text()", equalTo(""))
.extract().path("DescribeListenersResponse.DescribeListenersResult.Listeners.member.ListenerArn");
given().formParam("Action", "UpdateStack").formParam("StackName", stack)
.formParam("TemplateBody", template.formatted(arn, "201"))
.when().post("/").then().statusCode(200);
given().formParam("Action", "DescribeStacks").formParam("StackName", stack)
.when().post("/").then().statusCode(200)
.body("DescribeStacksResponse.DescribeStacksResult.Stacks.member.StackStatus", equalTo("UPDATE_COMPLETE"));
given().header("Authorization", AUTH).formParam("Action", "DescribeListeners")
.formParam("LoadBalancerArn", arn).when().post("/").then().statusCode(200)
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.ListenerArn", equalTo(listener))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Protocol", equalTo("GENEVE"))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Port.text()", equalTo(""))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.DefaultActions.member.FixedResponseConfig.StatusCode",
equalTo("201"));
} finally {
try {
given().formParam("Action", "DeleteStack").formParam("StackName", stack)
.when().post("/").then().statusCode(200);
given().header("Authorization", AUTH).formParam("Action", "DescribeListeners")
.formParam("LoadBalancerArn", arn).when().post("/").then().statusCode(200)
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.size()", equalTo(0));
} finally {
given().header("Authorization", AUTH).formParam("Action", "DeleteLoadBalancer")
.formParam("LoadBalancerArn", arn).when().post("/").then().statusCode(200);
}
}
}
@Test
void aModifiedAttributeWinsOverItsDefaultAndTheRestStillReport() {
String arn = createLoadBalancer("attrs-modified", "application", "10.99.");
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.elbv2;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -71,8 +72,9 @@ class ElbV2IntegrationTest {
+ "' at 'port' failed to satisfy constraint: Member must have value " + constraint));
}
@Test
void gatewayListenerPortRejectionsPreservePortlessListener() {
@ParameterizedTest
@CsvSource({"Port,6081", "Protocol,GENEVE", "Protocol,TCP"})
void gatewayListenerRejectionsPreservePortlessListener(String field, String value) {
String gatewayArn = given().header("Authorization", AUTH)
.formParam("Action", "CreateLoadBalancer")
.formParam("Name", "gateway-listener-port")
@@ -83,32 +85,32 @@ class ElbV2IntegrationTest {
try {
given().header("Authorization", AUTH)
.formParam("Action", "CreateListener").formParam("LoadBalancerArn", gatewayArn)
.formParam("Protocol", "GENEVE").formParam("Port", 6081)
.formParam(field, value)
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidConfigurationRequest"));
given().header("Authorization", AUTH)
.formParam("Action", "DescribeListeners").formParam("LoadBalancerArn", gatewayArn)
.when().post("/").then().statusCode(200)
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.size()", equalTo(0));
String gatewayListener = given().header("Authorization", AUTH)
Response created = given().header("Authorization", AUTH)
.formParam("Action", "CreateListener").formParam("LoadBalancerArn", gatewayArn)
.formParam("Protocol", "GENEVE")
.when().post("/").then().statusCode(200)
.extract().path("CreateListenerResponse.CreateListenerResult.Listeners.member.ListenerArn");
.when().post("/").then().statusCode(200).extract().response();
String gatewayListener = created.path("CreateListenerResponse.CreateListenerResult.Listeners.member.ListenerArn");
String originalProtocol = created.path("CreateListenerResponse.CreateListenerResult.Listeners.member.Protocol");
given().header("Authorization", AUTH)
.formParam("Action", "ModifyListener").formParam("ListenerArn", gatewayListener)
.formParam("Protocol", "TCP").formParam("Port", 6081)
.formParam(field, value)
.when().post("/").then().statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidConfigurationRequest"));
given().header("Authorization", AUTH)
.formParam("Action", "DescribeListeners").formParam("ListenerArns.member.1", gatewayListener)
.when().post("/").then().statusCode(200)
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Protocol", equalTo("GENEVE"))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Protocol", equalTo(originalProtocol))
.body("DescribeListenersResponse.DescribeListenersResult.Listeners.member.Port.size()", equalTo(0));
given().header("Authorization", AUTH)
.formParam("Action", "ModifyListener").formParam("ListenerArn", gatewayListener)
.when().post("/").then().statusCode(200)
.body("ModifyListenerResponse.ModifyListenerResult.Listeners.member.Protocol", equalTo("GENEVE"))
.body("ModifyListenerResponse.ModifyListenerResult.Listeners.member.Protocol", equalTo(originalProtocol))
.body("ModifyListenerResponse.ModifyListenerResult.Listeners.member.Port.size()", equalTo(0));
} finally {
given().header("Authorization", AUTH)
@@ -606,14 +606,49 @@ class ElbV2ServiceTest {
assertTrue(service.describeListeners(REGION, lbArn, null).isEmpty());
verifyNoInteractions(dataPlane);
Listener listener = service.createListener(REGION, lbArn, "GENEVE", null, null,
Listener listener = service.createListener(REGION, lbArn, null, null, null,
List.of(), List.of(), List.of(), Map.of());
String originalProtocol = listener.getProtocol();
clearInvocations(dataPlane);
AwsException modifyError = assertThrows(AwsException.class, () -> service.modifyListener(
REGION, listener.getListenerArn(), "TCP", port, null, null, null, null));
assertEquals("InvalidConfigurationRequest", modifyError.getErrorCode());
assertNull(listener.getPort());
assertEquals("GENEVE", listener.getProtocol());
assertEquals(originalProtocol, listener.getProtocol());
verifyNoInteractions(dataPlane);
}
@ParameterizedTest
@ValueSource(strings = {"GENEVE", "TCP", ""})
void gatewayListenerRejectsExplicitProtocolWithoutPublication(String protocol) {
String lbArn = service.createLoadBalancer(REGION, "gateway-protocol", "internal", "gateway", "ipv4",
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
clearInvocations(dataPlane);
AwsException error = assertThrows(AwsException.class, () -> service.createListener(
REGION, lbArn, protocol, null, null, List.of(), List.of(), List.of(), Map.of()));
assertEquals("InvalidConfigurationRequest", error.getErrorCode());
assertTrue(service.describeListeners(REGION, lbArn, null).isEmpty());
verifyNoInteractions(dataPlane);
}
@ParameterizedTest
@ValueSource(strings = {"GENEVE", "TCP", ""})
void gatewayListenerRejectsProtocolUpdateWithoutMutation(String protocol) {
String lbArn = service.createLoadBalancer(REGION, "gateway-protocol", "internal", "gateway", "ipv4",
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
Listener listener = service.createListener(REGION, lbArn, null, null, null,
List.of(), List.of(), List.of(), Map.of());
String originalProtocol = listener.getProtocol();
clearInvocations(dataPlane);
AwsException error = assertThrows(AwsException.class, () -> service.modifyListener(
REGION, listener.getListenerArn(), protocol, null, null, null, null, null));
assertEquals("InvalidConfigurationRequest", error.getErrorCode());
assertEquals(originalProtocol, listener.getProtocol());
assertNull(listener.getPort());
verifyNoInteractions(dataPlane);
}
@@ -623,8 +658,9 @@ class ElbV2ServiceTest {
ALB_SUBNETS, List.of(), Map.of()).getLoadBalancerArn();
String oldTarget = createTargetGroup("gateway-old");
String newTarget = createTargetGroup("gateway-new");
Listener listener = service.createListener(REGION, lbArn, "GENEVE", null, null,
Listener listener = service.createListener(REGION, lbArn, null, null, null,
List.of(), List.of(forwardAction(oldTarget)), List.of(), Map.of());
assertEquals("GENEVE", listener.getProtocol());
service.modifyListener(REGION, listener.getListenerArn(), null, null, null, null,
List.of(forwardAction(newTarget)), null);