Repository navigation
docs: clarify RLS grants and production privilege checks - #48413
paraggulve2641 wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
@paraggulve2641 is attempting to deploy a commit to the Supabase Team on Vercel. A member of the Team first needs to authorize it. |
|
Thanks for contributing to Supabase! ❤️ Our team will review your PR. A few tips for a smoother review process:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe documentation updates add explicit privilege revocation to the RLS SQL example and replace production security guidance with instructions for reviewing ChangesRLS privilege guidance
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
apps/docs/content/guides/database/postgres/row-level-security.mdxapps/docs/content/guides/deployment/going-into-prod.mdx
| 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; |
There was a problem hiding this comment.
🔒 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 || trueRepository: 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:
- 1: https://www.postgresql.org/docs/18/ddl-rowsecurity.html
- 2: https://www.postgresql.org/docs/current/ddl-rowsecurity.html
- 3: https://www.postgresql.org/docs/16/ddl-rowsecurity.html
- 4: https://wiki.postgresql.org/wiki/RLS
- 5: https://www.alibabacloud.com/help/en/rds/apsaradb-rds-for-postgresql/implementation-of-saas-tenant-data-isolation-solution-based-on-row-level
🏁 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 || trueRepository: 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:
- 1: https://www.postgresql.org/docs/18/sql-grant.html
- 2: https://www.postgresql.org/docs/17/sql-grant.html
- 3: https://www.postgresql.org/docs/current/ddl-priv.html
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.
| 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; |
There was a problem hiding this comment.
🔒 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 || trueRepository: 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:
- 1: https://www.postgresql.org/docs/19/sql-revoke.html
- 2: https://www.postgresql.org/docs/12/sql-revoke.html
- 3: https://www.postgresql.org/docs/18/sql-revoke.html
- 4: https://www.postgresql.org/docs/16/sql-revoke.html
🏁 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 || trueRepository: 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]}")
PYRepository: 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.
| 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.
| ### 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'); |
There was a problem hiding this comment.
🔒 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.
| ### 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.
e76962e to
72f0ae4
Compare
Overview
This updates the RLS documentation to clarify default privileges in the public schema and improve production security guidance.
Changes
Related Issue
Fixes #48382
Summary by CodeRabbit