I'm using PostgREST as an API for a project and now implement the security functions.
One thing I'd like to have but that is covered neither by row- nor by column-level security as I've read them so far is this use case:
- Table USERS is public SELECT (everyone can read it)
- Users can only edit (UPDATE) their own data (easy, row-level security)
- Admins can edit/delete all user's data (easy, role-based permission and row-level security)
- A few fields within the table should only be visible to admins and users themselves. Specifically, the phone number of a user should not be public information, but everyone should be able to see and edit their own phone number.
From everything I've read so far, neither row-level nor column-level security cover this, but I'm sure Postgres can handle it. How?
(Note: I know how to understand who the current user is and which row belongs to him, that is not my question)
Clarification: My users are not database users, but users in a user table. I have DB user roles for users, editors, admin, etc. but I don't create a DB role for every user signing up to the service. I can distinguish them for row-level security via JWT and
current_setting('request.jwt.claims', true)::json->>'user_id'
That's why I'm not trying to solve this with the obvious solution of using views.