agentleFS
DariuszDuszaDariuszDusza/agentic-workflow-foundry/.agents/skills/tenant-safe-change/SKILL.md

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.

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
  1. Distinctive:

    Seeders: use the sanctioned bypass mechanism, not a superuser kept for convenience.

    line 39
  2. Distinctive:

    Write a test that asserts both same-tenant success and cross-tenant denial, running as the application role.

    line 46

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Tenant-safe change

Required context

  1. The guardrail .agents/areas.json declares 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.
  2. .agents/policy/data-classification.yml: tenant data is confidential; handling follows.
  3. .agents/skills/secure-api-endpoint/SKILL.md: when the change is also an endpoint.
  4. The sibling model or migration on the same connection.

The rules that bite

  1. An insert must match the session's tenant context. An isolation policy with a USING clause and no WITH CHECK gates 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. Seeders use the sanctioned bypass mechanism, not a superuser kept for convenience.

Steps

  1. Decide what the write is: tenant-scoped, bootstrap (signup, invitation) or staff.
  2. Tenant-scoped: every insert carries the context's tenant id; a new table joins forced isolation.
  3. Bootstrap or staff: route through the audited bypass path only.
  4. 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 verify

Then 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.