Skip to content

docs: clarify RLS grants and production privilege checks - #48413

Open
paraggulve2641 wants to merge 1 commit into
supabase:masterfrom
paraggulve2641:docs/fix-48382-rls-guide
Open

paraggulve2641 wants to merge 1 commit into
supabase:masterfrom
paraggulve2641:docs/fix-48382-rls-guide

Conversation

@paraggulve2641

@paraggulve2641 paraggulve2641 commented Jul 28, 2026 •

Copy link
Copy Markdown

Overview

This updates the RLS documentation to clarify default privileges in the public schema and improve production security guidance.

Changes

  • Explain that public schema tables already have default grants for anon and authenticated roles.
  • Update examples to use revoke-then-grant pattern.
  • Add production checklist guidance to review table privileges.
  • Document that RLS does not apply to TRUNCATE.

Related Issue

Fixes #48382

Summary by CodeRabbit

  • Documentation
    • Updated the Row Level Security example to follow least-privilege practices by revoking existing table privileges before applying targeted grants.
    • Revised the production “Security” checklist to explicitly recommend reviewing table privileges for the relevant database roles.
    • Added an SQL snippet to inspect granted table permissions via the database’s metadata tables.

@paraggulve2641
paraggulve2641 requested a review from a team as a code owner July 28, 2026 17:59
@vercel

vercel Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
docs Error Error Aug 28, 2026 2:38am
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 28, 2026 2:38am
design-system Skipped Skipped Aug 28, 2026 2:38am
studio-self-hosted Skipped Skipped Aug 28, 2026 2:38am
studio-staging Skipped Skipped Aug 28, 2026 2:38am
ui-library Skipped Skipped Aug 28, 2026 2:38am
zone-www-dot-com Skipped Skipped Aug 28, 2026 2:38am

Request Review

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@paraggulve2641 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2e5a6b27-8951-47c1-ab5a-b8051d92dc41

📥 Commits

Reviewing files that changed from the base of the PR and between fe1ee78 and 72f0ae4.

📒 Files selected for processing (2)
  • apps/docs/content/guides/database/postgres/row-level-security.mdx
  • apps/docs/content/guides/deployment/going-into-prod.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/docs/content/guides/deployment/going-into-prod.mdx
  • apps/docs/content/guides/database/postgres/row-level-security.mdx

📝 Walkthrough

Walkthrough

The documentation updates add explicit privilege revocation to the RLS SQL example and replace production security guidance with instructions for reviewing anon and authenticated table grants.

Changes

RLS privilege guidance

Layer / File(s) Summary
Explicit RLS privilege grants
apps/docs/content/guides/database/postgres/row-level-security.mdx
The SQL example revokes existing privileges from anon and authenticated before applying role-specific grants and enabling RLS.
Production privilege review
apps/docs/content/guides/deployment/going-into-prod.mdx
The Security checklist instructs reviewers to inspect table privileges for anon and authenticated using information_schema.role_table_grants.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: czenko

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the main changes, but it misses the required template sections and the explicit CONTRIBUTING.md confirmation. Add the missing template sections (I have read CONTRIBUTING.md, current behavior, new behavior, additional context) and include the linked issue context.
Linked Issues check ⚠️ Warning The revoke-then-grant and privilege-review docs are added, but the TRUNCATE caveat and REFERENCES/TRIGGER notes from #48382 are still missing. Add a note that RLS does not cover TRUNCATE and mention the default REFERENCES/TRIGGER grants and their Data API visibility.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely matches the docs changes around RLS grants and production privilege checks.
Out of Scope Changes check ✅ Passed The edits stay within the documented RLS and production-security scope and don't add unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/docs/content/guides/database/postgres/row-level-security.mdx`:
- Around line 20-33: Add a brief note near the least-privilege SQL grants
explaining that TRUNCATE, REFERENCES, and TRIGGER are not controlled by RLS, and
that REVOKE ALL removes these non-CRUD table privileges as well. Keep the
existing grant statements unchanged.
- Around line 20-24: Update the documentation around the REVOKE ALL statement to
clarify that it affects only the specified existing table. Add that future
tables in the public schema require separate ALTER DEFAULT PRIVILEGES
configuration to enforce the same least-privilege policy.
- Around line 23-33: Update the SQL privilege setup to include service_role in
the initial REVOKE ALL statement before granting its final CRUD privileges,
ensuring any existing TRUNCATE, REFERENCES, or TRIGGER grants are removed.

In `@apps/docs/content/guides/deployment/going-into-prod.mdx`:
- Around line 16-25: Update the “Review database privileges” section in the
production deployment guide to retain the existing Security Advisor check and
present the role_table_grants query as an additional complementary check. Ensure
the guidance still directs users to review broader findings, including RLS
policies, exposed columns, and security-definer issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0827f333-442c-4a98-89c5-4b72517a8530

📥 Commits

Reviewing files that changed from the base of the PR and between d5436ae and fe1ee78.

📒 Files selected for processing (2)
  • apps/docs/content/guides/database/postgres/row-level-security.mdx
  • apps/docs/content/guides/deployment/going-into-prod.mdx

Comment on lines +20 to +33
Tables created in the `public` schema have default privileges granted to the `anon` and `authenticated` roles. To apply a least-privilege approach, revoke existing privileges first and then grant only the permissions required for your application.

```sql
GRANT SELECT ON <schema_name>.<table_name> TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON <schema_name>.<table_name> TO authenticated;
GRANT SELECT, INSERT, UPDATE, DELETE ON <schema_name>.<table_name> TO service_role;
REVOKE ALL ON TABLE <schema_name>.<table_name>
FROM anon, authenticated;

GRANT SELECT ON TABLE <schema_name>.<table_name>
TO anon;

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO authenticated;

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO service_role;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- file excerpt ---\n'
sed -n '1,90p' apps/docs/content/guides/database/postgres/row-level-security.mdx | cat -n

printf '\n--- git status/stat ---\n'
git diff --stat || true
git diff -- apps/docs/content/guides/database/postgres/row-level-security.mdx | sed -n '1,220p' || true

printf '\n--- search for TRUNCATE/REFERENCE/TRIGGER mentions in docs ---\n'
rg -n "TRUNCATE|REFERENCES|TRIGGER|row-level|RLS|role-policy|alter-default-privileges" apps/docs/content/guides/database/postgres apps/docs/content/guides/database -S || true

Repository: supabase/supabase

Length of output: 246


🌐 Web query:

PostgreSQL row-level security does not apply to TRUNCATE REFERENCES TRIGGER all privileges documentation

💡 Result:

In PostgreSQL, Row-Level Security (RLS) policies do not apply to the TRUNCATE command or to operations involving REFERENCES (foreign key checks) [1][2]. These operations are considered "whole-table" actions, and therefore, they are not subject to the fine-grained, row-based restrictions defined by RLS policies [1][3][2]. The PostgreSQL documentation explicitly states that when row security is enabled on a table, all normal access for selecting, inserting, updating, or deleting rows must comply with defined RLS policies; however, operations that apply to the whole table, such as TRUNCATE and REFERENCES, are specifically exempt [1][2]. Because these operations bypass RLS, it is important to manage privileges carefully using the standard SQL privilege system (GRANT/REVOKE) [1][2]. If a user has the TRUNCATE privilege on a table, they can empty that table regardless of any RLS policies that would otherwise restrict their ability to delete individual rows [4][5]. Similarly, referential integrity checks always bypass row security to ensure data integrity [1][2]. To prevent unauthorized users from performing these actions, you must ensure they are not granted the necessary privileges (e.g., ensure they do not hold the TRUNCATE privilege) [5].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- file excerpt ---'
sed -n '1,90p' apps/docs/content/guides/database/postgres/row-level-security.mdx | cat -n

printf '%s\n' ''
printf '%s\n' '--- git status/stat ---'
git diff --stat || true
git diff -- apps/docs/content/guides/database/postgres/row-level-security.mdx | sed -n '1,220p' || true

printf '%s\n' ''
printf '%s\n' '--- relevant privilege mentions in docs ---'
rg -n "TRUNCATE|REFERENCES|TRIGGER|row-level|RLS|REVOKE ALL|grant default|ALTER DEFAULT PRIVILEGES" apps/docs/content/guides/database apps/docs/content/guides/database/postgres -S || true

Repository: supabase/supabase

Length of output: 37178


🌐 Web query:

PostgreSQL ALL TABLE privileges include TRIGGER TRUNCATE REFERENCES documentation

💡 Result:

Yes, the ALL PRIVILEGES (or ALL) privilege in PostgreSQL for tables includes TRIGGER, TRUNCATE, and REFERENCES, along with other standard table-level privileges [1][2][3]. When you grant ALL PRIVILEGES on a table (or ALL TABLES in a schema), you are granting every privilege that is applicable to that object type [1][2]. For tables, the complete set of standard privileges includes [3]: SELECT (r) INSERT (a) UPDATE (w) DELETE (d) TRUNCATE (D) REFERENCES (x) TRIGGER (t) As of PostgreSQL 15 and later, an additional privilege, MAINTAIN (m), is also included under ALL PRIVILEGES for tables [1][2][3]. Therefore, granting ALL PRIVILEGES on a table is equivalent to granting SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, and (in newer versions) MAINTAIN [1][2][3].

Citations:


Document the RLS boundary for non-CRUD privileges.

Add a short note around the least-privilege grants that TRUNCATE, REFERENCES, and TRIGGER are outside RLS control, and that REVOKE ALL removes them too, so roles are not left with whole-table privileges after the least-privilege pattern.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/content/guides/database/postgres/row-level-security.mdx` around
lines 20 - 33, Add a brief note near the least-privilege SQL grants explaining
that TRUNCATE, REFERENCES, and TRIGGER are not controlled by RLS, and that
REVOKE ALL removes these non-CRUD table privileges as well. Keep the existing
grant statements unchanged.

Comment on lines +23 to +33
REVOKE ALL ON TABLE <schema_name>.<table_name>
FROM anon, authenticated;

GRANT SELECT ON TABLE <schema_name>.<table_name>
TO anon;

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO authenticated;

GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO service_role;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo.pipefail

echo "Repo files matching target:"
git ls-files | rg 'apps/docs/content/guides/database/postgres/row-level-security\.mdx$' || true

echo
echo "Target excerpt:"
if [ -f apps/docs/content/guides/database/postgres/row-level-security.mdx ]; then
  nl -ba apps/docs/content/guides/database/postgres/row-level-security.mdx | sed -n '1,80p'
fi

echo
echo "Search for service_role grants in docs:"
rg -n "service_role|REVOKE ALL|GRANT (TRUNCATE|REFERENCES|TRIGGER)|row-level-security" apps/docs || true

Repository: supabase/supabase

Length of output: 808


🌐 Web query:

PostgreSQL REVOKE ALL ON TABLE revokes all revokeable privileges referenced in GRANT documentation

💡 Result:

In PostgreSQL, the REVOKE ALL PRIVILEGES ON TABLE command is designed to remove all privileges on a specified table that were previously granted by the executor of the command [1][2]. When executed, this command does not necessarily strip every possible privilege from the target role if those privileges were granted by someone else; rather, it effectively revokes all privileges that the current user has the authority to revoke (i.e., those they granted) [1][2]. If a user attempts to revoke privileges they did not grant, the command's behavior is restricted by their grant options; it will only remove those privileges for which they hold the necessary grant options [2]. Additionally, when you use REVOKE ALL on a table, PostgreSQL automatically revokes any corresponding column-level privileges that were previously granted on that table [1][3]. However, the reverse is not true: revoking privileges on specific columns does not affect privileges granted at the table level [1][4]. The official documentation clarifies that the command is equivalent to revoking all privileges for which the issuing user holds grant options [1][2]. For superusers or the object owner, this effectively results in the removal of all privileges, as they are treated as holding all grant options [2].

Citations:


🏁 Script executed:

#!/bin/bash
set -u

echo "Repo files matching target:"
git ls-files | grep 'apps/docs/content/guides/database/postgres/row-level-security.mdx$' || true

echo
echo "Target excerpt:"
if [ -f apps/docs/content/guides/database/postgres/row-level-security.mdx ]; then
  nl -ba apps/docs/content/guides/database/postgres/row-level-security.mdx | sed -n '1,100p'
fi

echo
echo "Search for service_role grants/reviews in docs:"
grep -RIn "service_role\|REVOKE ALL\|TRUNCATE\|REFERENCES\|TRIGGER" apps/docs || true

Repository: supabase/supabase

Length of output: 50373


🏁 Script executed:

#!/bin/bash
python3 - <<'PY'
from pathlib import Path
p = Path('apps/docs/content/guides/database/postgres/row-level-security.mdx')
print(f"exists={p.exists()} size={p.stat().st_size if p.exists() else None}")
lines = p.read_text().splitlines() if p.exists() else []
for i in [22,23,24,25,26,27,28,29,30,31,32,33,34]:
    if 0 <= i < len(lines):
        print(f"{i+1}: {lines[i]}")
PY

Repository: supabase/supabase

Length of output: 585


Revoke service_role before assigning its final ACL.

The REVOKE excludes service_role, so existing TRUNCATE, REFERENCES, or TRIGGER grants can remain even though only CRUD privileges are re-granted. Include service_role in the revoke, or explicitly state that those additional privileges are intentional.

Suggested fix
- FROM anon, authenticated;
+ FROM anon, authenticated, service_role;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
REVOKE ALL ON TABLE <schema_name>.<table_name>
FROM anon, authenticated;
GRANT SELECT ON TABLE <schema_name>.<table_name>
TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO authenticated;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO service_role;
REVOKE ALL ON TABLE <schema_name>.<table_name>
FROM anon, authenticated, service_role;
GRANT SELECT ON TABLE <schema_name>.<table_name>
TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO authenticated;
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE <schema_name>.<table_name>
TO service_role;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/content/guides/database/postgres/row-level-security.mdx` around
lines 23 - 33, Update the SQL privilege setup to include service_role in the
initial REVOKE ALL statement before granting its final CRUD privileges, ensuring
any existing TRUNCATE, REFERENCES, or TRIGGER grants are removed.

Comment on lines +16 to +25
### Review database privileges

Before going into production, review the table privileges granted to the `anon` and `authenticated` roles.

You can check current table grants using:

```sql
select *
from information_schema.role_table_grants
where grantee in ('anon', 'authenticated');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Keep Security Advisor as a complementary production check.

This change replaces a broad automated security review with a query that only inspects table grants for anon and authenticated. It will not detect missing/weak RLS policies, exposed sensitive columns, security-definer issues, or other advisor findings. Retain the Security Advisor instruction and add this privilege query. (supabase.com)

Suggested fix
+Check and review issues in your database using Security Advisor.
+
 ### Review database privileges
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
### Review database privileges
Before going into production, review the table privileges granted to the `anon` and `authenticated` roles.
You can check current table grants using:
```sql
select *
from information_schema.role_table_grants
where grantee in ('anon', 'authenticated');
Check and review issues in your database using Security Advisor.
### Review database privileges
Before going into production, review the table privileges granted to the `anon` and `authenticated` roles.
You can check current table grants using:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/docs/content/guides/deployment/going-into-prod.mdx` around lines 16 -
25, Update the “Review database privileges” section in the production deployment
guide to retain the existing Security Advisor check and present the
role_table_grants query as an additional complementary check. Ensure the
guidance still directs users to review broader findings, including RLS policies,
exposed columns, and security-definer issues.

This branch has not been deployed

No deployments
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.

Docs: the RLS guide's GRANT examples are a no-op in the public schema, and TRUNCATE is not covered by RLS

1 participant