Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add note about security definer views (#26571)

TheOtherBrian1a5785afba634
diff --git a/apps/docs/content/guides/database/tables.mdx b/apps/docs/content/guides/database/tables.mdx
index fe9cdf9c178..09a58b09b75 100644
--- a/apps/docs/content/guides/database/tables.mdx
+++ b/apps/docs/content/guides/database/tables.mdx
@@ -401,12 +401,6 @@ create table private.salaries (
A View is a convenient shortcut to a query. Creating a view does not involve new tables or data. When run, an underlying query is executed, returning its results to the user.
-<Admonition type="caution">
-
-By default, PostgreSQL views bypass Row Level Security unless you change their owner (see https://github.com/supabase/supabase/discussions/901). PostgreSQL v15 (coming soon) will have a more intuitive control for this through [security invoker views](https://www.depesz.com/2022/03/22/waiting-for-postgresql-15-add-support-for-security-invoker-views/) and the previous step won't be needed.
-
-</Admonition>
-
Say we have the following tables from a database of a university:
**`students`**
@@ -459,6 +453,21 @@ Once done, we can now access the underlying query with:
select * from transcripts;
```
+### View security
+
+By default, views are accessed with their creator's permission ("security definer"). If a privileged role creates a view, others accessing it will use that role's elevated permissions. To enforce row level security policies, define the view with the "security invoker" modifier.
+
+```sql
+-- alter a security_definer view to be security_invoker
+alter view <view name>
+set (security_invoker = true);
+
+-- create a view with the security_invoker modifier
+create view <view name> with(security_invoker=true) as (
+ select * from <some table>
+);
+```
+
### When to use views
Views provide the several benefits: