S
Supabase3y ago
sebx

Permission denied for table but RLS is disabled?

All of my other tables are working just fine, but for some reason this new table I created isn't. Had RLS enabled and couldn't figure out why it was throwing errors, disabled it for a sanity check and it's still throwing permission error... Help! Not sure what bit of code is relevant to show here, but please let me know
90 Replies
NanoBit
NanoBit3y ago
Please show the error / code / table structure
sebx
sebxOP3y ago
{"message":"permission denied for table invitations","code":"42501","details":null,"hint":null}
{"message":"permission denied for table invitations","code":"42501","details":null,"hint":null}
Code:
const {data, error, count} = await supabaseClient.from("invitations").select('*', {count: 'exact'}).eq('fromId', ID).order('createdAt', {ascending: false}).limit(10)
const {data, error, count} = await supabaseClient.from("invitations").select('*', {count: 'exact'}).eq('fromId', ID).order('createdAt', {ascending: false}).limit(10)
Table structure:
sebx
sebxOP3y ago
No description
NanoBit
NanoBit3y ago
hm, that's weird. It looks normal If you create a new table, do u still have this issue? Is this local development?
sebx
sebxOP3y ago
I'll give it a shot - one sec And no the db is on supabase Okay so I made a new table, just using the supabase UI and it works fine....
garyaustin
garyaustin3y ago
I'm noticing you have alot of camelcase letters in your columns. That is not a good idea unless you are forced to by Prisma. https://discord.com/channels/839993398554656828/885237287280070708/988097402059780098
sebx
sebxOP3y ago
oh really? I've just been camelcasing everything because I'm using js i see i see
garyaustin
garyaustin3y ago
It will bite you at some point. The API does handle it, but if you write functions or RLS policies you have to double quote everything.
sebx
sebxOP3y ago
I wonder if somewhere in there is where my issues arose The table that wasn't working was generated via prisma schema
garyaustin
garyaustin3y ago
Your table permission thing is a bit odd. Did you create it any differently than others. LOL. YEs Yes, Prisma you have to do a bunch of grant fixes.
sebx
sebxOP3y ago
But all of my other tables are also generated the same way -- so i'm not really sure
garyaustin
garyaustin3y ago
Prisma
Prisma
Connect your Supabase postgres database to your Prisma project.
sebx
sebxOP3y ago
but considering the one i made with the UI works fine i'm guessing that's the issue
garyaustin
garyaustin3y ago
Has to do with migrations or some such you do on Prisma. I don't use it.
sebx
sebxOP3y ago
how do you manage your schemas?
garyaustin
garyaustin3y ago
I don't know anything about Prisma.
sebx
sebxOP3y ago
sure, but in general do you just keep the plain sql for migrations?
garyaustin
garyaustin3y ago
I have an IDE that handles what I do. Supabase has migration support with the CLI tool. That might be a good question to ask if you don't find it quickly in the docs.
sebx
sebxOP3y ago
That might be a good question to ask if you don't find it quickly in the docs. what do you mean do you use datagrip or something?
garyaustin
garyaustin3y ago
I do as part of PHPStorm
sebx
sebxOP3y ago
hmm okay i see
silentworks
silentworks3y ago
I write all mi migrations and ley to run them
sebx
sebxOP3y ago
anyways thanks for pointing me in the right direction -- I don't use prisma besides just for managing my schema/migrations
NanoBit
NanoBit3y ago
oh
silentworks
silentworks3y ago
I would say a better tool for managing your migrations is knex, it won't do crazy stuff like Prisma does
silentworks
silentworks3y ago
GitHub
GitHub - silentworks/appsmith-supabase-auth
Contribute to silentworks/appsmith-supabase-auth development by creating an account on GitHub.
silentworks
silentworks3y ago
Knex is great because you also get seeding as part of its tooling, so you can get test data into your database quickly.
sebx
sebxOP3y ago
Cool I'll look into that thank you! I saw your waitlist sveltekit demo app a while back and started using ley because of it haha, very nice to handle rls policies and indexes I'm just not very good at sql so anything that lets me not have to mess around with sql every time i need to make changes to tables is awesome to me
NanoBit
NanoBit3y ago
After reading how silentworks keep proposing knex makes me want to try it, sadly i've become stuck with prisma for now
silentworks
silentworks3y ago
I really need to update that repo to the latest SvelteKit and Auth Helpers
sebx
sebxOP3y ago
Same here, definitely going to check it out
silentworks
silentworks3y ago
Prisma works for a lot of people, but I'm not used to a migration tool blowing away my entire database just to create it again. I've never seen a migration tool that works like that in all my years of coding.
NanoBit
NanoBit3y ago
In my case, I don't have your issue with prisma. Granted: i don't use camelCase, I @map all names to snake case after reading gary mention that issue many times. I'd recommend running that Grant script once then
silentworks
silentworks3y ago
Gary is a wise man, so his advice is very much golden.
sebx
sebxOP3y ago
sure, if you ignore the "you'll need to reset your db to apply changes" warning messages you're in for a rude surprise but it's possible to say no and make minor changes like adding default values or whatever before migrating
NanoBit
NanoBit3y ago
It's a weird tool sometimes. I set up mine to re-apply the grant after each prisma migration during development. However, production works fine
sebx
sebxOP3y ago
can you share a link for this? definitely need to get on that
NanoBit
NanoBit3y ago
The Grant script is here
sebx
sebxOP3y ago
oh oh the resetting of privs and such
silentworks
silentworks3y ago
I think @sebx is after how you do the mapping to snake_case
NanoBit
NanoBit3y ago
Prisma
Prisma schema API (Reference)
API reference documentation for the Prisma Schema Language (PSL).
NanoBit
NanoBit3y ago
Sorry was trying to get that link
garyaustin
garyaustin3y ago
Well at least he did not say "wise old man"...😎
silentworks
silentworks3y ago
How can you be old at 25 Gary?
garyaustin
garyaustin3y ago
LOL
sebx
sebxOP3y ago
I did try to run the grant script before posting here and got an error relating to the "supabase_admin" role "supabase_admin" is a reserved role, only superusers can modify it
silentworks
silentworks3y ago
Where did you try and run it from?
sebx
sebxOP3y ago
the UI
NanoBit
NanoBit3y ago
Is it due to the migration from supabase_admin to postgres? Normally, I just ignore it when I apply my grants on Supabase db. (It doesn't affect anything for me)
garyaustin
garyaustin3y ago
You can tell if the new migration has occurred by doing "select user" in the SQL editor.
sebx
sebxOP3y ago
is "postgres_temporary_object_holder" the correct response to that query
garyaustin
garyaustin3y ago
Well I think that means you are in the middle of the process. Maybe ran the scripts.
sebx
sebxOP3y ago
same outcome
silentworks
silentworks3y ago
It's a sign. Ok I'm leaving now.
sebx
sebxOP3y ago
hahah oh well thanks for butting in @silentworks
NanoBit
NanoBit3y ago
This is an interesting error. Could you also list: prisma version, supabase version, whether this is production db or testing db
silentworks
silentworks3y ago
I should write that I'm joking here in case someone else comes in the chat doesn't realise it. @NanoBit and @garyaustin knows the Prisma issues better than me so best they handle it.
sebx
sebxOP3y ago
prisma version 4.3.1, production db not sure about supabase version, but it's the one running on the platform using supabase-js@2.0.5 though
garyaustin
garyaustin3y ago
I believe the issue is you are in the middle of the conversion from supabase_admin to Postgres as the UI user. You need to temp modify that Prisma process to add your ui user you showed.
sebx
sebxOP3y ago
hmm not sure what you mean by modifying prisma process
garyaustin
garyaustin3y ago
The grant script does not have postgres_temporary_object_holder in the assignments at the end.
sebx
sebxOP3y ago
is there a grant in the script that should be modified?
NanoBit
NanoBit3y ago
While I cannot comment on the grant script and modifying it (as I have not migrated the UI user yet), would you be able to test if fixing the column names help fix RLS issue? or is this purely a GRANT issue?
garyaustin
garyaustin3y ago
I'm just guessing at the grant part, that should only affect modifying the tables from the UI as currently your grants do not include postgres_temporary_object_holder as having permission on the tables.
In almost all of the lines there is assignment to postgres, anon, authenticated, service_role; that is missing postgres_temporary_object_holder I suspect for the moment postgres_temporary_object_holder has to be added to all of those. This is all based on this: https://github.com/supabase/supabase/discussions/9314 I suspect they did not think about this Prisma script in interim period. BUT I'm not really that up to speed on this middle time period.
GitHub
Security Patch Notice · Discussion #9314 · supabase/supabase
Security Patch Notice To better secure your Supabase server instances, we will be removing superuser access from the dashboard SQL Editor over the next 30 days. Existing projects with tables, funct...
garyaustin
garyaustin3y ago
I've asked in that discussion about this case.
NanoBit
NanoBit3y ago
I suspect they did not think about this Prisma script in interim period. BUT I'm not really that up to speed on this middle time period.
This ... could also be bad for me
garyaustin
garyaustin3y ago
Have you run the script they provided for the admin user change?
NanoBit
NanoBit3y ago
I have not..
For any projects not migrated after 5 Nov deadline, we will run the migration on your behalf to reassign all entities to postgres role. No temporary role can be used for rollback.
I saw this and thought that it would be fine.. Whoops, sorry for hijacking the thread. I'll test things out, but everything seems fine.
garyaustin
garyaustin3y ago
sebx has run the admin user change script so is in the middle state until Supabase does what ever they plan to do.
sebx
sebxOP3y ago
Gonna have to pick this up in the morning guys, I’ll run some tests based on your messages and get back to you 👍
garyaustin
garyaustin3y ago
https://github.com/supabase/supabase/discussions/9314#discussioncomment-4082332 Seems like the script was OK just generating false supabase_admin errors as the temp user has postgres user privileges.
GitHub
Security Patch Notice · Discussion #9314 · supabase/supabase
Security Patch Notice To better secure your Supabase server instances, we will be removing superuser access from the dashboard SQL Editor over the next 30 days. Existing projects with tables, funct...
sebx
sebxOP3y ago
So it would seem that the issues might be relating to a mismatch of permissions applied to supabase created tables and prisma created ones. New prisma created tables aren't working properly with supabase permissions AND same applies to the other way around: prisma doesn't have persmission to modify tables newly created via supabase ui Verified by duplicating the prisma generated table on supabase and being able to access it without any issues using the js-client Then in prisma changing the @map() to the duplicated table (invites_duplicate) and running prisma db push
Error: db error: ERROR: must be owner of table invites_duplicate
Error: db error: ERROR: must be owner of table invites_duplicate
NanoBit
NanoBit3y ago
Would creating everything again via prisma (or your ORM of choice) work?
sebx
sebxOP3y ago
To fix the permissions, right? I'm not sure i trust it to fix itself honestly 😅
NanoBit
NanoBit3y ago
I see. Well, I might upgrade my supabase later for the new migration and update you if I have any similar issues. However, all of my table is created via prisma(postgres role), so I prob won't have your issue..
sebx
sebxOP3y ago
Should I just wait until the migration has been applied for my account then?
NanoBit
NanoBit3y ago
If there is no rush, that can be done. Or spin up another test db or work on local db for now
sebx
sebxOP3y ago
I think it's having more impacts on things than i realized... Looks like joining related data isn't giving me the results it usually does Joins don't work on the client (RLS disabled), unless using service key
await supabaseClient.from("invites_duplicate")
.select("*,profiles(*)")
// returns {profiles: null}
await supabaseClient.from("invites_duplicate")
.select("*,profiles(*)")
// returns {profiles: null}
This works in supabase SQL editor, no problem
select * from invites_duplicate join profiles on profiles.id = invites_duplicate.from_id;
select * from invites_duplicate join profiles on profiles.id = invites_duplicate.from_id;
since prisma created tables are where the issues seem to stem from, I don't know if I trust resetting the db via prisma.. Is there another way to reset the permissions?
NanoBit
NanoBit3y ago
Uhm,is there a reason you're using supabaseClient if you have prisma? Could we backtrack a bit, and may I ask why are you using Prisma? Is it just for migration?
sebx
sebxOP3y ago
literally just for migrations and handling relations etc. Easier learning curve than sql lmao Prisma client queries take several seconds compared to supabase client, so i switched 🤷‍♂️
silentworks
silentworks3y ago
Does Prisma work client side too? or is it server-side only?
NanoBit
NanoBit3y ago
Prisma client queries take several seconds compared to supabase client
Hm, is there something wrong? Locally, prisma queries on API route take 50-100ms+ depending on calculations I think.
literally just for migrations and handling relations etc.
I'm not sure Prisma Migration is that good yet alone.. It'll be good when you can utilize the whole Prisma ecosystem. Server only.. (need nodejs runtime)
sebx
sebxOP3y ago
Yea I'm not running a local db — what kinds of query times are you seeing for production / non-local requests with prisma?
NanoBit
NanoBit3y ago
Without cold start and cache, around 400ms to 2k ms. Depends also on Vercel. I’m not sure it’s due to prisma or other factors like being serverless.
sebx
sebxOP3y ago
Hmm okay, strange Anyways i’m not really sure what to do… i tried finalizing the super admin migration and didn’t change anything… I need to make changes to my production db… so this is pretty concerning
NanoBit
NanoBit3y ago
How long did you say your requests took? What is several seconds? Would it be possible to benchmark on a local db as well to make sure it’s not prisma’s fault?
sebx
sebxOP3y ago
I still use prisma for some more complex queries that I couldn't replicate with the supabase client -- so here's a log from production: [LONG QUERY - 2498ms] Subscription.findMany Typically it's around 2-4seconds Note: Although I only use it for complex queries, simple select queries took just as long... Sure perhaps after I get this whole permissions mess figured out -- feel like I've been locked out of my database at the moment
NanoBit
NanoBit3y ago
2498 ms from your browser or from Vercel’s api route duration? With cold boot or without?
sebx
sebxOP3y ago
From a docker instance running on aws not sure what would categorize it as a cold boot since it's just a few prisma queries that run, but doesn't seem to matter -- it was happening with every query even back to back Here's another one -- same query took 3958ms
NanoBit
NanoBit3y ago
Oh I thought you were running on Vercel. This is not serverless then right If you’re not using serverless, I’m not sure if you should use pgbouncer(?). Wouldn’t a direct connection be cheaper

Did you find this page helpful?