Skip to content

Updated

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 sub claim 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_id column of the Storage schema. The schema also has an owner column, which is deprecated. Use owner_id instead.
  • 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.objects
for delete
to authenticated
using (
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.