RLS Error Uploading to Supabase Storage Bucket Using Service Role Key #37611
Replies: 3 comments 6 replies
|
The service role does bypass RLS. It is common for users to not create a separate service_role client in their server side code and then a user session will get into that client instead of the default from the apikey. You must have a separate "admin" client and not also use the same client for user access. There is one other odd case but I'll have to see if I can find it where there is a grant error or something odd that I can't recall than manifests as an RLS error. The most common case is the one above. Edit: |
|
Sorry to reuse or bring this question back. I was trying to apply some RBAC authorization policies to my uploads, based on Supabase RBAC Docs Then when I dropped my custom policies to update their checks and behabiour, I got locked. DROP POLICY "Authorized users can upload files" ON storage.objects;
DROP POLICY "Authorized users can view files" ON storage.objects;
DROP POLICY "Authorized users can update files" ON storage.objects;
DROP POLICY "Authorized users can delete files" ON storage.objects;Now using Supabase Studio I cannot upload to any bucket, public/private, newly created or whatever. The service role is not bypassing RLS anymore and I got stuck. I try to upload a file to my bucket from supabase studio, the progress bar reach 100% and it just disappears giving a 403 error with the message "new row violates row-level security policy" I fear to broke storage policies and now I don't know to restore the default service key RLS bypass policies. |
|
I found the issue, we had a trigger on storage to execute a function to process files. The function wasn't fully functinal, failing. The most confusing part, is the all errors related to this were comming in a form of RLS issue, pointing me in the wrong direction. Another member of the team created the trigger to work on the function that process files uploaded. I wasn't aware of that, and also I didn't think that if a trigger(after create) fails to execute a function, the file is not even added. So be careful about triggers applied over supabase internal schemas, ther could be some side effects like this, more difficult to track. I will try to use a webhook instead. Anyways thanks for the help and attentiont provided ✌️ |



Uh oh!
There was an error while loading. Please reload this page.
Hi Supabase team,
I'm encountering an RLS error when trying to upload audio files to a Supabase Storage bucket (audio) from my backend server using the SUPABASE_SERVICE_ROLE_KEY. The upload fails with the following message:
StorageApiError: new row violates row-level security policy status: 400Here’s what I’ve verified:
I'm using the @supabase/storage-js SDK from a Node backend (running on Replit)
createClient(SUPABASE_URL, SUPABASE_SERVICE_ROLE_KEY) is used server-side
The file is a valid .webm with correct content-type
The bucket is audio, and the upload target is cleanly formatted
Replit support confirmed:
→ The Authorization header is not being overwritten
→ The service role key is being passed properly
My RLS policy on storage.objects:
CREATE POLICY "Service role can upload audio files" ON storage.objects FOR INSERT TO service_role WITH CHECK (bucket_id = 'audio');Even with this policy in place, the upload still fails unless I fully disable RLS on the bucket. Everything I’ve read suggests that the service role should either bypass RLS or this policy should be sufficient.
Is there any known issue where:
The service role doesn’t bypass RLS in Storage?
Storage policies require additional conditions?
Supabase fails to detect service role when using @supabase/storage-js directly in a Node backend?
Let me know what else I can try — happy to share more context if needed.
Thanks in advance!
All reactions