tenant-safe-change
Skill1 starsChanged 27 days agoApache-2.0View on GitHub
Use when adding or changing anything that stores or reads tenant-scoped data, meaning a migration or model on the tenant database, a seeder, a background job or cache holding tenant data, or any code that writes across tenants. Prevents row-level-security failures at runtime and silent cross-tenant leaks.
In this repository25 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-coordinationSkill
- api-code-generationSkill
- api-test-generationSkill
- ci-cd-changeSkill
- frontend-changeSkill
- guidance-maintenanceSkill
- infrastructure-changeSkill
- refactoringSkill
- secret-and-pii-handlingSkill
- secure-api-endpointSkill
- workspace-importSkill
- agent-coordinationSkill
- api-code-generationSkill
- api-test-generationSkill
- ci-cd-changeSkill
- frontend-changeSkill
- guidance-maintenanceSkill
- infrastructure-changeSkill
- refactoringSkill
- secret-and-pii-handlingSkill
- secure-api-endpointSkill
- tenant-safe-changeSkill
- workspace-importSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
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 39
Seeders: use the sanctioned bypass mechanism, not a superuser kept for convenience.
- Distinctive: line 46
Write a test that asserts both same-tenant success and cross-tenant denial, running as the application role.
≈ “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
Tenant-safe change
Required context
- The guardrail
.agents/areas.jsondeclares for the area you are changing, and the migration that enables forced row-level security. Read the list of covered tables from that code, never from a document: the code is what production runs. .agents/policy/data-classification.yml: tenant data is confidential; handling follows..agents/skills/secure-api-endpoint/SKILL.md: when the change is also an endpoint.- The sibling model or migration on the same connection.
The rules that bite
- An insert must match the session's tenant context. An isolation policy with a
USINGclause and noWITH CHECKgates inserts too. An insert whose tenant id differs from the context set for the request fails with a permission error at runtime, usually on a path the tests exercised as the wrong role. - Cross-tenant writes use the one audited bypass path. Signup, invitation and staff operations go through the sanctioned mechanism. Never a superuser connection, never a connection switch to dodge isolation: those paths are invisible to the audit.
- A new tenant-scoped table joins forced isolation in the policy migration, or carries a written, justified exemption beside the existing ones. First confirm it is only written inside a request that sets the tenant context; forcing isolation on a table written outside that context turns a leak into an outage.
- Declare the connection. A migration or model for a non-default database states it; a missing declaration lands the table on the default database silently.
- The application role is not a superuser. A superuser bypasses row-level security, so tests that connect as one pass while production leaks or fails. Tests run as the application role.
- Context does not travel by itself. Jobs, schedulers and queue consumers set the tenant context explicitly. Cache keys for tenant data include the tenant id.
- Scoped relations for non-members. Where a global tenant scope hides a row the caller may legitimately see (an invitee resolving the workspace they were invited to), remove the scope for that one relation explicitly; a re-scoping lazy load returns nothing.
- Seeders use the sanctioned bypass mechanism, not a superuser kept for convenience.
Steps
- Decide what the write is: tenant-scoped, bootstrap (signup, invitation) or staff.
- Tenant-scoped: every insert carries the context's tenant id; a new table joins forced isolation.
- Bootstrap or staff: route through the audited bypass path only.
- Write a test that asserts both same-tenant success and cross-tenant denial, running as the application role. A test that would pass with the policy dropped proves nothing.
Verify
<the area's test runner, filtered to the tenancy tests> # success and denial, as the app role
make verifyThen the area's verify command exactly as .agents/areas.json declares it. If the service
exposes a health check for the bypass role model, a red one means a misconfigured role: fix the
role, never work around it. Reviewer: tenant-safety-reviewer.
Escalate when
- A migration changes or drops an isolation policy, or exempts a table from it.
- Data must be moved or backfilled across tenants.
- A change needs a new bypass path or a new privileged role.
- Anything would run against a shared or production database.
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.

