Using policy for "only user can update, but anyone can read" logic? #372
Replies: 1 comment
-
This was my mistake - I was not defining the policies correctly. It's worth noting the original policy configuration I had didn't work for select queries either. The select query wasn't failing but it wasn't returning rows from the DB either (as confirmed by manually adding a row using the editor). I thought I didn't need a So I added a full "for all" type policy as below, and now selects and insert/update seem to be working:
Edit: So now I'm trying to figure out why my upsert doesn't work. Edit 2:
|
Beta Was this translation helpful? Give feedback.
-
Started trying to figure out the policy-based security stuff (I'm new to row-level-security stuff, never tried it before).
I made a
private_user_info
table andpublic_user_info
table (both in thepublic
schema). The idea being that I would store stuff a user wouldn't want other users to see in the "private" table, and the "public" table would be for stuff anybody can read, but only the user themselves can change.My schema definition policies looks like:
The private table policy seems to have worked, but the public table policy won't let me insert a row, it fails with
new row violates row-level security policy for table "public_user_info"
.The code for inserting into the table looks like:
Is the RLS policy stuff the right approach for this idea of "readable by anyone, only writable for the user"? Am I doing something wrong?
It occurs to me, maybe this is better done by moving the "display name" column to the private table and having a view that other users can query but not update (I guess by revoking privileges, never done it before)?
As well as the code being availabe, you can see or try out the app here (including the failing result from updating the display name).
Beta Was this translation helpful? Give feedback.
All reactions