Storage RLS to restrict top level folder name to a uuid an authenticated user can access #31073
|
I'm trying to create an RLS policy on Storage objects that restricts the top level folder name to match the id of an entry in a table which an authenticated user has access to. For example, if I want to restrict access to a normal table with RLS I can use a policy that looks like this: create policy "Allow authenticated users to select devices from their products"
on "public"."devices"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
FROM products
WHERE (products.id = devices.product_id))));This will allow the authenticated user access to entries in the I'd like to apply a similar strategy to a storage bucket. I want authenticated users to only be able to store files in a path that has a root folder of a BEGIN;
ALTER POLICY "Allows authenticated users to insert own assets" ON "storage"."objects"
WITH CHECK ((((bucket_id = 'assets'::text)
AND ((EXISTS (SELECT 1
FROM products
WHERE (products.id::text = (storage.foldername(name))[1])))))));
COMMIT;However, when I save this policy, Supabase modifies the SQL. When I go back to edit the policy I see the SQL has been changed from Is there a way to prevent my SQL from getting changed on save or is there some other approach I could use to accomplish my RLS goal here? Maybe I'm going about it the wrong way. |
Replies: 1 comment 1 reply
|
Because name is used in two tables involved it is picking the name from the table in the select. Try something like storage.objects.name. |
Because name is used in two tables involved it is picking the name from the table in the select. Try something like storage.objects.name.