---
title: "Protecting reserved roles with PostgreSQL Hooks"
description: "Supabase grants customers the CREATEROLE privilege while preventing them from altering or dropping its internal service roles (like supabase_storage_admin) via a C extension, SupaUtils, that hooks PostgreSQL's ProcessUtility_hook."
url: "https://swe.quest/articles/protecting-reserved-roles-with-postgresql-hooks-2e21a72630349824"
canonical: "https://supabase.com/blog/roles-postgres-hooks"
source: "Supabase"
published: "2021-07-02"
difficulty: "hard"
kind: "How-to"
reading_minutes: 10
tags: ["postgres","identity-auth","c-cpp","multi-tenancy"]
---

# Protecting reserved roles with PostgreSQL Hooks

A post on [Supabase](https://swe.quest/sources/supabase.md), published 2021-07-02, 10 min read, How-to. Original: [https://supabase.com/blog/roles-postgres-hooks](https://supabase.com/blog/roles-postgres-hooks)

## Summary

Supabase grants customers the CREATEROLE privilege while preventing them from altering or dropping its internal service roles (like supabase\_storage\_admin) via a C extension, SupaUtils, that hooks PostgreSQL's ProcessUtility\_hook. The hook chains any previously installed hook, reads a reloadable GUC parameter supautils.reserved\_roles, and inspects AlterRoleStmt and DropRoleStmt nodes to raise an insufficient-privilege error when a reserved role is targeted. The walkthrough covers the PGXS Makefile, \_PG\_init registration, DefineCustomStringVariable, and testing via shared\_preload\_libraries, mirroring how Amazon RDS's rdsutils protects rds-prefixed roles.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)
- [Multi-tenancy](https://swe.quest/tags/multi-tenancy.md) (Architecture & design)

## Prerequisites

- PostgreSQL roles and privileges ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- C programming
- PostgreSQL extensions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))

## Keywords

PostgreSQL, ProcessUtility\_hook, SupaUtils, Supabase, CREATEROLE, Amazon RDS, GUC, shared\_preload\_libraries

## Related posts

- [PostgreSQL Event Triggers without superuser access](https://swe.quest/articles/postgresql-event-triggers-without-superuser-access-1e29cc1decfb7891.md): Supabase · 2025-05-08 · Hard · 3 min read · PostgreSQL, Security, Identity & auth
  Supabase's supautils extension lets non-superusers create Postgres Event Triggers by intercepting \`create event trigger\` from a "privileged role" via ProcessUtility\_hook, temporarily elevating to superuser for creation, then assigning ownership back to the privileged role.
- [Postgres Roles and Privileges](https://swe.quest/articles/postgres-roles-and-privileges-34a9d5f1c1427204.md): Supabase · 2024-04-11 · Medium · 20 min read · PostgreSQL, Identity & auth, Security
  Postgres access control rests on objects, privileges, roles and ownership: an object's owner holds all privileges on it and is the one who can grant them, so even an admin-like role such as Supabase's non-superuser postgres gets permission denied when granting on a table it neither owns nor holds privileges on.
- [Supabase Auth: Identity Linking, Hooks, and HaveIBeenPwned integration](https://swe.quest/articles/supabase-auth-identity-linking-hooks-and-haveibeenpwned-integration-8ed59b21ef27e3e6.md): Supabase · 2023-12-14 · Medium · 5 min read · Identity & auth, PostgreSQL
  Supabase Auth adds four features: manual Identity Linking via linkIdentity()/unlinkIdentity() for OAuth identities, session controls (time-boxed sessions, inactivity timeouts, single session per user on Pro and above), leaked password protection using the HaveIBeenPwned Pwned Passwords API with configurable password requirements, and Auth Hooks.
- [Postgres Roles: What to Know Before You Begin](https://swe.quest/articles/postgres-roles-what-to-know-before-you-begin-a6df1c63fd1f0301.md): Neon · 2024-07-12 · Medium · 12 min read · PostgreSQL, Identity & auth, Schema migrations
  Postgres has no separate users and groups, only roles: a role with LOGIN behaves like a user, and a role without it acts as a group whose privileges pass to its members through inheritance.
- [Higher-level CRUD Abstraction for Postgres RLS](https://swe.quest/articles/higher-level-crud-abstraction-for-postgres-rls-90207e4bb081ead2.md): Neon · 2024-11-13 · Medium · 3 min read · PostgreSQL, Identity & auth, TypeScript
  Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
