agentleFS
TheBeardedBearSASTheBeardedBearSAS/claude-craft/.claude/skills/multitenant/SKILL.md

multitenant

Skill108 starsChanged 6 days agoMITView on GitHub

Architecture multitenant avec approche tiered (Shared/Dedicated Schema/DB), RBAC/ABAC, field-level encryption. Use when working with multitenant applications, tenant isolation, data segregation.

The file

Files
SKILL.md

Multitenant — Quick Reference

Servir plusieurs clients (tenants) sur la même base de code avec isolation stricte et un coût d'infra contrôlé.

Trois tiers d'isolation

TierIsolationCoûtCas d'usage
Tier 1 — Shared schemacolonne tenant_id partout, filtres SQL automatiquesFaibleStartups, free / petits clients
Tier 2 — Dedicated schemaun schéma PostgreSQL par tenantMoyenSMB, clients exigeants
Tier 3 — Dedicated DBune base entière par tenantÉlevéEnterprise, compliance stricte (HDS, FedRAMP)

Règle de migration : commencer Tier 1, migrer un client en Tier 2/3 quand il représente > 20 % du revenu OU exige un SLA spécifique.

Cinq invariants non-négociables

  1. tenant_id propagé à chaque requête (AsyncLocalStorage / SecurityContext / middleware).
  2. PostgreSQL Row-Level Security (RLS) activé sur TOUTES les tables. Filet de sécurité contre un oubli applicatif.
  3. Tests d'isolation obligatoires. Tenant A ne doit jamais lire/écrire les données de B — y compris via tri, requête nuée, agrégat.
  4. Audit trail isolé par tenant. Pas de log multi-tenant cross-référencé sans permission explicite.
  5. Field-level encryption sur PII / secrets sensibles (Halite PHP, Eloquent Casts, libsodium).

Pattern minimal — Shared schema + RLS

ALTER TABLE invoices ADD COLUMN tenant_id UUID NOT NULL;
ALTER TABLE invoices ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON invoices
  USING (tenant_id = current_setting('app.tenant_id')::uuid);
// Symfony — middleware qui set la variable session pour RLS
$conn->executeStatement(
    'SET LOCAL app.tenant_id = :tid',
    ['tid' => $tenantId]
);

Anti-patterns critiques

  • ❌ Oublier le filtre tenant_id dans une requête raw → fuite cross-tenant.
  • ❌ Cache Redis sans préfixe tenant → données de A retournées à B.
  • ❌ Job worker async qui perd le tenant_id → impossible de retrouver le contexte.
  • ❌ Signed URLs / tokens sans tenant_id dans le payload → utilisable cross-tenant.
  • ❌ Field encryption avec une clé unique partagée → compromission = exposition totale (préférer keys per tenant).

RBAC / ABAC

  • RBAC : rôles globaux (admin, member, viewer) suffisent pour 80 % des cas.
  • ABAC : passer à des policies (Casbin, Cerbos, OPA) quand les règles dépendent d'attributs (région, montant, statut).

Pour aller plus loin

Patterns détaillés par tier, migration tier 1 → tier 2 sans downtime, tests d'isolation (Pest + tenant fixtures), RBAC/ABAC, exemples Laravel + Symfony, checklists par phase : voir @.claude/skills/multitenant/REFERENCE.md.

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.