-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Bug: realtime RLS policy evaluation differs based on type of change (INSERT vs DELETE), DELETE broadcasting in violation of RLS policy #562
Comments
@zachblume can you take a look at these docs and see if that addresses your issue? https://supabase.com/docs/guides/realtime/postgres-changes#custom-tokens |
Giving that a try, I did:
And got the following console error:
The error is only trigger if I make the supabase......subscribe() realtime call. |
The token I'm using from Clerk.dev:
Using jwt.io looks like this:
|
If I switch out all the keys for the anon key:
Then the websocket works (except for RLS of course). Seems to me like token.role might be at issue since clerk.dev passes a token signed with role=authenticated? Or something else? |
Looks like the same problem here:
|
I eventually found a workaround in a related thread using supabase.realtime.setAuth:
RLS process mostly correctly on self-hosted (after I re-made my development server and double checked replication and RLS policies). However, the oustanding bug of ALL deletes being broadcasted still persists, ignoring the RLS policy. |
To summarize:
I'm interested in collaborating on a PR to fix these |
I can confirm all of the issues summarized above, and in addition, I was not able to fix them with the mentioned workaround.
Also, I'm using the hosted version. @w3b6x9 tagging you, since you have been very helpful in solving issues with custom JWT 😄. Ps.: Might help - I've added logging to the function I use in the RLS policy, and while the logs are there when getting data via select, they are completely missing for realtime, suggesting that changes on realtime-subscriptions never make it to the RLS policy. Pss.: @zachblume logs can be added by using plpgsql and the
|
Thanks for the pointer to |
Not sure which logs you mean with pl/sql native logging, but the logs from |
I've tried one more time to apply the workaround, where I create the supabase-client without any options, and then call
@w3b6x9 any pointers as to what the error For reference, the payload of my token is:
with header:
This token works with RLS policy when getting data via @zachblume I've just seen it mentioned in the docs, that |
I finally got the workaround working.. I saw that the header of the custom jwt has to contain Found it while looking at:
@zachblume sorry for freeriding on your ticket.. |
Bug report
System information
Details and reproduction
I am using Clerk.dev's supabase template to sign my Supabase JS client with a proper JWT. The JWT includes an organization id metadata, orgID:
RLS works fine with a custom function:
With a simple policy:
This is where things start getting weird.
I subscribe to the table call_sessions realtime replication channel:
When I insert or update rows through the authenticated client, the listener is not triggered (it should be). When I delete rows through the authenticated client, the listener is correctly triggered.
Same thing with a raw connection: When I insert or update rows through PSQL or the Supabase studio, the listener is not triggered. When I delete rows which previously contained the correct organization_id through PSQL or supabase studio, the listener is triggered (correctly).
When I delete rows which previously contained a nonsense organization_id (organization_id="id_that_shouldnt_match_any_RLS_client") through PSQL or supabase studio, the authenticated listener somehow is also triggered (incorrectly).
When I disable RLS, the client listener is triggered by UPDATE, INSERT and DELETE from both authenticated client and raw connections. So clearly the problem is that RLS is being evaluated in a nonstandard way, i.e. the execution context must differ between regular SQL and realtime production.
What is going on there? Eeek.
Can I somehow fix:
The text was updated successfully, but these errors were encountered: