Skip to content
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

Fix prefix path type if the path matches a domain #756

Merged
merged 1 commit into from
Mar 26, 2021

Conversation

jcmoraisjr
Copy link
Owner

Map keys are built using sysadmin/user defined hostnames and paths. We concatenate both when building the map file, and also concatenate hdr(host) and path from the incoming request. This works pretty well on beg and reg match types. Since v0.11 we have also dir (Prefix from ingress pathType) and str (Exact). The later also work well with this construction, but str (Prefix) does not behave as expected from the end user perspective.

Take this map example:

   domain.local/ backend1
   sub.domain.local/ backend2

and this request:

   sub.domain.local/domain.local

A begin or regex match type would choose backend2, and this is the expected behavior for prefix as well, but due to how haproxy implements -m dir, backend1 would be chosen.

When using dir match type, haproxy slices the request using the slash as separator. These slices tries to match a whole map entry, but without starting from the beginning.

A hash # is added after the hostname and before the first slash, leaving the first item of the slice as unique. This is only needed for dir / Prefix, but will not hurt other match types and does not have any performance degradation.

Now the map looks like this:

   domain.local#/ backend1
   sub.domain.local#/ backend2

and the request is internally converted to this:

   sub.domain.local#/domain.local

Should be merged as far as v0.11.

Map keys are built using sysadmin/user defined hostnames and paths. We
concatenate both when building the map file, and also concatenate
hdr(host) and path from the incoming request. This works pretty well on
beg and reg match types. Since v0.11 we have also dir (Prefix from
ingress pathType) and str (Exact). The later also work well with this
construction, but str (Prefix) does not behave as expected from the end
user perspective.

Take this map example:

   domain.local/ backend1
   sub.domain.local/ backend2

and this request:

   sub.domain.local/domain.local

A begin or regex match type would choose backend2, and this is the
expected behavior for prefix as well, but due to how haproxy implements
-m dir, backend1 would be chosen.

When using dir match type, haproxy slices the request using the slash as
separator. These slices tries to match a whole map entry, but without
starting from the beginning.

A hash # is added after the hostname and before the first slash,
leaving the first item of the slice as unique. This is only needed for
dir / Prefix, but will not hurt other match types and does not have any
performance degradation.

Now the map looks like this:

   domain.local#/ backend1
   sub.domain.local#/ backend2

and the request is internally converted to this:

   sub.domain.local#/domain.local

Should be merged as far as v0.11.
@jcmoraisjr
Copy link
Owner Author

#753

@jcmoraisjr jcmoraisjr merged commit 1c2b422 into master Mar 26, 2021
@jcmoraisjr jcmoraisjr deleted the jm-fix-prefix-match branch March 26, 2021 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant