parse-dashboard icon indicating copy to clipboard operation
parse-dashboard copied to clipboard

CLP not working as expected

Open phillipwinder opened this issue 9 years ago • 15 comments

Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Dashboard!

  • [X] You're running version >=1.0.23 of Parse Dashboard.

  • [X] You're running version >=2.3.2 of Parse Server.

  • [X] You've searched through existing issues. Chances are that your issue has been reported or resolved before.

Environment Setup

Steps to reproduce

I have a class XYZ. If I go into the security menu of this class and set public read to FALSE everything works as expected. I can now not read any data from this class. However if I click on "Role, User or Pointer...", add my user with which I am currently logged in and set read to TRUE for this user i still cannot retrieve the data from this class. Do I have to do something differently here?

My goal would be to make certain data only visible to certain user (further down by assigning them to roles).

phillipwinder avatar Oct 18 '17 16:10 phillipwinder

Can you provide the content of your schema?

flovilmart avatar Oct 18 '17 16:10 flovilmart

Please see my comment on this issue.

This is the expected result. Without the master key, a query must pass both CLP and ACL checks to access an object.

natanrolnik avatar Oct 18 '17 16:10 natanrolnik

Thank you for your answers. However I am still a little bit stuck here. If I want different roles to be able to "read" different classes, how do I implement that? For example user X should have read permission for class XYZ but not ABC and user Y should have read permission for both classes.

phillipwinder avatar Oct 18 '17 17:10 phillipwinder

Wait, it's my bad. I thought you were using ACLs with your user. CLPs should indeed work as you are describing. Are you able to post here the Schema as @flovilmart requested?

natanrolnik avatar Oct 18 '17 17:10 natanrolnik

Wow, you guys are fast, thanks so much :)

What exactly do you mean by schema? How the classes are structured, their columns, the column types and so on?

phillipwinder avatar Oct 18 '17 17:10 phillipwinder

In your Mongo database, there is a collection called _Schema. Can you post the content of its single document?

natanrolnik avatar Oct 18 '17 17:10 natanrolnik

I just found out, that it only happens for a specific class. In all other cases it works fine. I will debug a little bit and get back to you :)

phillipwinder avatar Oct 18 '17 18:10 phillipwinder

Ok, so for this specific class I am getting the following error:

2017-10-19T15:02:52.146Z - Permission denied for action find on class XYZ. 2017-10-19T15:02:52.145Z - Error generating response. ParseError { code: 119, message: 'Permission denied for action find on class XYZ.' }

I am however never using the find method on the class XYZ.

phillipwinder avatar Oct 19 '17 15:10 phillipwinder

Here is a snippet of my cloud code to demonstrate where the error is happening:

the class in question is called "Booking"


let bookingQuery = new Parse.Query("Booking");
        
        bookingQuery.equalTo("golfCourse", golfCourseParseObject);
        bookingQuery.equalTo("isCanceled", false);            
        bookingQuery.include("user");      
        // Until here, everything gets executed as expected - no Errors

        bookingQuery.each(booking => {             
            // This does not execute - throws the error message

phillipwinder avatar Oct 19 '17 15:10 phillipwinder

@PhillipWinder how are you saving this booking object? Who has the ACL on it? You should pass the session token of the user you want. For example:

bookingQuery.find({sessionToken: user.getSessionToken()}).then(function(results) {
    //iterate over results.
});

natanrolnik avatar Oct 19 '17 21:10 natanrolnik

A booking object is set on the frontend (the user selects some parameters (date, golfcourse and so on) and then booking.save() is called to create the object.


const BookingParseObj = Parse.Object.extend("Booking")
            let newBooking = new BookingParseObj()

            newBooking.set("bookingDate", date)
            newBooking.set("golfCourse", golfCourseObject)
            newBooking.set("user", Parse.User.current())
            newBooking.set("isCanceled", false)
            newBooking.set("isRemainingStock", isRemainingStock)
            newBooking.set("isInvite", this.isInvite)
            newBooking.set("slots", slots)

            return newBooking.save()

ACL on all booking objects (as of now) is public read write true.

Do you mean like this?

bookingQuery.each({sessionToken: request.user.getSessionToken()}, booking => {}

If I do

bookingQuery.find({sessionToken: user.getSessionToken()}).then(function(results) {
    console.log(results)
});

then results always is an empty array.

If I do

bookingQuery.each({sessionToken: request.user.getSessionToken()}, booking => {     
   console.log(booking)   

then I get null logged one time (although there are multiple booking objecs)

phillipwinder avatar Oct 20 '17 01:10 phillipwinder

ACL on all booking objects (as of now) is public read write true.

If ACLs are public write and read, then how come the finds come empty? Is the CLP also public write and read?

I think you might be missing something or the query isn’t right. Try running the same query if master key and see the response. If it has objects, then it’s a ACL/CLP “problem” (likely not really a problem in how they work, but in how you are expecting them to work); if it doesn’t return objects even with the master key, then the query parameters might be wrong.

natanrolnik avatar Oct 20 '17 06:10 natanrolnik

“If ACLs are public write and read, then how come the finds come empty?“ - this is exactly my question :D

If I set the CLP for the booking class to public read write true everything works fine. If I set it to public read write false also everything works as expected (nothing can be accessed). If I set it too public read write false AND use the masterkey also everything works as expected (everything can be accessed). So the query per se does work - in the cases where I should be able to get the booking objects using the find/each method I do get them.

HOWEVER if I set the CLP to

  • public read write false
  • myUser read write true

I cant get the data although I am logged in with myUser and SHOULD have read/write permissions for the booking class. Instead I get the above mentioned error and the find/each method return null - that is the strange thing thats happening. Other query methods (include, equalTo..) work fine (I can access the data with my user) but find/each strangely do not work.

As mentioned above the ACL for all booking objects is public read write true.

I can also provide you screenshots of my CLP/ACL settings and querys if you would like to (just tell me where to send them to).

phillipwinder avatar Oct 20 '17 08:10 phillipwinder

the each is backward, try this instead:

bookingQuery.each(console.log, {sessionToken: request.user.getSessionToken()});

see: http://parseplatform.org/Parse-SDK-JS/api/classes/Parse.Query.html#methods_each

Also, in a comment up above, you say:

if I do

 bookingQuery.find({sessionToken: user.getSessionToken()}).then(function(results) {
    console.log(results)
});

then results always is an empty array.

Can you console.log(user.toJSON()) and verify that you are getting a session token?

and that the username is what you expect? Should it maybe be request.user?

acinader avatar Oct 20 '17 16:10 acinader

bookingQuery.each(console.log, {sessionToken: request.user.getSessionToken()});

This did the trick! Thank you so much :)

phillipwinder avatar Oct 20 '17 20:10 phillipwinder