Files
supabase/apps/docs/content/guides/storage/security/ownership.mdx
T
8864e5633c docs: storage s3 protocol (#22647)
* docs: storage s3 protocol

* fix: edits

* docs(storage): added ownership,management,custom-roles docs

* chore: fix prettier

* docs: fix formatting & rephrase some bits

* fix: edits

* add error codes documentation

* update docs

* Adds blog post

* Adds embeds

* chore: update images

* parquet video

* Update thumb.png

* some doc updates

* Adds compat list

* guide: cyberduck

* doc updates

* ga page data

* blog updates

* update image

* Update 2024-04-18-s3-compatible-storage.mdx

* Update supabase-contributions.png

* blog update

* moves cyberduck to integrations

* updated multipart section blog

* Update 2024-04-18-s3-compatible-storage.mdx

* update blog

* fix link

* blog updates

* update blog

* docs update

* update announcement banners

* update

* update build stage

* update

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
Co-authored-by: Kang Ming <kang.ming1996@gmail.com>
Co-authored-by: Inian <inian1234@gmail.com>
Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com>
Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>
Co-authored-by: Francesco Sansalvadore <francescosansalvadore@mac.wind3.hub>
2024-04-18 14:57:16 +02:00

40 lines
1.6 KiB
Plaintext

---
id: 'storage-access-control'
title: 'Ownership'
description: 'Learn how ownership works in Supabase Storage and how to control access'
sidebar_label: 'Security'
---
When creating new buckets or objects in Supabase Storage, an owner is automatically assigned to the bucket or object. The owner is the user who created the resource and the value is derived from the `sub` claim in the JWT.
We store the `owner` in the `owner_id` column.
<Admonition type="note">
When using the `service_key` to create a resource, the owner will not be set and the resource will be owned by anyone. This is also the case when you are creating Storage resources via the Dashboard.
</Admonition>
<Admonition type="note">
The Storage schema has 2 fields to represent ownership: `owner` and `owner_id`. `owner` is deprecated and will be removed. Use `owner_id` instead.
</Admonition>
## Access control
By itself, the ownership of a resource does not provide any access control. However, you can enforce the ownership by implementing access control against storage resources scoped to their owner.
For example, you can implement a policy where only the owner of an object can delete it. To do this, check the `owner_id` field of the object and compare it with the `sub` claim of the JWT:
```sql
create policy "User can delete their own objects"
on storage.objects
for delete
to authenticated
using (
owner_id = (select auth.uid())
);
```
The use of RLS policies is just one way to enforce access control. You can also implement access control in your server code by following the same pattern.