docs(storage): explain which policies a public bucket needs (#54558)

## Problem

The public buckets section says that anyone with a file's URL can
download it and that other operations still use access control. It
doesn't say which policies a public bucket needs, so readers can't tell
that a broad `SELECT` policy lets clients list the whole bucket, or that
writes stay blocked until a policy allows them.

Related to
[FDBKIN-5481](https://linear.app/supabase/issue/FDBKIN-5481/document-best-practices-for-securing-public-storage-buckets)
Closes
[DOCS-1852](https://linear.app/supabase/issue/DOCS-1852/explain-how-to-lock-down-a-public-storage-bucket)

## Solution

A new "Control access to a public bucket" subsection on the Storage
buckets page covers several points. Reads by public URL need no `SELECT`
policy, and a bucket-wide `SELECT` policy opens listing. Listing,
overwrites, moves, copies, and deletes each need a `SELECT` policy, so
the subsection says how to scope it to the user's objects and, with the
operation helpers, to the operations that need it. Writes stay blocked
until a scoped write policy allows them. It links the existing policy
examples, upload restrictions, and helper functions instead of repeating
them, and names the Security Advisor lint and the Dashboard warning that
flag a listable public bucket. The Related resources line for access
control now covers both bucket types.

Three related fixes support the new subsection. The public buckets intro
now says Storage skips access controls when it serves a file from a
public bucket, and names listing among the operations that still need
policies. The access control page has a sentence-case title and
descriptive link text instead of "here". "Restricting uploads" on the
Creating buckets page shows how to change limits on an existing bucket
with `updateBucket`, notes that the JavaScript SDK requires `public`,
and names the `fileSizeLimit` option correctly.

Both of those pages also lose old wording. The Creating buckets title is
in sentence case, and its intro and upload-rejection sentences no longer
use "Here we", "above", or the future tense. Its Restricting uploads
example sentence is shorter and writes "1 MB" with a space. The access
control intro and Policy examples drop "perfectly", "incredibly
powerful", and "An easy way", and the upsert sentence drops "you will
need to additionally grant".

The new title also appears in the docs nav entry for the page and in the
link text on the Storage upload limits page. The Dashboard steps for
creating a bucket, on the Creating buckets page and the Storage
quickstart, now use Studio's current labels: **New bucket** and
**Create**.

## How to verify

1. Open each changed page in the preview:
-
https://docs-git-tedd-docs-1852-supabase.vercel.app/docs/guides/storage/buckets/fundamentals#public-buckets
-
https://docs-git-tedd-docs-1852-supabase.vercel.app/docs/guides/storage/security/access-control#access-policies
-
https://docs-git-tedd-docs-1852-supabase.vercel.app/docs/guides/storage/buckets/creating-buckets#restricting-uploads
-
https://docs-git-tedd-docs-1852-supabase.vercel.app/docs/guides/storage/uploads/file-limits
-
https://docs-git-tedd-docs-1852-supabase.vercel.app/docs/guides/storage/quickstart
2. The "Control access to a public bucket" subsection says public URL
reads need no `SELECT` policy on `storage.objects`.
3. It says a bucket-wide `SELECT` policy lets clients list every object,
and that listing, overwrites, moves, copies, and deletes need a `SELECT`
policy scoped to the user's objects and the operations.
4. It says uploads and other writes stay blocked until a policy allows
them, and links Access policies and Policy examples.
5. It links Restricting uploads for file size and MIME type limits.
6. It says the Security Advisor flags a public bucket that allows
listing.
7. The public buckets intro says downloads from a public bucket skip
access controls, and that uploading, listing, deleting, moving, and
copying still need policies.
8. The access control page title is "Storage access control", and its
"Access policies" section has no "here" link text. The page has no
"perfectly", "incredibly powerful", "An easy way", or "you will need to
additionally grant".
9. The Creating buckets page title is "Creating buckets". Its intro has
no "Here we", the Restricting uploads example sentence has no "You can
achieve the following" and writes "1 MB", and the sentence after the
example has no "above" or "will be rejected".
10. "Restricting uploads" has an `updateBucket` snippet with `public:
true` and a sentence that the JavaScript SDK requires `public`.
11. The Storage nav shows "Creating buckets" for that page, and the
Storage upload limits page links it as "Creating buckets".
12. The Dashboard tabs on the Creating buckets page and the Storage
quickstart say **New bucket** and **Create**.
13. Each changed link opens the right page and section, including the
`0025_public_bucket_allows_listing` tab on the Advisors page.

## Checks

Ran `pnpm exec oxfmt --check` on the changed files, and `eslint` on
`NavigationMenu.constants.ts`. The `updateBucket` snippet typechecks
with its hidden setup (`tsc --ignoreConfig --moduleResolution bundler
--module esnext --skipLibCheck`). MDX has no ESLint config in apps/docs.
Behavior was checked against `supabase/storage` and against a local
stack running storage-api v1.98.7. Public downloads skip RLS, both
through the public URL and through `download()`, because `getObject.ts`
reads public-bucket objects as superuser. Listing and writes go through
RLS. Delete, move, copy, and upsert fail without a `SELECT` policy and
work with a scoped one. `updateBucket` leaves omitted fields unchanged.
The Advisor claim was checked against splinter lint 0025, and the
Dashboard warning against Studio's `PublicBucketWarning`. The Dashboard
labels come from Studio's `NewBucketButton` and `CreateBucketModal`.
Skipped `pnpm build:guides-markdown`, which needs GitHub credentials for
federated content.

## Follow-ups

- The JavaScript reference for `update()` says it needs `update` and
`select` on `storage.objects`. A local run on storage-api v1.98.7 showed
that it also needs `insert`. That text comes from supabase-js, so this
PR can't fix it.

## Checklist

- [x] I have read the [Contributing
Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] I have checked that the change follows the docs style guide
- [ ] I have checked that the change works in the preview deployment

## Feedback for Tedd

To ask Tedd for a change to this PR, reply in Tedd's session on
[DOCS-1852](https://linear.app/supabase/issue/DOCS-1852/explain-how-to-lock-down-a-public-storage-bucket).
Tedd doesn't read comments on this PR.

---------

Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com>
Co-authored-by: alexisintech <98043211+alexisintech@users.noreply.github.com>
This commit is contained in:
supabase-vercel-tedd[bot]andalexisintech authored and GitHub committed 2026-12-03 16:10:00 -07:00
1 parent 7c9b65e21d
commit 9ca221ee86
6 files changed
+42 -21

No files matched your search

@@ -2112,7 +2112,7 @@ export const storage: NavMenuConstant = {
{ name: 'Quickstart', url: '/guides/storage/quickstart' },
{ name: 'Fundamentals', url: '/guides/storage/buckets/fundamentals' },
{
name: 'Creating Buckets',
name: 'Creating buckets',
url: '/guides/storage/buckets/creating-buckets' as `/${string}`,
},
{
@@ -1,13 +1,13 @@
---
id: 'storage-creating-buckets'
title: 'Creating Buckets'
title: 'Creating buckets'
description: 'Learn how to create Supabase Storage buckets.'
sidebar_label: 'Buckets'
tocVideo: ch2UGHMreB0
---
You can create a bucket using the Supabase Dashboard. Since storage is interoperable with your Postgres database, you can also use SQL or our client libraries.
Here we create a bucket called "avatars":
The following code examples create a bucket called `avatars`:
<Tabs
scrollable
@@ -37,8 +37,8 @@ const { data, error } = await supabase.storage.createBucket('avatars', {
<TabPanel id="dashboard" label="Dashboard">
1. Go to the [Storage](/dashboard/project/_/storage/buckets) page in the Dashboard.
2. Click **New Bucket** and enter a name for the bucket.
3. Click **Create Bucket**.
2. Click **New bucket** and enter a name for the bucket.
3. Click **Create**.
</TabPanel>
<TabPanel id="sql" label="SQL">
@@ -115,7 +115,7 @@ var bucket = await supabase.Storage.CreateBucket("avatars", new BucketUpsertOpti
When creating a bucket you can add additional configurations to restrict the type or size of files you want this bucket to contain.
For example, imagine you want to allow your users to upload only images to the `avatars` bucket and the size must not be greater than 1MB. You can achieve the following by providing `allowedMimeTypes` and `maxFileSize`:
For example, to allow only images of up to 1 MB in the `avatars` bucket, set `allowedMimeTypes` and `fileSizeLimit`:
```js
import { createClient } from '@supabase/supabase-js'
@@ -131,4 +131,19 @@ const { data, error } = await supabase.storage.createBucket('avatars', {
})
```
If an upload request doesn't meet the above restrictions it will be rejected. See [File Limits](/docs/guides/storage/uploads/file-limits) for more information.
Storage rejects an upload that doesn't meet the bucket's restrictions. For more information, see [Storage upload limits](/docs/guides/storage/uploads/file-limits).
To change the restrictions of an existing bucket, call `updateBucket`. The JavaScript SDK requires `public`, so pass the bucket's current value to keep its visibility. `getBucket` returns that value.
```js
import { createClient } from '@supabase/supabase-js'
const supabase = createClient('your_project_url', 'your_supabase_api_key')
// ---cut---
await supabase.storage.updateBucket('avatars', {
public: true,
allowedMimeTypes: ['image/*'],
fileSizeLimit: '1MB',
})
```
@@ -35,9 +35,9 @@ The following are example use cases for private buckets:
## Public buckets
When a bucket is set to **Public**, it bypasses access controls for both retrieving and serving files within the bucket. Anyone with the asset URL can access the file.
When a bucket is set to **Public**, anyone with a file's public URL can download it. Storage skips access controls when it serves a file from a public bucket.
[Access control is still enforced](/kb/troubleshooting/why-cant-i-uploadlistetc-my-public-bucket-Z6CmGt) for other types of operations including uploading, deleting, moving, and copying.
[Access control is still enforced](#control-access-to-a-public-bucket) for other operations, including uploading, listing, deleting, moving, and copying.
The following are example use cases for public buckets:
@@ -47,8 +47,14 @@ The following are example use cases for public buckets:
Public buckets get a better cache hit rate than private buckets, because they're [cached differently](/docs/guides/storage/cdn/fundamentals#public-vs-private-buckets).
### Control access to a public bucket
A public bucket needs no policy for downloads by URL, so don't add a `SELECT` policy to make files readable. A `SELECT` policy that matches the whole bucket, such as `using (bucket_id = 'avatars')`, lets clients list every object in it.
Listing, overwrites, moves, copies, and deletes each need a `SELECT` policy. Scope it to the user's own objects with an `owner_id` or folder check. For the permissions each operation needs, see [Access policies](/docs/guides/storage/security/access-control#access-policies). The [Security Advisor](/docs/guides/observability/advisors?lint=0025_public_bucket_allows_listing) flags a public bucket that allows listing.
## Related resources
- [Creating buckets](/docs/guides/storage/buckets/creating-buckets): create a bucket and set upload restrictions.
- [Storage access control](/docs/guides/storage/security/access-control): write the RLS policies that private buckets use.
- [Storage access control](/docs/guides/storage/security/access-control): write the RLS policies that control file operations in your buckets.
- [Storage CDN](/docs/guides/storage/cdn/fundamentals): how public and private buckets are cached.
@@ -45,8 +45,8 @@ You can create a bucket using the Supabase Dashboard. Since the storage is inter
<TabPanel id="dashboard" label="Dashboard">
1. Go to the [Storage](/dashboard/project/_/storage/buckets) page in the Dashboard.
2. Click **New Bucket** and enter a name for the bucket.
3. Click **Create Bucket**.
2. Click **New bucket** and enter a name for the bucket.
3. Click **Create**.
</TabPanel>
<TabPanel id="sql" label="SQL">
@@ -1,14 +1,14 @@
---
id: 'storage-access-control'
title: 'Storage Access Control'
title: 'Storage access control'
description: 'Learn how to restrict Supabase file uploads.'
sidebar_label: 'Uploads'
tocVideo: '4ERX__Y908k'
---
Supabase Storage is designed to work perfectly with Postgres [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS).
Supabase Storage works with Postgres [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS).
You can use RLS to create [Security Access Policies](https://www.postgresql.org/docs/current/sql-createpolicy.html) that are incredibly powerful and flexible, allowing you to restrict access based on your business needs.
Use RLS to create [access policies](https://www.postgresql.org/docs/current/sql-createpolicy.html) that restrict access to match your app's requirements.
## Access policies
@@ -31,23 +31,23 @@ You need policies on `storage.buckets` only when clients call bucket methods. Ea
| Delete a bucket | `SELECT` and `DELETE` | None |
| Empty a bucket | `SELECT` | `SELECT` and `DELETE` |
You can find the documentation for the storage schema [here](/docs/guides/storage/schema/design) , and to simplify the process of crafting your policies, you can use these [helper functions](/docs/guides/storage/schema/helper-functions) .
For the tables and columns that policies check, see [Storage schema](/docs/guides/storage/schema/design).
If you need different `SELECT` policies for different Storage actions, such as listing objects versus reading authenticated objects, use the operation-aware helpers `storage.allow_only_operation()` and `storage.allow_any_operation()` documented in [Storage Helper Functions](/docs/guides/storage/schema/helper-functions).
If you need different `SELECT` policies for different Storage actions, such as listing objects versus reading authenticated objects, use the operation-aware helpers `storage.allow_only_operation()` and `storage.allow_any_operation()` documented in [Storage helper functions](/docs/guides/storage/schema/helper-functions).
<Admonition type="note">
The RLS policies required for different operations are documented [here](/docs/reference/javascript/file-buckets-createbucket)
The [JavaScript Storage reference](/docs/reference/javascript/file-buckets-createbucket) lists the RLS policies for each operation.
</Admonition>
For example, the only RLS policy required for [uploading](/docs/reference/javascript/file-buckets-upload) objects is to grant the `INSERT` permission to the `storage.objects` table.
To allow overwriting files using the `upsert` functionality you will need to additionally grant `SELECT` and `UPDATE` permissions.
To let users overwrite files with `upsert`, also grant the `SELECT` and `UPDATE` permissions.
## Policy examples
An easy way to get started would be to create RLS policies for `SELECT`, `INSERT`, `UPDATE`, `DELETE` operations and restrict the policies to meet your security requirements. For example, one can start with the following `INSERT` policy:
To get started, create RLS policies for `SELECT`, `INSERT`, `UPDATE`, and `DELETE` operations, and restrict them to meet your security requirements. For example, start with the following `INSERT` policy:
```sql
create policy "policy_name"
@@ -27,7 +27,7 @@ Additionally, you can specify the [maximum file size](/kb/troubleshooting/upload
## Per bucket restrictions
You can have different restrictions on a per bucket level such as restricting the file types (e.g. `pdf`, `images`, `videos`) or the maximum file size, which should be lower than the global limit. To apply these limits on a bucket level see [Creating Buckets](/docs/guides/storage/buckets/creating-buckets#restricting-uploads).
You can have different restrictions on a per bucket level such as restricting the file types (e.g. `pdf`, `images`, `videos`) or the maximum file size, which should be lower than the global limit. To apply these limits on a bucket level see [Creating buckets](/docs/guides/storage/buckets/creating-buckets#restricting-uploads).
## File name restrictions