The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Break out Access Control docs
dannykng33aa78fa88d9
diff --git a/apps/docs/components/Navigation/Navigation.constants.ts b/apps/docs/components/Navigation/Navigation.constants.tsindex 565d27b4ce8..8000e07e607 100644--- a/apps/docs/components/Navigation/Navigation.constants.ts+++ b/apps/docs/components/Navigation/Navigation.constants.ts@@ -245,6 +245,7 @@ export const menuItems: NavMenu = {items: [{ name: 'Overview', url: '/guides/storage', items: [] },{ name: 'Quickstart', url: '/guides/storage/quickstart', items: [] },+ { name: 'Access Control', url: '/guides/storage/access-control', items: [] },{ name: 'CDN', url: '/guides/storage-cdn', items: [] },],},diff --git a/apps/docs/pages/guides/storage.mdx b/apps/docs/pages/guides/storage.mdxindex f9def048f2b..fd024d292c8 100644--- a/apps/docs/pages/guides/storage.mdx+++ b/apps/docs/pages/guides/storage.mdx@@ -34,138 +34,6 @@ keep all video files in a "video" bucket, and profile pictures in an "avatar" bu></iframe></div>-### Public and Private Buckets--Storage buckets are private by default.--For private buckets, you can access objects via the [download](/docs/reference/javascript/storage-from-download) method. This corresponds to `/object/auth/` API endpoint.-Alternatively, you can create a publicly shareable URL with an expiry date using the [createSignedUrl](/docs/reference/javascript/storage-from-createsignedurl) method-which calls the `/object/sign/` API.--For public buckets, you can access the assets directly without a token or an Authorisation header. The [getPublicUrl](/docs/reference/javascript/storage-from-getpublicurl)-helper method returns the full public URL for an asset. This calls the `/object/public/` API endpoint internally. While no authorization is required for accessing objects in a public bucket, proper [access control](#access-control) is required for other operations like uploading, deleting objects from public buckets as well. Public buckets also tend to have [better performance](/docs/guides/storage-cdn#public-vs-private-buckets).--<details>-<summary>Advanced: reverse proxy</summary>-The URLs returned are proxied through the API Proxy. They are prefixed by <code>/storage/v1</code>.--For example, on the hosted Platform they will be--<code>https://[project_ref].supabase.co/storage/v1/object/public/[id]</code>--You can access the storage API directly with the same endpoint. See the <a href="https://supabase.github.io/storage-api">API docs</a> for a full list of operations available.--</details>-------## Access control--Supabase Storage is integrated with your [Postgres Database](/docs/guides/database).-This means that you can use the same [Row Level Security Policies](/docs/guides/auth#policies)-for managing access to your files. Supabase Storage stores metadata in the `objects` and `buckets` table in the storage schema. To allow read access to files, the RLS policy must allow users to `SELECT` the `objects` table and for uploading a new object, the RLS policy must grant users access to `INSERT` into the `objects` table and so on. The mapping between the different API calls and the database permissions required is documented in the [Reference docs](/docs/reference/javascript/storage-createbucket).--<Admonition type="note">--Access control for Storage is mapped to CRUD operations on the `buckets` and `objects` table via RLS policies.--</Admonition>--<div className="video-container">- <iframe- src="https://www.youtube-nocookie.com/embed/4ERX__Y908k"- frameBorder="1"- allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"- allowFullScreen- ></iframe>-</div>--## Helpers--Supabase Storage provides SQL helper functions which you can use in your database queries and-policies.-------#### `storage.filename()`--Returns the name of a file.--```sql-select storage.filename(name)-from storage.objects;-```--For example, if your file is stored in `public/subfolder/avatar.png` it would return:--`'avatar.png'`-------#### `storage.foldername()`--Returns an array path, with all of the subfolders that a file belongs to.--```sql-select storage.foldername(name)-from storage.objects;-```--For example, if your file is stored in `public/subfolder/avatar.png` it would return:--`[ 'public', 'subfolder' ]`-------#### `storage.extension()`--Returns the extension of a file.--```sql-select storage.extension(name)-from storage.objects;-```--For example, if your file is stored in `public/subfolder/avatar.png` it would return:--`'png'`-------## Policy examples--Here are some examples of storage policies.--### Allow public access to a bucket--```sql--- 1. Allow public access to any files in the "public" bucket-create policy "Public Access"-on storage.objects for select-using ( bucket_id = 'public' );-```--### Allow logged-in access to a bucket--```sql--- 1. Allow logged-in access to any files in the "restricted" bucket-create policy "Restricted Access"-on storage.objects for select-using (- bucket_id = 'restricted'- and auth.role() = 'authenticated'-);-```--### Allow individual access to a file--```sql--- 1. Allow a user to access their own files-create policy "Individual user Access"-on storage.objects for select-using ( auth.uid() = owner );-```-## See also- Read more about Supabase Storage in the [blog post](https://supabase.com/blog/supabase-storage)diff --git a/apps/docs/pages/guides/storage/access-control.mdx b/apps/docs/pages/guides/storage/access-control.mdxnew file mode 100644index 00000000000..58572bd789e--- /dev/null+++ b/apps/docs/pages/guides/storage/access-control.mdx@@ -0,0 +1,137 @@+import Layout from '~/layouts/DefaultGuideLayout'++export const meta = {+ id: 'storage-access-control',+ title: 'Access Control',+ description: 'Manage who can access your Supabase Storage files.',+}++Supabase Storage is integrated with your [Postgres Database](/docs/guides/database).+This means that you can use the same [Row Level Security Policies](/docs/guides/auth#policies)+for managing access to your files. Supabase Storage stores metadata in the `objects` and `buckets` table in the storage schema.++To allow read access to files, the RLS policy must allow users to `SELECT` the `objects` table and for uploading a new object, the RLS policy must grant users access to `INSERT` into the `objects` table and so on. The mapping between the different API calls and the database permissions required is documented in the [Reference docs](/docs/reference/javascript/storage-createbucket).++<Admonition type="note">++Access control for Storage is mapped to CRUD operations on the `buckets` and `objects` table via RLS policies.++</Admonition>++<div className="video-container">+ <iframe+ src="https://www.youtube-nocookie.com/embed/4ERX__Y908k"+ frameBorder="1"+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"+ allowFullScreen+ ></iframe>+</div>++## Public and private buckets++Storage buckets are private by default. For private buckets, you can access objects via the [download](/docs/reference/javascript/storage-from-download) method. This corresponds to `/object/auth/` API endpoint.+Alternatively, you can create a publicly shareable URL with an expiry date using the [createSignedUrl](/docs/reference/javascript/storage-from-createsignedurl) method+which calls the `/object/sign/` API.++For public buckets, you can access the assets directly without a token or an Authorisation header. The [getPublicUrl](/docs/reference/javascript/storage-from-getpublicurl)+helper method returns the full public URL for an asset. This calls the `/object/public/` API endpoint internally. While no authorization is required for accessing objects in a public bucket, proper [access control](#access-control) is required for other operations like uploading, deleting objects from public buckets as well. Public buckets also tend to have [better performance](/docs/guides/storage-cdn#public-vs-private-buckets).++<details>+<summary>Advanced: reverse proxy</summary>+The URLs returned are proxied through the API Proxy. They are prefixed by <code>/storage/v1</code>.++For example, on the hosted Platform they will be++<code>https://[project_ref].supabase.co/storage/v1/object/public/[id]</code>++You can access the storage API directly with the same endpoint. See the <a href="https://supabase.github.io/storage-api">API docs</a> for a full list of operations available.++</details>++## Helper functions++Supabase Storage provides SQL helper functions which you can use in your database queries and+policies.++---++#### `storage.filename()`++Returns the name of a file.++```sql+select storage.filename(name)+from storage.objects;+```++For example, if your file is stored in `public/subfolder/avatar.png` it would return:++`'avatar.png'`++---++#### `storage.foldername()`++Returns an array path, with all of the subfolders that a file belongs to.++```sql+select storage.foldername(name)+from storage.objects;+```++For example, if your file is stored in `public/subfolder/avatar.png` it would return:++`[ 'public', 'subfolder' ]`++---++#### `storage.extension()`++Returns the extension of a file.++```sql+select storage.extension(name)+from storage.objects;+```++For example, if your file is stored in `public/subfolder/avatar.png` it would return:++`'png'`++---++## Policy examples++### Allow public access to a bucket++```sql+-- 1. Allow public access to any files in the "public" bucket+create policy "Public Access"+on storage.objects for select+using ( bucket_id = 'public' );+```++### Allow logged-in access to a bucket++```sql+-- 1. Allow logged-in access to any files in the "restricted" bucket+create policy "Restricted Access"+on storage.objects for select+using (+ bucket_id = 'restricted'+ and auth.role() = 'authenticated'+);+```++### Allow individual access to a file++```sql+-- 1. Allow a user to access their own files+create policy "Individual user Access"+on storage.objects for select+using ( auth.uid() = owner );+```++export const Page = ({ children }) => <Layout meta={meta} children={children} />++export default Page