---
title: "Is Postgres RLS for Everything and Everyone?"
description: "Postgres row-level security is a poor fit for expressing an entire app's authorization model."
url: "https://swe.quest/articles/is-postgres-rls-for-everything-and-everyone-1df08667813a2c82"
canonical: "https://neon.com/blog/is-postgres-rls-for-everything-and-everyone"
source: "Neon"
published: "2024-11-15"
difficulty: "medium"
kind: "Opinion"
reading_minutes: 4
tags: ["postgres","identity-auth","multi-tenancy","security"]
---

# Is Postgres RLS for Everything and Everyone?

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-11-15, 4 min read, Opinion. Original: [https://neon.com/blog/is-postgres-rls-for-everything-and-everyone](https://neon.com/blog/is-postgres-rls-for-everything-and-everyone)

## Summary

Postgres row-level security is a poor fit for expressing an entire app's authorization model. Its syntax is dense, org-membership checks hit "infinite recursion detected in policy" errors (worked around with views or RLS-bypassing functions), and there are several pitfalls: wrapping auth calls in a subselect so the optimizer caches them per statement, permissive policies being OR'd while restrictive ones are AND'd, security\_invoker semantics on views and functions, and hard-to-write integration tests. The recommended hybrid is to keep fine-grained authorization in a higher-level framework like CASL and use RLS as a baseline guard against cross-tenant access, applying one tenant\_id policy to every table driven by a JWT tenantId claim.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

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

## Prerequisites

- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- JWT authentication ([easy posts on Identity & auth](https://swe.quest/tags/identity-auth.md?difficulty=easy))

## Keywords

Row-Level Security, Neon RLS, Drizzle ORM, ZenStack, CASL, pg\_session\_jwt, Neon Data API

## Related posts

- [Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM](https://swe.quest/articles/modelling-authorization-for-a-social-network-with-postgres-rls-and-drizzle-orm-6267eb437b8171e7.md): Neon · 2024-11-11 · Medium · 8 min read · PostgreSQL, Identity & auth, TypeScript, System design
  Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg\_session\_jwt extension's auth.user\_id().
- [Introducing Neon RLS: Simplifying Row-Level Security For Postgres](https://swe.quest/articles/introducing-neon-rls-simplifying-row-level-security-for-postgres-4b66d76670bb402f.md): Neon · 2024-10-30 · Medium · 6 min read · PostgreSQL, Identity & auth, Multi-tenancy, TypeScript
  Neon RLS lets Postgres row-level security policies authenticate requests with JWTs from any auth provider that exposes a JWKS URL.
- [How to Set Up Row-Level Security in Postgres Using AWS Cognito](https://swe.quest/articles/how-to-set-up-row-level-security-in-postgres-using-aws-cognito-7cb6bed6c9694d22.md): Neon · 2024-12-04 · Medium · 5 min read · PostgreSQL, Identity & auth, JavaScript, Serverless
  Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like \`sub\` into Postgres session variables.
- [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.
- [Partial data dumps using Postgres Row Level Security](https://swe.quest/articles/partial-data-dumps-using-postgres-row-level-security-7b8cbab5206adee8.md): Supabase · 2022-06-28 · Medium · 4 min read · PostgreSQL, Privacy, Identity & auth, Testing
  Postgres Row Level Security can produce a seed.sql containing only safe, non-customer rows: create a restricted \`exporter\` role, attach RLS select policies that filter which rows it can see, then run \`pg\_dump --data-only --enable-row-security\` as that role.

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)
