Policies
Rules written as Postgres row-level security on the files table, with auth.uid() and your own tables.
On this page
Every request is checked against policies on sypnia_files.objects, the same row-level security Postgres uses for your tables. A request is allowed only if a policy for that command and role allows it; with no policy, nothing is allowed.
| Request | Command checked |
|---|---|
| download, list | select |
| upload | insert |
replace (upsert), move, change metadata | update (and insert for the new path) |
| delete | delete |
Examples
-- anyone can read the public menu photos
create policy "menu is public" on sypnia_files.objects for select to anon, authenticated
using (bucket_id = 'menu');
-- a user reads and writes only their own folder
create policy "own folder" on sypnia_files.objects for all to authenticated
using (bucket_id = 'avatars' and (sypnia_files.foldername(name))[1] = auth.uid()::text)
with check (bucket_id = 'avatars' and (sypnia_files.foldername(name))[1] = auth.uid()::text);
-- a customer reads the receipt of their own order (joins your table)
create policy "own receipts" on sypnia_files.objects for select to authenticated
using (bucket_id = 'receipts' and exists (
select 1 from public.orders o
where o.id = (sypnia_files.objects.metadata->>'orderId')::bigint and o.customer_id = auth.uid()));Helpers: sypnia_files.foldername(name) (the folders as an array), sypnia_files.filename(name), sypnia_files.extension(name). auth.uid(), auth.role() and auth.jwt() come from Sypnia Data, or from the engine when you use another issuer.
Without Sypnia Data
With another issuer, the engine verifies the JWT against its JWKS and exposes the same auth.* functions in its own metadata database, so policies are written the same way.
In the console Cloud
The policy editor offers templates («public read», «own folder», «owner only», «role from app_metadata») and shows the SQL it will run. The lint that warns about unqualified columns in sub-selects runs here too.