agentleFS
hi-donwihi-donwi/Donwi-Skills/skills/saas-multitenancy/SKILL.md

saas-multitenancy

Skill0 starsChanged 12 days agoMITView on GitHub

Enforce multi-tenant data isolation, trusted tenant context, row-level security, and noisy-neighbor limits. Use for shared customer infrastructure, not membership lifecycles or private agent context sharing.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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:

    Test two tenants with colliding identifiers, absent and forged scope, reused connections, failed transactions, exports, and retries.

    line 48

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

SaaS Multi-Tenancy

Overview

Make the tenant boundary enforceable across requests, persistence, asynchronous work, and shared infrastructure. Authentication, membership, and isolation are separate checks.

When to use

  • Choosing pooled, schema, database, or infrastructure isolation for customer data.
  • Preventing cross-tenant access in queries, caches, files, search, exports, and workers.
  • Testing connection-pool reuse and per-tenant resource fairness.

Hand off when

NeedSkill
Invitations, member status, and owner transfermembership-management
Tenant provisioning, suspension, and deletionsaas-onboarding
Private agent notes and context audiencescontext-privacy
Quarkus persistence implementationquarkus-persistence

Process

  1. Classify global and tenant-owned data. Choose isolation from contractual residency, restore, scale, and operational requirements; document residual shared-service risks.
  2. Resolve a requested tenant, then verify the authenticated actor's active membership or scoped service credential. A header, host, URL, or signed stale claim is not enough.
  3. Propagate immutable verified scope explicitly or through a correctly bounded runtime context. Fail closed when missing; clear it after each request and worker execution.
  4. Enforce scope on reads and writes, including raw SQL and bulk operations. In pooled schemas use scoped unique keys and composite foreign keys to prevent cross-tenant links.
  5. For PostgreSQL RLS, use a restricted runtime role and transaction-local settings on the same connection. Check both USING and WITH CHECK; test privileged bypass separately.
  6. Namespace caches, search filters, storage objects, signed downloads, and job payloads. Workers verify job ownership and current policy before constructing fresh context.
  7. Apply aggregate tenant quotas, concurrency limits, and bounded queues; optional IP limits supplement rather than replace tenant-wide noisy-neighbor controls.
  8. Test two tenants with colliding identifiers, absent and forged scope, reused connections, failed transactions, exports, and retries. Never use an admin role only.

Red flags

  • Treating RLS, database-per-tenant, or a tenant ID in a message as an absolute guarantee.
  • Runtime roles with superuser, BYPASSRLS, ownership, or unnecessary privileged functions.
  • Client-selected scope, unscoped foreign keys, or context surviving connection reuse.
  • Assuming every identity must be duplicated per tenant instead of classifying global data.

Verification

  • Cross-tenant reads, writes, links, files, and exports are denied under the runtime role.
  • Missing scope fails closed; connection and worker reuse never inherit another tenant.
  • Per-tenant restore, throttling, and privileged administration have explicit boundaries.

References

  • references/isolation-strategies.md - isolation choices and transaction-safe RLS.
  • references/tenant-context.md - verified scope across synchronous and asynchronous work.

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.