-
Notifications
You must be signed in to change notification settings - Fork 162
Provide auth example with app users + row level security #81
Comments
This may be a little tangential... I banged my head against RLS and ended up enforcing it in the API views like so: I'll work through 2ndQuadrant's blog post this weekend to contrast |
Note to self, also include example of read-only or invisible fields based on user permissions as @sqwishy requested in the chat.
|
Also @daurnimator poses another scenario we might want to model:
|
Planning to make this tutorial 2 (we've got 0 and 1 already written) |
Hi, I'm trying to tackle authentication and I followed the example on the docs and it seems I have generated the mentioned functions and tables but:
If I could get some pointers on how to continue, I'd also be very happy to contribute to the docs. Thanks :) |
Sorry for the silence. Did you manage to make the login function work? |
I too am struggling with this example. First I was getting
when trying to create the It feels like I'm close but I'm pretty inexperienced with functions/stored procedures in Postgres. 😕 |
Sorry for not replying as well, I haven't been able to solve the problem myself (probably for lack of trying). |
I could be wrong, but it seems that row-level security policies are not enforced when a table is being accessed through a view. Instead, the table is accessed using the privilege of the view's owner, instead of the current role? This is based on a small amount of experimentation and my poor reading of If this is the case, I suppose the thing to do is duplicate the security policy into the view's where clause (and maybe use See also: Work:
|
@sqwishy Yes, RLS rules are applied to the view owner and it's likely that you have a SUPERUSER(or a role with BYPASSRLS) as the owner and that will bypass RLS. What you can do is to There's an example in postgrest-starter-kit where a dedicated "api" role is created for this, |
FYI, there's an RLS bug on VIEWs that @daurnimator reported in psql-bugs. Basically, subqueries in the RLS policy are not checked against the privileges of the view owner but of the view caller. I also bumped in to this bug when working on a example for the rls tutorial. Edit: I think the most simple workaround for this would be wrapping the subquery in a security definer function. |
The bug was fixed https://www.postgresql.org/message-id/CAEZATCV_yDYoptaxtjiVB4yLwxQ%3DN7OWu8Ls98rA5MvBL%2BjKiQ%40mail.gmail.com. Haven't tried and see if it's available on pg recent releases though. |
By now we have examples for app users + row level security! |
This blog post presents a great approach for auth:
https://blog.2ndquadrant.com/application-users-vs-row-level-security/
Postgrest does not allow arbitrary user queries, so the article's approach becomes really simple. Our docs need a clear example of how to do auth.
The text was updated successfully, but these errors were encountered: