Storage ownership
Knowing who owns a Storage object lets you write access rules scoped to that user. For how to write those rules, see Storage access control.
How Storage assigns an owner
Storage automatically records an owner for each bucket and object, except those created with the service_key or in the Dashboard:
- The owner is the user who created the resource, taken from the
subclaim in the JWT. - When a user copies or moves an object, the owner of the new object is the user who initiated the operation. For details, see Copy objects.
- Storage keeps the owner in the
owner_idcolumn of the Storage schema. The schema also has anownercolumn, which is deprecated. Useowner_idinstead. - A resource you create with the
service_key, or in the Dashboard, has no owner set, so it's owned by anyone.
Access control
Ownership by itself provides no access control. To enforce it, scope access control on Storage resources 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:
create policy "User can delete their own objects"on storage.objectsfor deleteto authenticatedusing ( owner_id = (select auth.uid()::text));Row Level Security (RLS) policies are one way to enforce access control. You can also implement access control in your server code by following the same pattern.
Related resources
- Storage access control: write RLS policies for Storage.
- Storage schema: the tables that hold the
owner_idcolumn.