The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(docs): use more restrictive RLS policies for storage in example projects (#46172)
Lenny2a8dc75e3d89
diff --git a/apps/docs/content/_partials/user_management_quickstart_sql_template.mdx b/apps/docs/content/_partials/user_management_quickstart_sql_template.mdxindex 28f790a6d37..276bdfef8ab 100644--- a/apps/docs/content/_partials/user_management_quickstart_sql_template.mdx+++ b/apps/docs/content/_partials/user_management_quickstart_sql_template.mdx@@ -49,10 +49,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.+-- Set up access controls for storage. Allows downloading object with public key-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/apps/docs/content/guides/storage/security/access-control.mdx b/apps/docs/content/guides/storage/security/access-control.mdxindex 909896d1a62..075c5a89dc3 100644--- a/apps/docs/content/guides/storage/security/access-control.mdx+++ b/apps/docs/content/guides/storage/security/access-control.mdx@@ -85,6 +85,19 @@ to authenticatedusing ( (select auth.jwt()->>'sub') = owner_id );```+Allow anyone to access objects in the `avatars` bucket via publishable key. The `allow_any_operation()` filter is critical here as without it users would be able to list the bucket contents.++<Admonition type="note">++This is not needed for public buckets, as they are already publicly accessible++</Admonition>++```sql+create policy "Avatar images are publicly accessible." on storage.objects+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));+```+---{/* Finish with a video. This also appears in the Sidebar via the "tocVideo" metadata */}diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.queries.ts b/apps/studio/components/interfaces/SQLEditor/SQLEditor.queries.tsindex 775c121953b..2f42bc16365 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.queries.ts+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.queries.ts@@ -935,10 +935,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.--- See ${DOCS_URL}/guides/storage#policy-examples for more details.+-- Set up access controls for storage. Allows downloading object with public key+-- See ${DOCS_URL}/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/examples/user-management/angular-user-management/README.md b/examples/user-management/angular-user-management/README.mdindex 9f900f55c3b..224c97d330b 100644--- a/examples/user-management/angular-user-management/README.md+++ b/examples/user-management/angular-user-management/README.md@@ -46,9 +46,10 @@ create policy "Users can update own profile." on profilesinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/examples/user-management/expo-user-management/README.md b/examples/user-management/expo-user-management/README.mdindex c99d084921a..9add39ff072 100644--- a/examples/user-management/expo-user-management/README.md+++ b/examples/user-management/expo-user-management/README.md@@ -107,9 +107,11 @@ insert intovalues('avatars', 'avatars');+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects forselect- using (bucket_id = 'avatars');+ using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objects for insertwithdiff --git a/examples/user-management/expo-user-management/supabase/migrations/20240403090422_init.sql b/examples/user-management/expo-user-management/supabase/migrations/20240403090422_init.sqlindex 7c102c555fa..d6af1e53e94 100644--- a/examples/user-management/expo-user-management/supabase/migrations/20240403090422_init.sql+++ b/examples/user-management/expo-user-management/supabase/migrations/20240403090422_init.sql@@ -41,10 +41,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.--- See https://supabase.com/docs/guides/storage#policy-examples for more details.+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/examples/user-management/nextjs-user-management/README.md b/examples/user-management/nextjs-user-management/README.mdindex 894e1818a38..067ff011a33 100644--- a/examples/user-management/nextjs-user-management/README.md+++ b/examples/user-management/nextjs-user-management/README.md@@ -186,10 +186,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.--- See https://supabase.com/docs/guides/storage#policy-examples for more details.+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/examples/user-management/nextjs-user-management/supabase/migrations/20221017024722_init.sql b/examples/user-management/nextjs-user-management/supabase/migrations/20221017024722_init.sqlindex 7c102c555fa..d6af1e53e94 100644--- a/examples/user-management/nextjs-user-management/supabase/migrations/20221017024722_init.sql+++ b/examples/user-management/nextjs-user-management/supabase/migrations/20221017024722_init.sql@@ -41,10 +41,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.--- See https://supabase.com/docs/guides/storage#policy-examples for more details.+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');diff --git a/examples/user-management/solid-user-management/README.md b/examples/user-management/solid-user-management/README.mdindex 0a3e64f206d..46e147af84a 100644--- a/examples/user-management/solid-user-management/README.md+++ b/examples/user-management/solid-user-management/README.md@@ -116,9 +116,11 @@ insert intovalues('avatars', 'avatars');+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects forselect- using (bucket_id = 'avatars');+ using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objects for insertwithdiff --git a/examples/user-management/svelte-user-management/README.md b/examples/user-management/svelte-user-management/README.mdindex a3e7568de3b..57f71249ce8 100644--- a/examples/user-management/svelte-user-management/README.md+++ b/examples/user-management/svelte-user-management/README.md@@ -114,9 +114,11 @@ insert intovalues('avatars', 'avatars');+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects forselect- using (bucket_id = 'avatars');+ using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objects for insertwithdiff --git a/examples/user-management/swift-user-management/supabase/migrations/20240403090422_init.sql b/examples/user-management/swift-user-management/supabase/migrations/20240403090422_init.sqlindex 7c102c555fa..d6af1e53e94 100644--- a/examples/user-management/swift-user-management/supabase/migrations/20240403090422_init.sql+++ b/examples/user-management/swift-user-management/supabase/migrations/20240403090422_init.sql@@ -41,10 +41,10 @@ create trigger on_auth_user_createdinsert into storage.buckets (id, name)values ('avatars', 'avatars');--- Set up access controls for storage.--- See https://supabase.com/docs/guides/storage#policy-examples for more details.+-- Set up access controls for storage. Allows downloading object with public key+-- See https://supabase.com/docs/guides/storage/security/access-control#policy-examples for more details.create policy "Avatar images are publicly accessible." on storage.objects- for select using (bucket_id = 'avatars');+ for select using (bucket_id = 'avatars' and storage.allow_any_operation(array['object.get_authenticated_info', 'object.get_authenticated']));create policy "Anyone can upload an avatar." on storage.objectsfor insert with check (bucket_id = 'avatars');