SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Setting where (URL rewrite) of mongo-mounts property as path prefix in predicate #245

Closed varunnayal closed 7 years ago

varunnayal commented 7 years ago

RestHeart Version: 3.1.1

I am trying to use where property in mongo-mounts to define permissions for various roles. Here is the snippet of mongo-mounts from restheart.yml

...
mongo-mounts:
    - what: "*"
      where: /
    - what: "/db/coll"
      where: "/path/to/collection"
...

Here is the snippet of permissions from security.yml

...
users:
    - userid: restrict
      password: restrict
      roles: [basic]
...
permissions:
   ...
    - role: basic
      # Based on the url exposed in mongo-mounts
      predicate: path-prefix[path="/path/to/collection"]
...

Now, following curl request throws Forbidden Access(403) error curl -u restrict:restrict 'http://127.0.0.1:8080/path/to/collection'

Changing the predicate to /db/coll and then using http://127.0.0.1:8080/db/coll in curl would work and restrict the user to specified collection but then we won't be using url rewrite feature.

ujibang commented 7 years ago

That's by design. The predicate is applied to the canonical resource name, not to the rewritten one.

This way you can remap your URLs without impacting the security configuration.

varunnayal commented 7 years ago

Thanks for the clarification.