Skip to content

docs(database): correct RLS guide against skills and academy rules - #49268

Closed
czenko wants to merge 20 commits into
docs/rls-restructurefrom
cursor/rls-accuracy-f756
Closed

czenko wants to merge 20 commits into
docs/rls-restructurefrom
cursor/rls-accuracy-f756

Conversation

@czenko

@czenko czenko commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Docs update (technical accuracy), stacked on #49017.

Review #49017 first. This PR only adds the accuracy pass after that restructure.

Stack (bottom → top): #49017 (docs/rls-restructure → master) → this PR (cursor/rls-accuracy-f756 → docs/rls-restructure).

Local tracking is via gh stack (gh stack init / gh stack add / gh stack submit). Creating the GitHub Stack object failed here with Resource not accessible by integration. After merge of #49017, retarget this PR to master if GitHub does not do that automatically. To attach official GitHub Stack metadata from a token that can write stacks:

gh stack link --base master 49017 49268

What is the current behavior?

The restructured RLS guide in #49017 still had a few technical mismatches with:

What is the new behavior?

Accuracy-only edits to row-level-security.mdx:

  • Permissive policies OR together; as restrictive to AND (link #mfa)
  • FORCE RLS: owners / superusers / bypassrls skip RLS; do not force on lookup tables a security definer helper reads as owner
  • Revoke EXECUTE on helper functions from public, anon, authenticated, and service_role (new functions grant EXECUTE to public)
  • auth.uid() null: null = user_id is unknown, not false; prefer to authenticated instead of IS NOT NULL
  • Update-without-select is a Data API representation issue, not a Postgres requirement
  • supabase.auth.update() → updateUser()
  • Invalid team JWT SQL team_id in (select jsonb) → ((select auth.jwt()) -> 'app_metadata' -> 'teams') ? team_id::text

Did not copy for all from security-rls-basics; academy/docs prefer one policy per operation.

Additional context

Base is docs/rls-restructure, not master. Files changed vs #49017 is the accuracy commit only.

Open in Web Open in Cursor 

czenko and others added 20 commits August 12, 2026 12:31
The build-docs-002-rls-guide eval failed six checks. Each one traces to
something the guide doesn't say.

- Grants. Add a "Grants and policies" section and rewrite the opening
  admonition around revoke-then-grant. The guide only ever showed grant,
  so agents left anon holding insert, update, and delete.
- Indexes. Drop the "(or primary keys)" carve-out and explain that a
  column is indexed only when it leads a btree index, with a composite
  primary key example.
- Tests. Add a "Test your policies" section covering pgTAP file location,
  supabase test db, role and identity switching, and which assertion
  matches which denial.

Co-Authored-By: Claude Opus 5 <[email protected]>
The section ran context, then a procedure, then context again. The 42501
paragraph after the numbered steps broke the action path.

- Move the 42501 explanation up with the other context.
- Put the steps under their own heading so the type boundary is visible.
- Tie the read-only example to step 2 instead of leaving it floating.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit's own rewrite of the admonition carried the italics forward.
CONTRIBUTING allows bold for a term the reader must not miss, not
italics for general emphasis, so a line this PR rewrites should not
leave it in place.

Co-Authored-By: Claude Opus 5 <[email protected]>
The procedure gave SQL with no operating context. CONTRIBUTING asks
procedures to tell the reader where to act.

Names both surfaces, matching column-level-security: the SQL Editor for
a one-off, a migration to keep it reproducible.

Co-Authored-By: Claude Opus 5 <[email protected]>
The section explained why policies fail quietly but never told the
reader to write the tests, or when.

- Open with the recommendation, and tie it to the same change that sets
  the grants and creates the policies.
- Point forward from the end of the grants procedure, which a reader
  reaches first.

Co-Authored-By: Claude Opus 5 <[email protected]>
The defaults were a prose sentence listing three roles and four
privileges. A table makes the starting state scannable and adds what
each role should be left with.

Co-Authored-By: Claude Opus 5 <[email protected]>
The assertion guidance sat after the numbered steps, so the reader met
the procedure before the material step 2 depends on.

- Group the role switching, the denial-to-assertion mapping, and the
  returning trick under How policy tests work, above the steps.
- Put the steps under Write and run the tests.
- Soften the recommendation. It reads as guidance now, not a mandate.

Co-Authored-By: Claude Opus 5 <[email protected]>
The section was three tips under a heading, with no opening sentence and
nothing connecting them. It reads as the rubric for step 2, so it now
says so.

- Open with what a test case is, then name the three things that decide
  whether an assertion means anything.
- Label each one and give it a reason, instead of a bare instruction.
- Fold the allowed-write bullet in with `returning`, where it belongs.
- Rename to Anatomy of a policy test, since the old heading promised an
  explanation the body never gave.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copy and correctness only. No sections move.

- Replace the italic emphasis on "never" with bold. CONTRIBUTING allows
  bold for a term the reader must not miss, not italics for emphasis.
- Drop marketing language from the opener, the intro, and the policies
  and performance section leads. Clears all 4 supa-mdx-lint warnings.
- Replace "we" with second person in two places.
- Scope the own-profile SELECT example with `to authenticated`. It
  contradicted the guide's own advice.
- Pin `search_path` on the security definer example and schema-qualify
  its body. The guide graded this requirement without ever stating it.
- State when a Service Key actually bypasses RLS. The section said keys
  bypass RLS, then a note said the opposite with no condition given.
- Repoint the two `#using-functions` links in the RBAC guide. That anchor
  has never existed.

Co-Authored-By: Claude Opus 5 <[email protected]>
The RLS guide spent 225 lines and 5 benchmark tables on performance,
covering the same six tips as the RLS Performance and Best Practices
troubleshooting entry, from the same source.

- Add guides/database/postgres/row-level-security-performance. Carries
  the client-filter and join-rewrite rules, all 5 benchmark tables
  merged into one, and a diagnostic section the guide never had: toggle
  RLS off to confirm it's the cost, then read the plan under an
  impersonated role.
- Keep every eval-graded rule on the RLS guide. Indexes, select-wrapping,
  role scoping, and security definer safety are correctness rules, not
  tuning tips, and an agent reading the guide top-down has to reach them.
  Group the first three under "Write policies that scale".
- Repoint the Grafana IO troubleshooting entry at the new page.
- Rewrite More resources as Related content. Each link now says what it
  is. Drops discussion 14576: locked, mislabeled here as "RLS Guide and
  Best Practices", and superseded by the troubleshooting entry.

Co-Authored-By: Claude Opus 5 <[email protected]>
The guide alternated between context, procedure, and reference on almost
every heading. A reader who wanted to write a policy passed through four
context or reference sections to reach one.

- Group into Understand Row Level Security, Secure a table with RLS, and
  RLS reference, with a navigation intro. Headings are demoted rather
  than renamed where anything links to them, so every inbound anchor
  survives.
- Merge the four policy sections. They repeated the same 10-line create
  table and enable RLS block, burying the clause that differed. One setup
  block now precedes four short policy examples.
- Move the auto-enable event trigger recipe to event-triggers.mdx, which
  had a stub section whose entire body was a link back here. It was 70
  lines of advanced recipe sitting before the reader saw a policy.
- Relocate the "auth.uid() returns null" caution, which was stranded
  inside that event trigger section, into the auth.uid() reference.
- Lift the revoke and grant procedure out of the danger admonition and
  merge it with the two other places that taught enable row level
  security.

765 lines to 582. 30 headings to 25.

Co-Authored-By: Claude Opus 5 <[email protected]>
"Postgres Row Level Security (RLS)" appeared twice in three sentences,
and the subtitle already states what the page is for.

Co-Authored-By: Claude Opus 5 <[email protected]>
- Open with an explicit recommendation. The section described the failure
  mode but never said to write the tests.
- Point step 2 at supabase-test-helpers, which replaces the user seeding
  and role switching the example does by hand, and at Advanced pgTAP
  testing for schema-wide assertions.
- Replace mkdir and touch with `supabase test new`.
- Cut the example from 90 lines to 48. It now shows each technique once,
  a grant denial, an allowed write proved by returning, and two policy
  denials, instead of walking all four operations. The coverage rule
  stays in prose, with the eight-assertion floor stated.

Co-Authored-By: Claude Opus 5 <[email protected]>
The number came from the eval's threshold, not from anything a reader
needs. The coverage rule already says what to test.

Co-Authored-By: Claude Opus 5 <[email protected]>
Matches the wording introduced at the bottom of the stack, and adds the
forward pointer from the grants procedure that the rebase dropped.

Co-Authored-By: Claude Opus 5 <[email protected]>
Carries the softened recommendation and the context-before-procedure
split up from the bottom of the stack, at the heading level this branch
uses.

Co-Authored-By: Claude Opus 5 <[email protected]>
Carries Anatomy of a policy test up from the bottom of the stack at this
branch's heading level.

Co-Authored-By: Claude Opus 5 <[email protected]>
Drop the ellipses that were bridging the policy example, replace quoted
"fresh" with up-to-date, and recommend secret keys over legacy JWT
service_role keys for bypassing RLS.

Co-authored-by: Miranda Limonczenko <[email protected]>
Fail closed if the auto-enable trigger cannot turn on RLS, await the
client query examples, qualify the join policy's outer team_id, fix the
copied test6 improvement percentage, describe grants as project-default
dependent, and restore the missing verb in the Grafana RLS bullet.

Co-authored-by: Miranda Limonczenko <[email protected]>
Permissive policies OR together, FORCE RLS is opt-in and unsafe on
helper lookup tables, security definer functions must revoke EXECUTE,
auth.uid() null is unknown not false, update-without-select is a Data
API representation issue, updateUser() is the Auth method, and the
app_metadata team check needs the jsonb ? operator.

Co-authored-by: Miranda Limonczenko <[email protected]>
@vercel

vercel Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, v0 Aug 19, 2026 6:17pm
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 19, 2026 6:17pm
design-system Skipped Skipped Aug 19, 2026 6:17pm
studio-self-hosted Skipped Skipped Aug 19, 2026 6:17pm
studio-staging Skipped Skipped Aug 19, 2026 6:17pm
ui-library Skipped Skipped Aug 19, 2026 6:17pm
zone-www-dot-com Skipped Skipped v0 Aug 19, 2026 6:17pm

Request Review

@supabase

supabase Bot commented Aug 19, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 039be6db-1810-455b-a0e6-ca17e11b3a28

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@czenko

czenko commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Aborting. Cursor is a bit unhinged (but I do like Grok's writing style a lot more). Moving back to Claude and redoing this.

@czenko

czenko commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #49274, which carries this work as a single PR stacked on #49017. Nothing is lost: the combined branch produces a byte-identical guide to this chain's tip.

Closing and deleting the branch.

czenko added a commit that referenced this pull request Aug 19, 2026
## Problem

The guide alternated between context, procedure, and reference on almost
every heading. A reader who wanted to write a policy passed through four
context or reference sections to reach one. A reader who wanted the
model had to skip three procedures.

## Solution

- Group into three sections by information type: `Understand Row Level
Security`, `Secure a table with RLS`, and `RLS reference`, with a
navigation intro.
- Merge the four policy sections. They repeated the same setup block,
burying the clause that differed. One setup block now precedes four
short policy examples.
- Move the auto-enable recipe into `event-triggers.mdx`, whose stub
section's entire body was a link back here.
- Relocate the stranded `auth.uid()` caution into the `auth.uid()`
reference.
- Lift the revoke-and-grant procedure out of the danger admonition and
merge it with the two other places that taught `enable row level
security`.
- Point the Grafana IO chart entry at the performance guide. Its
`#rls-performance-recommendations` anchor went away when tuning split
out in #49016.

765 lines to 582. 30 headings to 25.

Headings are demoted rather than renamed wherever anything links to
them. Every inbound anchor in the repo still resolves; the only one
removed, `#auto-enable-rls-for-new-tables`, was referenced solely by the
`event-triggers.mdx` stub this PR replaces.

## Note on the history

Rebuilt from `master` after #49011, #49015, and #49016 merged. The
branch previously carried those 10 commits plus rebase churn against
them.

Rebasing naively would have reverted review feedback from #49016
(`70fa812`), which removed the benchmarks table and the "This guide"
opener from the performance guide. Those are deliberately not restored
here. The only changes to that file are two missing `await`s and a join
predicate that was a tautology while unqualified.

The three PRs stacked on this one (#49268, #49269, #49270) have been
rebased onto the new base.

## Manual testing

1. Open the [Row Level Security
guide](https://docs-git-docs-rls-restructure-supabase.vercel.app/docs/guides/database/postgres/row-level-security)
on the preview. Three top-level sections appear in the table of
contents.
2. Select each link in the intro. All three jump to their section.
3. Open [Event
triggers](https://docs-git-docs-rls-restructure-supabase.vercel.app/docs/guides/database/postgres/event-triggers).
The auto-enable section holds the full recipe instead of a link.
4. Open the [performance
guide](https://docs-git-docs-rls-restructure-supabase.vercel.app/docs/guides/database/postgres/row-level-security-performance).
No benchmarks table, and the three bullets at the top link into the RLS
guide.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Documentation**
* Reworked the Row Level Security guide with clearer guidance on grants,
policies, permissions, performance, testing, views, and secure
functions.
* Added a complete example for automatically enabling RLS on newly
created public tables.
* Improved SQL examples and clarified table references in RLS
performance guidance.
* Corrected grammar in the Grafana chart troubleshooting documentation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants