mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elbv2): dispatch a shared listener port by the hostnames rules declare (#4207)
* fix(elbv2): dispatch a shared listener port by the hostnames rules declare Two load balancers with a listener on the same port both answered 502. Floci serves every load balancer from one socket per port, and listener selection keyed only on the load balancer's own DNS name, so a request carrying any other Host header matched neither key. With one load balancer a size-1 fallback covered that up; adding a second removed the fallback and silently broke both. Listener selection now also consults the host-header conditions the listener's rules already declare. A load balancer that names the hostname it serves, which is the configuration AWS needs anyway, claims that hostname here too. The DNS-name match and the single-listener fallback are unchanged and still take precedence in that order. A port taken by a second load balancer now logs a warning naming both, since nothing else reported the collision: the targets behind them stay healthy and no API call fails. Real AWS has no load-balancer selection step, because every load balancer has its own DNS name and addresses; host-header rules only choose a rule inside one listener. Selecting a listener by Host header is a Floci deviation forced by the shared socket, and is documented as one. * test(elbv2): pin the AWS host-header matching semantics selection relies on The AWS docs state that a hostname is not case-sensitive, that * matches 0 or more characters and ? exactly 1, and that the rule *.example.com matches test.example.com but not example.com. Listener selection now depends on that matching, so cover it directly: a case-shifted Host still resolves, and a wildcard rule does not let its listener claim the bare domain. Also record that HostHeaderConfig.RegexValues is unsupported, so a load balancer naming itself only through a regex cannot be selected this way.
This commit is contained in:
1 parent
51b6485173
commit
8d9ae9554d
3 files changed
+207
-2
No files matched your search
+82
@@ -3,11 +3,14 @@ package io.github.hectorvent.floci.services.elbv2;
|
||||
import io.github.hectorvent.floci.testing.RealElbV2DataPlaneProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -27,6 +30,8 @@ class ElbV2SamePortHostDispatchIntegrationTest {
|
||||
private static String secondLbArn;
|
||||
private static String secondDnsName;
|
||||
private static String secondListenerArn;
|
||||
private static String firstRuleArn;
|
||||
private static String secondRuleArn;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@@ -107,15 +112,92 @@ class ElbV2SamePortHostDispatchIntegrationTest {
|
||||
assertNoListenerForHost("unknown.example.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void samePortListenerClaimsAHostItsRulesDeclare() {
|
||||
secondRuleArn = createHostHeaderRule(secondListenerArn, 10,
|
||||
List.of("app.example.test", "*.wild.example.test"), "second-rule");
|
||||
|
||||
assertHostResponse("app.example.test", "second-rule");
|
||||
assertHostResponse("api.wild.example.test", "second-rule");
|
||||
assertHostResponse("APP.EXAMPLE.TEST", "second-rule");
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS states that the rule {@code *.example.com} matches {@code test.example.com} but not
|
||||
* {@code example.com}, so a wildcard must not let a listener claim the bare domain either.
|
||||
*/
|
||||
@Test
|
||||
@Order(7)
|
||||
void aWildcardRuleDoesNotClaimTheBareDomain() {
|
||||
assertNoListenerForHost("wild.example.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void aDeclaredHostDoesNotDisplaceTheLoadBalancerDnsName() {
|
||||
assertHostResponse(firstDnsName, "first");
|
||||
assertHostResponse(secondDnsName, "second");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void aHostBothListenersDeclareStaysUnclaimed() {
|
||||
firstRuleArn = createHostHeaderRule(firstListenerArn, 10,
|
||||
List.of("app.example.test"), "first-rule");
|
||||
|
||||
assertNoListenerForHost("app.example.test");
|
||||
assertHostResponse("api.wild.example.test", "second-rule");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(Integer.MAX_VALUE)
|
||||
void cleanup() {
|
||||
deleteRule(firstRuleArn);
|
||||
deleteRule(secondRuleArn);
|
||||
deleteListener(firstListenerArn);
|
||||
deleteListener(secondListenerArn);
|
||||
deleteLoadBalancer(firstLbArn);
|
||||
deleteLoadBalancer(secondLbArn);
|
||||
}
|
||||
|
||||
private static String createHostHeaderRule(String listenerArn, int priority, List<String> hosts, String body) {
|
||||
RequestSpecification request = given()
|
||||
.formParam("Action", "CreateRule")
|
||||
.formParam("ListenerArn", listenerArn)
|
||||
.formParam("Priority", String.valueOf(priority))
|
||||
.formParam("Conditions.member.1.Field", "host-header")
|
||||
.formParam("Actions.member.1.Type", "fixed-response")
|
||||
.formParam("Actions.member.1.FixedResponseConfig.StatusCode", "200")
|
||||
.formParam("Actions.member.1.FixedResponseConfig.ContentType", "text/plain")
|
||||
.formParam("Actions.member.1.FixedResponseConfig.MessageBody", body)
|
||||
.header("Authorization", AUTH);
|
||||
for (int i = 0; i < hosts.size(); i++) {
|
||||
request = request.formParam(
|
||||
"Conditions.member.1.HostHeaderConfig.Values.member." + (i + 1), hosts.get(i));
|
||||
}
|
||||
return request
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("CreateRuleResponse.CreateRuleResult.Rules.member.RuleArn");
|
||||
}
|
||||
|
||||
private static void deleteRule(String ruleArn) {
|
||||
if (ruleArn != null) {
|
||||
given()
|
||||
.formParam("Action", "DeleteRule")
|
||||
.formParam("RuleArn", ruleArn)
|
||||
.header("Authorization", AUTH)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(anyOf(equalTo(200), equalTo(204)));
|
||||
}
|
||||
}
|
||||
|
||||
private static String createFixedResponseListener(String lbArn, String body) {
|
||||
return given()
|
||||
.formParam("Action", "CreateListener")
|
||||
|
||||
Reference in new issue
Block a user