Skip to content

Policies

Rules written as Postgres row-level security on the files table, with auth.uid() and your own tables.

Applies to EngineCloud
View as Markdown
On this page
  1. Examples
  2. Without Sypnia Data
  3. In the console

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.

RequestCommand checked
download, listselect
uploadinsert
replace (upsert), move, change metadataupdate (and insert for the new path)
deletedelete

Examples

SQL
-- 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.

  1. Examples
  2. Without Sypnia Data
  3. In the console

    Search pages, sections and terms