Skip to content

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

blog: small improvements to Event Triggers (#35668)

Copple19099541e5c2
diff --git a/apps/www/_blog/2025-05-08-event-triggers-wo-superuser.mdx b/apps/www/_blog/2025-05-08-event-triggers-wo-superuser.mdx
index 97deb348224..63e2bf3823d 100644
--- a/apps/www/_blog/2025-05-08-event-triggers-wo-superuser.mdx
+++ b/apps/www/_blog/2025-05-08-event-triggers-wo-superuser.mdx
@@ -16,9 +16,9 @@ tags:
date: '2025-05-08'
---
-Event triggers in Postgres are powerful, but only a superuser can create them. In cloud environments, granting superuser access isn't an option.
+Event Triggers in Postgres are powerful, but only a superuser can create them. In cloud environments, granting superuser access isn't an option.
-But thanks to Postgres' extensibility, we can allow regular users to create event triggers, in a safe way.
+But thanks to Postgres' extensibility, we can allow regular users to create Event Triggers, in a safe way.
In this blog post, we’ll explain how we do this in the `supautils` extension, using a combination of the Utility Hook and the Function Manager Hook.
@@ -36,12 +36,12 @@ Creating an event trigger like this is not safe though, as it would allow privil
## The privilege escalation problem
-Here, a problem arises. Once an event trigger is created:
+Here, a problem arises. Once an Event Trigger is created:
- It targets every role.
- It runs using the target role privileges [^2].
-This means that a malicious user can create an event trigger like:
+This means that a malicious user can create an Event Trigger like:
```sql
create or replace function become_super()
@@ -63,17 +63,17 @@ And once a superuser trips on the event trigger, it will fire with its privilege
![fmgr hook](/images/blog/2025-05-08-event-triggers-wo-superuser/fmgr-hook.png)
-A solution would be skipping user event triggers for superusers.
+A solution would be skipping user Event Triggers for superusers.
The Function Manager hook (`fmgr_hook`) allows us to intercept and modify functions’ execution.
-We can intercept the event trigger function and replace it with a “noop”. Postgres doesn’t provide a noop function, but we can use the existing `version()` function for the same purpose.
+We can intercept the Event Trigger function and replace it with a “noop”. Postgres doesn’t provide a noop function, but we can use the existing `version()` function for the same purpose.
Besides superusers, we also want to skip user event triggers for “reserved roles” [^3]. These are used for managed services (like `pgbouncer`).
## User Event Triggers
-This now allows users to safely create event triggers, without superuser access:
+This now allows users to safely create Event Triggers, without superuser access:
```sql
-- use the privileged role, which is configured to be "postgres"
@@ -108,15 +108,17 @@ NOTICE: the event trigger is executed for myrole
We would also like to allow regular user event triggers in Postgres core. To this end, we’ve submitted [some patches](https://www.postgresql.org/message-id/flat/CAGRrpzbtYDkg7_xwfzrqByYgCJQbbL38tADyuN%2B6tAkbA-Pnkg%40mail.gmail.com) which are already generating fruitful discussion.
-Note that user event triggers in Postgres core will likely be more restricted than the `supautils` version.
+Note that user Event Triggers in Postgres core will likely be more restricted than the `supautils` version.
## Try it out
-User event triggers are now available for new projects on the Supabase platform.
+User Event Triggers are now available for new projects on the Supabase platform.
You can also git clone the [supautils repo](https://github.com/supabase/supautils/) and `make install` it in your own deployment.
-Finally, we want to give a special shout out to the [Zero Sync](https://zero.rocicorp.dev) guys, which kept pushing us to release this feature.
+Finally, we want to give a special shout out to the [Zero Sync](https://zero.rocicorp.dev) team, who pushed us to release this feature.
+
+---
[^1]: This is so the event trigger can be altered or dropped by end users.
[^2]: This is not true if you mark the event trigger function as `security definer`, then it will run with the privileges of the function owner. But this is not a usual practice on event triggers, as they usually want to preserve the context of the current user.