Issues creating application RLS policies on storage.objects
#49806
Replies: 3 comments
|
Short version: on a hosted Supabase project, plain To your specific questions:
Can you paste the exact SQL you're running? I'd bet it includes an create policy "users read own files"
on storage.objects for select
to authenticated
using (
bucket_id = 'avatars'
and (storage.foldername(name))[1] = (select auth.uid()::text)
);If you're still blocked, reproduce it in the SQL editor as |
|
Your diagnostics are all accurate, but they describe a restriction that doesn't actually gate Why ownership isn't the blocker hereUpstream Postgres does say "You must be the owner of a table to create or change policies for it." So your inference is reasonable — it's just that the hosted platform carves this case out deliberately:
So What's most likely actually failingYou said you're not trying to alter table storage.objects enable row level security; -- ❌ fails: must be owner of table objects
create policy "..." on storage.objects ...; -- never runsTwo things make this bite harder than it looks:
Drop the create policy "authenticated can upload to own folder"
on storage.objects
for insert
to authenticated
with check (
bucket_id = 'my-bucket'
and (storage.foldername(name))[1] = auth.uid()::text
);Note If you're going through the CLI
To answer your actual question directlyThere is no special role, That last part is the useful test: run only the |
|
Storage policies are separate from table RLS. The Required policies for bucket -- Allow authenticated uploads
CREATE POLICY "auth_upload" ON storage.objects
FOR INSERT TO authenticated
WITH CHECK (bucket_id = 'my-bucket');
-- Allow authenticated full access
CREATE POLICY "auth_full" ON storage.objects
FOR ALL TO authenticated
USING (bucket_id = 'my-bucket');
-- Allow public reads (if bucket is public)
CREATE POLICY "public_read" ON storage.objects
FOR SELECT TO anon
USING (bucket_id = 'my-bucket');Verify bucket exists and is public/private correctly: SELECT id, name, public FROM storage.buckets WHERE id = 'my-bucket';The service_role key works because it bypasses ALL RLS — that's expected behavior. Free Storage + RLS audit: https://github.com/cekuu35/supabase-rls-leak-demo |
Uh oh!
There was an error while loading. Please reload this page.
We are trying to create application RLS policies on
storage.objectsin a newly created hosted Supabase project.The SQL Editor session reports:
current_user = postgressession_user = postgrespostgresis not a superuserstorage.objectsis owned bysupabase_storage_adminpostgresis not a member ofsupabase_storage_adminpostgrescannotSET ROLEtosupabase_storage_adminstorage.objectsWe only need to execute
CREATE POLICY ... ON storage.objects; we are not trying to alter the Storage table, change its owner, disable/enable RLS, or modify the Storage schema.Supabase's Storage documentation documents
CREATE POLICY ... ON storage.objects, and the schema-restriction guidance states that creating RLS policies onstorage.objectsremains permitted.Under the current hosted-project permission model, what is the officially supported and reproducible way to execute
CREATE POLICYonstorage.objects?Specifically:
postgresrole normally have indirect ownership authority overstorage.objects?supabase_storage_admin?SET ROLE supabase_storage_adminintentionally unavailable topostgres?We do not want to grant ourselves membership in
supabase_storage_admin, change table ownership, or otherwise work around Supabase's privilege model. We want to use the officially supported mechanism.All reactions