How can I create an AS RESTRICTIVE RLS policy on storage.objects in hosted Supabase? #52150
|
Hi Supabase community, I'm using a hosted Supabase project on the Free plan and need to create an RLS policy on AS RESTRICTIVE
FOR INSERT
TO authenticatedThis policy is intended to restrict existing PERMISSIVE INSERT policies. Replacing it with another PERMISSIVE policy would change the intended security behavior. What I've checked:
My questions:
I want to follow the supported security model and avoid changing managed object ownership or granting elevated privileges. Thank you for any guidance or links to official documentation. |
Replies: 4 comments 3 replies
|
The SQL editor can create policies on storage.objects. You just don't use alter table method to do it. |
|
Here is the direct technical answer to all four of your questions regarding 1. Is
|
|
The SQL in the replies runs, but the explanation isn't right, and two details change what the policy actually does. Why select current_user, current_setting('supautils.policy_grants', true);
create policy restrict_insert on storage.objects
as restrictive for insert to authenticated
with check (bucket_id <> 'your-bucket' or owner_id = (select auth.jwt() ->> 'sub'));
create policy restrict_update on storage.objects
as restrictive for update to authenticated
using (bucket_id <> 'your-bucket' or owner_id = (select auth.jwt() ->> 'sub'))
with check (bucket_id <> 'your-bucket' or owner_id = (select auth.jwt() ->> 'sub'));Restrictive policies only narrow access: a request still needs a permissive policy, they apply only to the roles in |
|
Your question 2 has a precise answer, and it is worth checking first because it changes the whole path: since PostgreSQL 15, select has_table_privilege(current_user, 'storage.objects', 'MAINTAIN') as can_create_policy;
The Dashboard Storage editor creates permissive policies only, so it cannot express this regardless. The two supported routes when the check returns false
A restrictive policy is an additional filter that every write must also satisfy. It only earns its keep when a permissive policy matches broadly and you want to carve an exception out of it. If the permissive INSERT policies on select polname, polcmd, polroles::regrole[], pg_get_expr(polqual, polrelid) as using_expr, pg_get_expr(polwithcheck, polrelid) as with_check
from pg_policy
where polrelid = 'storage.objects'::regclass
order by polcmd;If the list shows permissive INSERT policies beyond the one you write, go the support route — RESTRICTIVE is the only mechanism that intersects them. One caution on the free plan: nothing about this is plan-gated; it is the same ownership model on every hosted project. The plan only matters for support response times, not for whether the mechanism exists. Do not reach for |
The SQL editor can create policies on storage.objects. You just don't use alter table method to do it.
https://supabase.com/docs/guides/storage/security/access-control#policy-examples
Shows SQL examples that work from the SQL editor.