mornir
09/03/2021, 11:22 AMsilentworks
09/03/2021, 1:11 PMmornir
09/03/2021, 1:15 PMmornir
09/03/2021, 1:16 PMmornir
09/03/2021, 1:17 PMmornir
09/03/2021, 1:18 PMsilentworks
09/03/2021, 1:18 PMsilentworks
09/03/2021, 1:19 PMuser_id
in the reviews table represent? is that the user who created the review or the user who can view that review?mornir
09/03/2021, 1:20 PMmornir
09/03/2021, 1:20 PMmornir
09/03/2021, 1:20 PMsilentworks
09/03/2021, 1:21 PMuser_id
in the reviews table to created_by
to not confuse you later onmornir
09/03/2021, 1:21 PMsilentworks
09/03/2021, 1:23 PMsilentworks
09/03/2021, 1:23 PMcreate policy
partsilentworks
09/03/2021, 1:23 PMmornir
09/03/2021, 1:25 PMsilentworks
09/03/2021, 1:26 PMmornir
09/03/2021, 1:27 PMsilentworks
09/03/2021, 1:27 PMsql
(
auth.uid() IN (
SELECT user_id
FROM members
WHERE reviews.group_id = members.group_id
)
)
mornir
09/03/2021, 1:28 PMsilentworks
09/03/2021, 1:29 PMgroup_id
should be from the reviews
table or maybe we need to make it explicit because you have a group_id
on the members table toosilentworks
09/03/2021, 1:29 PMsilentworks
09/03/2021, 1:30 PMmornir
09/03/2021, 1:36 PMmornir
09/03/2021, 1:36 PMsilentworks
09/03/2021, 1:36 PMsilentworks
09/03/2021, 1:36 PMmornir
09/03/2021, 1:36 PMsilentworks
09/03/2021, 1:36 PMmornir
09/03/2021, 1:37 PMsilentworks
09/03/2021, 1:38 PMmornir
09/03/2021, 1:39 PMsilentworks
09/03/2021, 1:39 PMmornir
09/03/2021, 1:39 PMsilentworks
09/03/2021, 1:39 PMsilentworks
09/03/2021, 1:39 PMsilentworks
09/03/2021, 1:39 PMmornir
09/03/2021, 1:40 PMsilentworks
09/03/2021, 1:41 PMWaldemar
09/03/2021, 2:17 PMuser_id
), but also more complex. For example suppliers
table:
- John must view all records, but only be able to create/update records where suppliers.country
is "Italy"
- Anna must be able to view/create/update/delete all suppliers
- ...
And we have a few such tables. So you can imagine it will be a nightmare to maintain a many-to-many table like user_suppliers
for each individual user / supplier combo and different level of permissions.
We need a proper RBAC basically.
I guess it is more of a question of how I design all these roles/permissions tables. I hope the auth.uid
will be enough and I can somehow join my way through to the user's role privileges without needing to create hundreds of policies or maintain thousands of many-to-many tables just for RBAC.
Btw, I've been developing ERP projects for 10 years and the RBAC system there was insane. Sometimes I was setting up roles for months. I mean not design the RBAC system itself, but actually setting up what you call "policies" here.
Anyways, I will try to make it work just with auth.uid()
. If you guys are interested, I can share how I've done it / what I struggled with and maybe there is something you could add to Supabase to make it easier to design a bit more sophisticated RBAC compared to the simple user/team, user/review cases.Waldemar
09/03/2021, 2:29 PMCREATE POLICY supplier_managers_it ON supplier TO managers_italy
...
because for that I'd need one Postgres user per my app user and assign him to Postgres role managers_italy
in this example, but it's always the`postgres` user my users will log in as, isn't it? The actual user is stored in JWTSETY
09/06/2021, 9:37 PMSETY
09/06/2021, 9:38 PMcreate or replace function auth.uid() returns uuid as $$
select nullif(current_setting('request.jwt.claim.sub', true), '')::uuid;
$$ language sql stable;