Skip to content

path based acls for routing #1235

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

Merged
merged 1 commit into from
Mar 13, 2015
Merged

Conversation

pweil-
Copy link

@pweil- pweil- commented Mar 5, 2015

@rajatchopra @pmorie @ramr @akram @smarterclayton

All, this is the initial implementation of path based routing in the HAProxy router. Right now the router assumes that you're putting a / at the beginning of the route so a path based routing rule would look like the example below. I'd like some feedback on that assumption, if it is fine I'll add a validation rule to ensure the slash, if not then we can add the slash for users if preferrable.

Some notes for reviewers:

  • paths are matched based on the path_beg function in HAProxy AND the host name, both must match to trigger the ACL
  • path based routing rules use a lookup map with map_beg rules
  • path based routing rules have priority over the plain host rules
  • path based routes are supported (right now) for unsecure and edge terminated routes. I think we can do it for reencrypt routes too but I haven't addressed that use case in this PR

TODO:

  • get input on validations
  • sort the path based routes for the lookup map (see @rajatchopra 's comments below)
{
    "metadata": {
        "name": "route-unsecure-path"
    },
    "id": "route-unsecure-path",
    "apiVersion": "v1beta1",
    "kind": "Route",
    "host": "www.example.com",
    "path": "/test",
    "serviceName": "hello-nginx"
}

@rajatchopra
Copy link
Contributor

Path based ACLs are going to be quite slow. I had an explicit conversation with Willy on this topic and as always a new feature was delivered 'just for you'.
So, here is what came out. Use map_beg instead of map in our map lookup. In two separate lookups if that makes it easier for us. So create two files, one with hostname lookups that do not need paths (like one we have), and the other with paths included and values pointing to the backend.
e.g.

use_backend bk_%[base,map_beg(mapfile)]

The file would contain all the host+path sorted from the longest to the shortest (basically just a sort -r) :

 domain1/path1/       backend1
 domain1/path2/       backend2
 domain1/             backend3
 domain2/path1/       backend1
 domain2/             backend4

I had checked that with the commit from the git tree pre 1.5 release. You may want to verify the behaviour post-release. I tested with 150k backends and it was O(logn) and not O(n) anymore.

@pweil-
Copy link
Author

pweil- commented Mar 5, 2015

@rajatchopra awesome, I'll look at changing the implementation to use map_beg. Thanks for the info.

@pweil-
Copy link
Author

pweil- commented Mar 5, 2015

@rajatchopra PTAL - that cleans up the template significantly.

@rajatchopra
Copy link
Contributor

@pweil- Looks good. Should we prefer putting the hostname lookup before the path based lookup? Just so that bulk goes through one step and minority through two. Assuming path based stuff is going to be in minority.

@pweil-
Copy link
Author

pweil- commented Mar 5, 2015

@rajatchopra if you have both a path based and host based route for the same host you will never hit your path based route if the host based lookup is first.

@rajatchopra
Copy link
Contributor

Yes. I meant never to put the path based hostnames in the host map. I think the logic just moves on if appropriate backend is not found. You may want to double-check this, though. I may be wrong.
And with that we would not need the 'if' condition after map_beg look up (causes a double lookup).

@pweil-
Copy link
Author

pweil- commented Mar 5, 2015

We may have crossed streams. Let me illustrate what I'm thinking.

Let's say we have haproxy config of

use backend be_(map host, <file>) if blah

use backend be_(map base, <file>) if blah

user A has route1: www.example.com and route2: www.example.com/test. Which results in config files of:

os_http_be.map:
www.example.com <backend name>

EOF

os_http_paths_be.map:
www.example.com/test <backend name>

if mapping for host comes first then a request to http://www.example.com/test will match the os_http_be.map lookup.

Also, what I found was that if I used if TRUE it seemed to always end up at the default backend. I'm not discounting user error though, I can keep playing with it to see. But anyway, that's why I think the path based lookup needs to be first.

Please correct me if that's faulty logic.

@pweil- pweil- changed the title path based acls for routing WIP: path based acls for routing Mar 5, 2015
@pweil- pweil- force-pushed the router-paths branch 2 times, most recently from 548638f to 2c0639a Compare March 9, 2015 14:23
@pweil-
Copy link
Author

pweil- commented Mar 9, 2015

@rajatchopra - based on our IRC conversation I've cleaned up this implementation. I realized that we can use a single file for all of this too. So now the lookup tries a path based check and if that fails it reverts to a host header check.

I tested out what you were thinking about moving to the next use backend statement if lookup fails. That seems to work fine so long as the map result returns null. If anything is returned that doesn't exist it will fail which I think is fine because it indicates we have a map entry and no corresponding backend.

Please take a look.

@pweil-
Copy link
Author

pweil- commented Mar 9, 2015

[test]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_openshift3/1299/)

@pweil- pweil- changed the title WIP: path based acls for routing path based acls for routing Mar 10, 2015
@pweil-
Copy link
Author

pweil- commented Mar 10, 2015

@rajatchopra @smarterclayton @ramr removing the WIP tag. Ready for review.

Open item: is it ok for me to force a / at the beginning of the path field in validation or should I do a check + append?

@smarterclayton
Copy link
Contributor

Be strict up front so users get what the expect:

On Mar 10, 2015, at 9:05 AM, Paul [email protected] wrote:

@rajatchopra @smarterclayton removing the WIP tag. Ready for review.

Open item: is it ok for me to force a / at the beginning of the path field in validation or should I do a check + append?


Reply to this email directly or view it on GitHub.

@pweil-
Copy link
Author

pweil- commented Mar 10, 2015

updated with validations

@rajatchopra
Copy link
Contributor

In what cases do you feel 'base' will not match but 'hdr(host)' will?
If I guess the answer is www.example.com/ vs www.example.com, then I just feel there will be more apps without a path specification than without. So, a plain lookup with hdr(host) first and then one with 'base' may be more efficient.

Its a minor nit, though. Looks good to me otherwise.

@rajatchopra
Copy link
Contributor

I meant there will be more apps without a path spec than with any.

@pweil-
Copy link
Author

pweil- commented Mar 10, 2015

@rajatchopra this is particularly for use cases where someone has either both path based routes AND host based routes or only host based routes and making sure we match most specific to least:

Only Host:

  1. os admin defines www.example.com route (no path)
  2. user requests www.example.com/test
  3. haproxy misses on map_beg for the url
  4. haproxy hits on host header exact match

Host and Path:

  1. os admin defines www.example.com (1) route and www.example.com/test route (2)
  2. user requests www.example.com/test
  3. if we host check first we match route 1 and miss the path specificity
  4. if we match map_beg with base first we hit the correct route
  5. user requests www.example.com/test2
  6. same flow as above

@smarterclayton
Copy link
Contributor

Zomg make sure we have a test case for this :)

On Mar 10, 2015, at 3:05 PM, Paul [email protected] wrote:

@rajatchopra this is particularly for use cases where someone has either both path based routes AND host based routes or only host based routes and making sure we match most specific to least:

Only Host:

os admin defines www.example.com route (no path)
user requests www.example.com/test
haproxy misses on map_beg for the url
haproxy hits on host header exact match
Host and Path:

os admin defines www.example.com (1) route and www.example.com/test route (2)
user requests www.example.com/test
if we host check first we match route 1 and miss the path specificity
if we match map_beg with base first we hit the correct route
user requests www.example.com/test2
same flow as above

Reply to this email directly or view it on GitHub.

@pweil-
Copy link
Author

pweil- commented Mar 10, 2015

I'll add a new test method to the int test that tests this combination together. The individual isolated cases are covered.

@@ -240,6 +273,146 @@ func TestRouter(t *testing.T) {
}
}

// TestRouterPathSpecificity tests that the router is matching routes from most specific to least when using
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarterclayton @rajatchopra - this is a test for the use case I was mentioning. PTAL

@smarterclayton
Copy link
Contributor

Please leave final review on this.

@rajatchopra
Copy link
Contributor

LGTM. Good work.

@smarterclayton
Copy link
Contributor

[merge]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_openshift3/1175/) (Image: devenv-fedora_1038)

@openshift-bot
Copy link
Contributor

Evaluated for origin up to a7b4855

openshift-bot pushed a commit that referenced this pull request Mar 13, 2015
@openshift-bot openshift-bot merged commit 84d9030 into openshift:master Mar 13, 2015
jboyd01 pushed a commit to jboyd01/origin that referenced this pull request Sep 20, 2017
…service-catalog/' changes from ae6b643caf..50e234de83

50e234de83 origin build: add origin tooling
092d7f8 Fix typos and resource names in walkthrough e2e logs (openshift#1237)
d25bd11 Archive the old agenda doc, link to new one (openshift#1243)
6192d14 fix lint errors (openshift#1242)
d103dad Fix lint errors and regenerate openapi (openshift#1238)
e9328d3 Broker Relist (openshift#1183)
b0f3222 Correct the reasons and messages set on the ready condition during async polling (openshift#1235)
d2bb82f Re-enable the href checker (openshift#1232)
2c29654 Use feature gates in controller-manager (openshift#1231)
699eab9 switch build to go1.9 (openshift#1155)
7529ed8 broker resource secret authorization checking (openshift#1186)
50d9bdf v0.0.20 chart updates (openshift#1228)
REVERT: ae6b643caf Use oc adm instead of oadm which might not exist in various installations.
REVERT: 66a4eb2a2c Update instructions... will remove once documented elsewhere
REVERT: 1b704d1530 replace build context setup with init containers
REVERT: ee4df18c7f hack/lib: dedup os::util::host_platform and os::build::host_platform
REVERT: 1cd6dfa998 origin: Switch out owners to Red Hatters
REVERT: 664f4d318f Add instructions for syncing repos
REVERT: 2f2cdd546b origin-build: delete files with colon in them
REVERT: cdf8b12848 origin-build: don't build user-broker
REVERT: ebfede9056 origin build: add _output to .gitignore
REVERT: 55412c7e3d origin build: make build-go and build-cross work
REVERT: 68c74ff4ae origin build: modify hard coded path
REVERT: 3d41a217f6 origin build: add origin tooling

git-subtree-dir: cmd/service-catalog/go/src/github.com/kubernetes-incubator/service-catalog
git-subtree-split: 50e234de836b5e7c9e3d7d763847b99a0f0ea500
jboyd01 pushed a commit to jboyd01/origin that referenced this pull request Sep 21, 2017
…service-catalog/' changes from ae6b643caf..06b897d198

06b897d198 origin build: add origin tooling
092d7f8 Fix typos and resource names in walkthrough e2e logs (openshift#1237)
d25bd11 Archive the old agenda doc, link to new one (openshift#1243)
6192d14 fix lint errors (openshift#1242)
d103dad Fix lint errors and regenerate openapi (openshift#1238)
e9328d3 Broker Relist (openshift#1183)
b0f3222 Correct the reasons and messages set on the ready condition during async polling (openshift#1235)
d2bb82f Re-enable the href checker (openshift#1232)
2c29654 Use feature gates in controller-manager (openshift#1231)
699eab9 switch build to go1.9 (openshift#1155)
7529ed8 broker resource secret authorization checking (openshift#1186)
50d9bdf v0.0.20 chart updates (openshift#1228)
REVERT: ae6b643caf Use oc adm instead of oadm which might not exist in various installations.
REVERT: 66a4eb2a2c Update instructions... will remove once documented elsewhere
REVERT: 1b704d1530 replace build context setup with init containers
REVERT: ee4df18c7f hack/lib: dedup os::util::host_platform and os::build::host_platform
REVERT: 1cd6dfa998 origin: Switch out owners to Red Hatters
REVERT: 664f4d318f Add instructions for syncing repos
REVERT: 2f2cdd546b origin-build: delete files with colon in them
REVERT: cdf8b12848 origin-build: don't build user-broker
REVERT: ebfede9056 origin build: add _output to .gitignore
REVERT: 55412c7e3d origin build: make build-go and build-cross work
REVERT: 68c74ff4ae origin build: modify hard coded path
REVERT: 3d41a217f6 origin build: add origin tooling

git-subtree-dir: cmd/service-catalog/go/src/github.com/kubernetes-incubator/service-catalog
git-subtree-split: 06b897d1988a5a3c035c5a971c15b97cbc732918
jpeeler pushed a commit to jpeeler/origin that referenced this pull request Feb 1, 2018
Miciah pushed a commit to Miciah/origin that referenced this pull request Jun 27, 2018
[3.9] Bug 1567532 - Unidle handling in router should ignore headless services.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants