-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong route for multiple matching host glob patterns #506
Comments
IIUC fabio should match the routes from the most specific to the most generic one. So, in this particular case I'd expect to match the *.edge.foo.com for the hostname |
Yes, i would expect the same result, but navigating old issues and doing some testing , the results were this:
Fabio version is v1.5.6. Regards |
Could you see if you can reproduce the same behavior and b the current version? I thought this was covered in a router test case. |
I can't reproduce this. When I add this test to the 1.5.6 codebase it works: Sun Jun 10 20:25 frank@fancypants ((v1.5.6) *) $ git diff
diff --git a/route/table_test.go b/route/table_test.go
index eb0fdea..7d2da44 100644
--- a/route/table_test.go
+++ b/route/table_test.go
@@ -495,6 +495,7 @@ func TestTableLookup(t *testing.T) {
route add svc z.abc.com/foo/ http://foo.com:3100
route add svc *.abc.com/ http://foo.com:4000
route add svc *.abc.com/foo/ http://foo.com:5000
+ route add svc *.def.abc.com/ http://foo.com:6000
route add svc xyz.com:80/ https://xyz.com
`
@@ -530,6 +531,7 @@ func TestTableLookup(t *testing.T) {
// glob match the host
{&http.Request{Host: "x.abc.com", URL: mustParse("/")}, "http://foo.com:4000"},
+ {&http.Request{Host: "x.def.abc.com", URL: mustParse("/")}, "http://foo.com:6000"},
{&http.Request{Host: "y.abc.com", URL: mustParse("/abc")}, "http://foo.com:4000"},
{&http.Request{Host: "x.abc.com", URL: mustParse("/foo/")}, "http://foo.com:5000"},
{&http.Request{Host: "y.abc.com", URL: mustParse("/foo/")}, "http://foo.com:5000"}, |
Same for 1.5.9 and when I let the test run in a loop.
|
@magiconair thanks a lot for taking the time to test this. I haven't checked but in @arrodriguez example there's a path in the URL. Maybe that's causing the issue? |
Hmm, I can reproduce this with the test server. |
The demo server responds with 404 not found which is a bug in the demo server but the request gets routed to the wrong backend. |
Looks like a bug. |
I think I know what is going on. This line doesn't do what I think it does: https://github.com/fabiolb/fabio/blob/master/route/table.go#L306 The problem is not that fabio does not respect the longer host but that The issue is that domain names have the most significant part at the front whereas the request URIs have the most significant part at the end. |
That's also the reason the test case works since |
This patch fixes a behaviour where fabio routes to the wrong backend when multiple glob matching routes are available since the sorting of the host names was wrong. Sorting DNS names requires reversing them before sorting since they have their most significant part at the front. Fixes #506
This patch fixes a behavior where fabio routes to the wrong backend when multiple glob matching routes are available since the sorting of the host names was wrong. Sorting DNS names requires reversing them before sorting since they have their most significant part at the front. Fixes #506
This patch fixes a behavior where fabio routes to the wrong backend when multiple glob matching routes are available since the sorting of the host names was wrong. Sorting DNS names requires reversing them before sorting since they have their most significant part at the front. Fixes #506
@magiconair Thank you for your response. I understand the problem. while ago i had an issue in some project of firewall rules which uses wildcard host for matching. The difference with fabio is that this project permits the wildcard in any positiion. The solution were to use "permuterm indexes". (https://nlp.stanford.edu/IR-book/html/htmledition/permuterm-indexes-1.html) So in my opinion makes sense to rotate de entries in the route table index. But i dont know if fabio wants this scope. |
Fabio should always go from most specific to least specific when picking a match. However, it also allows a glob pattern anywhere in the host name. |
Yes you are right. Its make sense leaving this like #507 |
Issue #506: reverse domain names before sorting
@magiconair @marcosnils @xetorthio
Hello guys :
i am wondering which route fabio selects when we have configure this prefix:
if use api.edge.foo.com in the host header, What is the expect behaviour?
It will use *.edge.foo.com/gizmo or *.foo.com/gizmo ?
I was doing a couple of tests and always select the route * foo.com
Regards!
The text was updated successfully, but these errors were encountered: