-
-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.x] RLS without central user (role) having bypassrls #1288
[4.x] RLS without central user (role) having bypassrls #1288
Conversation
…-bypassrls' into rls-fix-for-central-user-without-bypassrls
Thanks for the PR! Can you revert the formatting changes? |
Ah nevermind, I see that there's an extra loop now. |
Currently in the process of testing an alternative implementation for this btw, so no need to bother fixing phpstan for now. |
Could you provide some concrete reproduction steps for the bug first? |
The user that is used as the central user in tenancy should not have the Could you try with:
Or just create a new user:
Some possible steps to follow:
Without this pull request the app will throw a error or just not select the data, because the user cannot access the data without rls bypass. You can check the policies by running |
Thanks, we managed to reproduce the issue with those steps. I have a few questions though:
|
Thanks for checking! I'm using a Scaleway managed Postgresql database and it has limitations:
They have made it so that i can create users from their admin-ui but im unable to grant the users BYPASSRLS. Maybe i'm stupid in not being able to figure out how to do it with their system and limitations but there you go.
I'm not sure about the 'FORCE ROW LEVEL SECURITY' removal. How can i test this on my system? |
Should be enough to just remove 'FORCE ROW LEVEL SECURITY' from all places in the code. |
I tested it a bit, and everything seems fine, so that's great! But it does seem less secure, although it probably isn't. It depends on the users that have access to the database. With the other setup all users have to adhere to RLS.
|
I think we can just make that part of the RLS statements configurable then? Seems better than maintaining two sets of policies. |
Off topic, RLS macros
Usage
|
Seems about right. |
Can you provide some more context for the finetuning? What exactly do you need to customize? |
Yeah sure, I have one table that contains 'system' and tenant created rows.
And in another instance I wanted to use a function to determine if a user should or should not be able to view nodes in a tree where the root node is set in a tree_owners table:
Not very efficient but does the job in my case |
Hmm could you expand on the use case in a bit more depth? Normally to interact with central data you could just do |
Original issue
Description
I am using a managed Postgres solution where the admin role does not have and can not get BYPASSRLS.
That leads to the behaviour that when using the 'central connection' i don't have access to tenant data (including 'tennant_user').
That makes the management of tenants impossible.
So I thought of a solution giving the tenancy.rls.user.username (database tenant_user) the rsl policies already implemented by the package.
AND giving the central user a policy with full access:
This worked for me :)
Why this should be added
I have implemented this in the
CreateUserWithRLSPolicies
command and 'TableRLSManager' class.This could use some more refactoring and possibly detecting if central user has BYPASSRLS permissions and ommiting the central policy.
But this is to give you an idea of what I did with this.
What do you think?
Original @stancl reply: