multi-tenancy

Enforce tenant isolation across data access with TenantContext and JWT extraction.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/LawrenceWebon/eins --skill multi-tenancy-lawrencewebon
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multi-tenancy
Source: https://github.com/LawrenceWebon/eins/tree/main/ph-gov-platform/.agent/skills/multi-tenancy
Command: npx skills add https://github.com/LawrenceWebon/eins --skill multi-tenancy-lawrencewebon

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a standardized approach to enforce tenant isolation and schema separation across services, preventing data leakage between tenants.

Core Features & Use Cases

  • Tenant Context Holder using ThreadLocal to track the current tenant
  • JWT-based tenant extraction filter to set and clear TenantContext per request
  • Dynamic schema selection and optional Row-Level Security (RLS) for data access
  • Kubernetes namespace isolation and per-tenant network policies

Quick Start

Configure your application to extract the tenant_id from JWT and consistently apply TenantContext for all data access calls.

Frequently Asked Questions about multi-tenancy

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce data isolation in a multi-tenant Java application?

To enforce data isolation in a multi-tenant Java application, apply a tenant context to all data access operations. This ensures a tenantId is present in queries and persisted with entities, preventing data leakage between tenants.

How does JWT-based tenant extraction work for multi-tenant data isolation?

JWT-based tenant extraction works by using a filter to read the tenant_id from incoming JSON Web Tokens. The filter sets and clears the TenantContext per request, ensuring all subsequent database interactions are scoped to the correct tenant.

What is the best way to track tenant context during a request lifecycle?

The best way to track tenant context during a request lifecycle is using a ThreadLocal Tenant Context Holder. It maintains the current tenant identifier throughout the thread's execution, ensuring all repository access calls remain strictly scoped.

Does this multi-tenancy approach support row-level security and dynamic schema selection?

Yes, this multi-tenancy approach supports both dynamic schema selection and optional row-level security (RLS). These features enforce strict tenant isolation at the database interaction layer by applying tenant context to all queries.

Can I use Kubernetes namespace isolation for multi-tenant applications?

Yes, you can use Kubernetes namespace isolation alongside per-tenant network policies. This provides an additional layer of secure, scalable multi-tenant isolation by separating tenant workloads at the infrastructure level.

Why do I need a TenantContext for repository data access?

You need a TenantContext for repository data access to guarantee that every query includes the correct tenantId. Without this standardized context applied to all data access calls, multi-tenant applications risk unauthorized data leakage between tenants.