Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORY Oathkeeper match multiple rules

In ORY Oathkeeper I would like a request to the domain root to go to one server, and a request to a sub path to go to another server. So I defined two rules like this:

[
  {
    "id": "ping1",
    "version": "v0.0.1",
    "upstream": {
      "url": "http://backend1/"
    },
    "match": {
      "url": "http://<.*>/api/ping1",
      "methods": ["GET"]
    },
    "authenticators": [{ "handler": "anonymous" }],
    "authorizer": { "handler": "allow" },
    "mutators": [{ "handler": "noop" }]
  },
  {
    "id": "ping2",
    "version": "v0.0.1",
    "upstream": {
      "url": "http://backend2/"
    },
    "match": {
      "url": "http://<.*>",
      "methods": ["GET"]
    },
    "authenticators": [{ "handler": "anonymous" }],
    "authorizer": { "handler": "allow" },
    "mutators": [{ "handler": "noop" }]
  }
]

Accessing the root works. However, when I try to access the sub path ending with /api/ping1, I get "Expected exactly one rule but found multiple rules reason= request-id= status=500 "

I can get around this by not defining the root rule as "url": "http://<.*>", but instead use the specific domain name.

This works:

"match": {
      "url": "http://mydomainname.com",
      "methods": ["GET"]
},

But, I would like to avoid that, and be able to put a wild card to match domain name there. Is there a way of making this work without explicitly specifying the domain name?

like image 523
Henrik Avatar asked Sep 08 '25 04:09

Henrik


1 Answers

I found that it works with a wildcard if I add a slash att the end of the match url, like so:

{
    "id": "ping2",
    "version": "v0.0.1",
    "upstream": {
      "url": "http://backend2/"
    },
    "match": {
      "url": "http://<.*>/",  <--- SLASH ADDED AT END
      "methods": ["GET"]
    },
    "authenticators": [{ "handler": "anonymous" }],
    "authorizer": { "handler": "allow" },
    "mutators": [{ "handler": "noop" }]
  }
like image 107
Henrik Avatar answered Sep 11 '25 02:09

Henrik