database-access-rules
Skill0 starsChanged 23 days agoMITView on GitHub
Design, write and test database access rules so each user can only see and change their own data - Postgres row-level security (including Supabase), Firebase Security Rules, or server-side ownership checks with an ORM (Prisma, Drizzle). Use when the user adds a table or collection, shares data between users or teams, sees "permission denied" errors, or asks if their data is private.
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- packs/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-rate-limitingSkill
- launch-polishSkill
- lean-changesSkill
- secure-api-endpointSkill
- stripe-webhook-setupSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Before launch, or after "can other users see my data?".
- Distinctive: line 25
Only your server talks to the database (Prisma, Drizzle, SQL): enforce in a data-access layer that always filters by the session user, and …
- Distinctive: line 41
Never disable RLS or open rules "temporarily" to debug.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database access rules
"Logged in" is not "allowed". This skill makes the database enforce who can read and write each row or document.
When to use
- A new table, collection or storage bucket.
- Multi-user or team features (orgs, shared projects, invites).
- Before launch, or after "can other users see my data?".
Steps
- Map access. For each table or collection, write a short matrix: who can select, insert, update, delete (anonymous, signed-in, owner, team member, admin). Ask the user to confirm anything public.
- Pick the enforcement layer.
- Browser talks to the database directly (Supabase, Firebase, PostgREST): rules must live in the database, using RLS policies or Security Rules.
- Only your server talks to the database (Prisma, Drizzle, SQL): enforce in a data-access layer that always filters by the session user, and give the app a least-privilege database role.
- Write the rules.
- Postgres: enable RLS on every exposed table; one policy per action;
usingfor reads,with checkfor writes;(select auth.uid())or your session function; helpersecurity definerfunctions for team membership with a fixedsearch_path; indexes on filtered columns. - Firebase: deny by default; match paths;
request.auth.uid == resource.data.ownerId; validate fields and types on create and update. - Storage: private buckets; per-user folders; signed URLs.
- Postgres: enable RLS on every exposed table; one policy per action;
- Write them as a migration or rules file in the repo, never only in a dashboard.
- Test with real identities. User A, user B and anonymous: A reads A's rows (allowed), A reads B's rows (denied), anonymous reads (denied unless public), A tries to set
user_idto B (denied). Use the Firebase emulator rules tests, pgTAP, or a small script with two test accounts on a local or staging database. - Report the access matrix, the policies, and the test results.
Output format
Access matrix table, migration or rules file, test file or script, and a pass/fail list from the tests.
Safety rules (always)
- Work on local or staging first. Show the migration and wait for an explicit "yes" before applying anything to production.
- Never disable RLS or open rules "temporarily" to debug. Debug with a test account instead.
- Admin or service-role credentials only from server environment variables; never print or commit them.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

