Privileges: grant, revoke and reduce
Read the real privilege matrix of a project, grant or revoke a privilege with aura db raw, change the defaults for future tables, and keep a least-privilege setup in place over time.
A request reaches a table only if its role holds the privilege for the operation (select, insert…), and only then do the policies filter the rows. Aurabase grants broad privileges to the public roles on everything in your schema and relies on row level security to limit rows. This page shows those privileges as they are, and how to narrow them.
Prerequisites#
-
A linked project:
aura link <project-id>. -
The example schema, installed with the service role key of the project:
export AURABASE_SERVICE_ROLE_KEY=aura_sk_… aura db seed --example docsIt creates
profiles,orgs,org_members,posts,todos, the viewopen_todosand the functiontodo_count(p_user uuid). See Example schema.
The examples create objects prefixed sec_priv_ and change the default privileges of the project schema; the Clean up block drops the objects and restores the defaults.
Privileges come before policies#
1. role of the request anon key → aura_anon, user → aura_authenticated, service_role → bypass
2. privilege on the object missing → 403 permission denied for table … (whatever the policies)
3. policies of the table no match → empty answer, or 403 new row violates row-level security policyWhich key becomes which role, and which roles bypass row level security, is on Roles, keys and RLS bypass. This page is about step 2 for aura_anon and aura_authenticated.
What the public roles hold by default#
When it provisions a project, Aurabase runs, as the administrator role of the project, grant all on the schema, its tables and its sequences to aura_anon, aura_authenticated and aura_service_role, and alter default privileges … grant all on tables (and sequences) for every relation created later. It also removes PostgreSQL's default execute for everyone on new functions. Measured on a project:
| Object in your schema | aura_anon and aura_authenticated hold | Rows limited by |
|---|---|---|
Table created with the CLI, the schema API, aura db raw or a migration | All table privileges: select, insert, update, delete, truncate, references, trigger, maintain | Policies (RLS on) |
| Partition | The same | Nothing when the partition is read by name: RLS is off on new partitions |
| View | The same | The policies of its tables, when security_invoker = true |
| Materialized view | The same | Nothing: no RLS on materialized views |
| Sequence | All sequence privileges | — |
| Function | No execute until you grant it | — |
| The schema itself | usage and create | — |
What these privileges allow beyond the policies:
truncateempties a table; policies do not apply to it.triggerlets the role create triggers on the table,referenceslets it reference the table from a foreign key,maintainlets it runvacuum,analyze,reindex,refresh materialized viewandlock tableon it.createon the schema lets the role create its own tables, which then belong to it and have no row level security.
The REST API and the SDK never send these statements: they only matter for SQL that runs as a public role, such as a security invoker function you expose with rpc(), or a future path you did not plan for. They are defense in depth, and removing them costs nothing to an application.
Read the matrix of your project#
has_table_privilege answers for any role and object, and aura db raw accepts it. Create one object of each kind, then list what aura_anon holds on each:
aura db raw "create table sec_priv_items (id bigint generated always as identity primary key, name text not null)"
aura db table create sec_priv_cli "name:text"
aura db raw "create view sec_priv_view as select id, name from sec_priv_items;
create materialized view sec_priv_counts as select count(*) as n from sec_priv_items;
create table sec_priv_events (at date not null) partition by range (at);
create table sec_priv_events_2026 partition of sec_priv_events for values from ('2026-01-01') to ('2027-01-01')" ℹ No results (0 rows).
» Creating table 'sec_priv_cli'
✔ Table 'sec_priv_cli' created with 3 column(s).
ℹ RLS enabled by default.
• Columns: id, name, created_at
ℹ No results (0 rows).select o.obj as object,
string_agg(p.priv, ',' order by p.n) filter (where has_table_privilege('aura_anon', o.obj, p.priv)) as anon_privileges
from (values ('sec_priv_items'), ('sec_priv_cli'), ('sec_priv_view'), ('sec_priv_counts'),
('sec_priv_events'), ('sec_priv_events_2026'), ('todos')) o(obj)
cross join (values (1, 'select'), (2, 'insert'), (3, 'update'), (4, 'delete'), (5, 'truncate'),
(6, 'references'), (7, 'trigger'), (8, 'maintain')) p(n, priv)
group by o.obj
order by o.obj; anon_privileges │ object
─────────────────────────────────────────────────────────────────┼─────────────────────
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_cli
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_counts
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_events
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_events_2026
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_items
select,insert,update,delete,truncate,references,trigger,maintain │ sec_priv_view
select,insert,update,delete,truncate,references,trigger,maintain │ todos
ℹ 7 row(s).aura_authenticated holds the same; replace the role in the query to check it. has_column_privilege, has_function_privilege and has_schema_privilege work the same way.
Grant and revoke#
grant and revoke run through aura db raw, the SQL editor of the Studio, migrations and the direct connection. Revoking a privilege from a public role gives 403 INSUFFICIENT_PRIVILEGE, permission denied for … to the requests of that role:
aura db raw "revoke all on sec_priv_counts from aura_anon, aura_authenticated"
curl -s "$AURABASE_URL/v1/db/$PROJECT_ID/sec_priv_counts" -H "apikey: $AURABASE_ANON_KEY" \
| node -e 'const e = JSON.parse(require("fs").readFileSync(0, "utf8")).error; console.log(e.code, e.message)' ℹ No results (0 rows).
INSUFFICIENT_PRIVILEGE permission denied for materialized view sec_priv_countsTypical uses:
| Goal | SQL |
|---|---|
| Keep a materialized view for servers only | revoke all on <view> from aura_anon, aura_authenticated; |
| Read-only table for the public roles | revoke insert, update, delete on <table> from aura_anon, aura_authenticated; |
| Hide a column | Revoke select on the table, then grant select (<columns>) …; Realtime events still carry every column (Column-level security) |
| Let signed-in users call a function | grant execute on function <name>(<types>) to aura_authenticated; (Database functions) |
| Expose a table created over the direct connection with the project's login role | grant select, insert, update, delete on <table> to aura_authenticated; after enabling RLS and writing policies (Connect) |
Reduce the defaults#
The privileges below are never needed by the REST API or the SDK. Revoke them on what exists, and change the defaults so future tables are created without them. On your project, the first statement covers every table, view, materialized view and partition of your schema at once (excerpt; your schema is project_ followed by the project id with underscores):
revoke truncate, references, trigger, maintain on all tables in schema project_<id> from aura_anon, aura_authenticated;The example below does the same on the objects of this page only, so that the tables of the example schema stay as they are, then removes create on the schema and changes the defaults. alter default privileges applies to objects created later by the role that runs it, which for aura db raw, the CLI and the schema API is the administrator role of the project, the one that set the defaults:
SCHEMA="project_${PROJECT_ID//-/_}"
aura db raw "revoke truncate, references, trigger, maintain
on sec_priv_items, sec_priv_cli, sec_priv_view, sec_priv_counts, sec_priv_events, sec_priv_events_2026
from aura_anon, aura_authenticated;
revoke create on schema $SCHEMA from aura_anon, aura_authenticated;
alter default privileges in schema $SCHEMA revoke truncate, references, trigger, maintain on tables from aura_anon, aura_authenticated"
aura db raw "create table sec_priv_after (id int)"
aura db raw "select string_agg(p.priv, ',' order by p.n) filter (where has_table_privilege('aura_anon', 'sec_priv_after', p.priv)) as anon_on_new_table,
has_schema_privilege('aura_anon', current_schema(), 'create') as anon_creates
from (values (1, 'select'), (2, 'insert'), (3, 'update'), (4, 'delete'), (5, 'truncate'),
(6, 'references'), (7, 'trigger'), (8, 'maintain')) p(n, priv)" ℹ No results (0 rows).
ℹ No results (0 rows).
anon_creates │ anon_on_new_table
─────────────┼────────────────────────────
false │ select,insert,update,delete
ℹ 1 row(s).A partition has its own privileges: revoking on the parent does not change its partitions, which all tables in schema covers. Keep select, insert, update and delete: the policies decide which rows they reach, and removing them breaks the API for that role.
Two things are not covered by this script: objects created over the direct connection by another role than the administrator (the defaults are those of the role that creates), and the platform schemas of the project, which Aurabase manages.
Keep it in place#
Aurabase re-applies its grants to the schemas of a project, your schema included, when it upgrades their internal migrations: the same grant all on every table and sequence, and the same default privileges. Such an upgrade restores what your revoke statements removed, including the revocations of Column-level security and of materialized views. This re-application is described from the code of the provisioner and was not triggered for this page. Therefore:
- keep your
revokeandgrantstatements in a migration or a script that you can run again at any time; - check the result with the matrix query above, in CI or after each platform upgrade (Test RLS in CI);
- for data that must never reach a public role whatever its privileges, rely on row level security (a policy that does not match) or keep it in a table without any policy for the public roles.
Roles you cannot create#
A project cannot create PostgreSQL roles (permission denied to create role). Model your own roles with claims instead: set app_metadata.roles from a server and test auth.has_role('<role>') in policies, or keep memberships in a table read by a security definer function (Multi-tenant schema design). The service_role key and the password of the direct connection both act as administrator; they never go to a browser or an app (API keys).
Result#
After the reduction, the public roles keep the four privileges that policies filter, on the objects revoked above and on new tables:
select o.obj as object,
string_agg(p.priv, ',' order by p.n) filter (where has_table_privilege('aura_authenticated', o.obj, p.priv)) as user_privileges
from (values ('sec_priv_items'), ('sec_priv_after'), ('sec_priv_events_2026')) o(obj)
cross join (values (1, 'select'), (2, 'insert'), (3, 'update'), (4, 'delete'), (5, 'truncate'),
(6, 'references'), (7, 'trigger'), (8, 'maintain')) p(n, priv)
group by o.obj
order by o.obj; object │ user_privileges
─────────────────────┼────────────────────────────
sec_priv_after │ select,insert,update,delete
sec_priv_events_2026 │ select,insert,update,delete
sec_priv_items │ select,insert,update,delete
ℹ 3 row(s).Common errors#
| Message | Cause | Fix |
|---|---|---|
403 INSUFFICIENT_PRIVILEGE, permission denied for table … | The role lacks the privilege: revoked, or a table created over the direct connection with the project's login role. | Grant what the role needs, then let policies filter. |
permission denied for materialized view … / … for view … | The view was revoked from the role. | Read it with the service_role key, or through a function. |
permission denied for function … | No execute for the role: the default for new functions. | grant execute on function … to aura_authenticated; |
permission denied for schema project_… | create was revoked on the schema and SQL running as a public role tried to create an object. | Expected after the reduction: create objects as administrator. |
permission denied to create role | Projects cannot create roles. | Use claims and policies. |
| A revoked privilege is back | A platform upgrade re-applied the default grants. | Run your script again (Keep it in place). |
Clean up#
Drop the objects, and give the defaults back as the project had them:
SCHEMA="project_${PROJECT_ID//-/_}"
aura db raw "drop table if exists sec_priv_after;
drop materialized view sec_priv_counts;
drop view sec_priv_view;
drop table sec_priv_events;
drop table sec_priv_items;
drop table sec_priv_cli;
grant create on schema $SCHEMA to aura_anon, aura_authenticated;
alter default privileges in schema $SCHEMA grant all on tables to aura_anon, aura_authenticated" ℹ No results (0 rows).Keep the reduction on your own project; this block only restores the state that the rest of the documentation assumes.