How do I prove tenant isolation to a customer in a Laravel app?
You prove tenant isolation by showing how your Laravel application keeps each tenant’s data apart and by giving the customer evidence they can check. A tenant is one customer organisation using your shared application. A statement that each customer has separate data proves nothing. Blocked and logged attempts to cross the boundary do.
Quick answer
To prove tenant isolation in a Laravel app, show the customer how tenant context is established and enforced. Then run cross-tenant tests that try to break it and share a dated CI report. Depending on your architecture and the customer’s security requirements, add database-level controls, an audit trail, and an independent penetration test. No single artifact proves isolation alone.
How to prove tenant isolation to a customer, step by step
1. Describe your isolation model on one page
Name the model you use. Each has strengths and gaps, because each depends on configuration you also need to explain.
- A shared database with a
tenant_idcolumn depends on every query, job, and export applying the right tenant. - A schema per tenant gives each tenant its own tables inside one database. It still depends on selecting the correct schema per request and on roles that cannot read other schemas.
- A database per tenant gives stronger structural separation. It still depends on selecting the correct connection, on credentials limited to that tenant’s database, and on jobs that receive the right tenant. One privileged credential that opens every tenant database weakens the separation.
Then list what tenants still share: cache, queues, file storage, search indexes, logs, and scheduled jobs.
2. Enforce tenant boundaries in application code
Set the current tenant from the authenticated user’s verified membership. A tenant ID in a header, URL, or request body only asks the server to select a tenant. The server must confirm the user belongs to it. The OWASP multi-tenant security cheat sheet gives the same rule.
- Middleware resolves the tenant and checks membership before protected code runs.
- Policies and gates decide whether a user may act on a specific record.
- Query scoping restricts reads to the current tenant.
This policy suits users who belong to one tenant. Applications with several memberships should check the user’s authorised membership instead.
public function view(User $user, Order $order): bool
{
return $user->tenant_id === $order->tenant_id;
}
An Eloquent global scope adds a constraint such as where tenant_id = ? to every query made through a model. It does not apply to raw queries or query-builder calls such as DB::select() and DB::table(), and withoutGlobalScopes() removes it. A scope is a useful safety net. Policies and ownership checks still do the authorising, and OWASP describes ORM-level filtering as defence in depth.
3. Write cross-tenant tests for every operation
To prove tenant isolation in code, create two tenants with their own users and records. Sign in as a user of tenant A and attack tenant B’s data. Decide the response your API should give before you write the assertion. A 403 means access is denied, and it tells the caller the record exists. A 404 can deliberately hide that another tenant’s record exists.
This test expects a 403. It assumes route binding finds the record and the controller authorises it with the policy above. If your application hides other tenants’ records, use assertNotFound() instead.
it('forbids reading another tenant\'s order', function () {
$tenantA = Tenant::factory()->create();
$tenantB = Tenant::factory()->create();
$userA = User::factory()->for($tenantA)->create();
$orderB = Order::factory()->for($tenantB)->create();
$this->actingAs($userA)
->getJson("/api/orders/{$orderB->id}")
->assertForbidden();
});
Writes need their own test. This one assumes the application ignores a client-supplied tenant_id, returns a 201, and stores the order under the signed-in user’s tenant. A specific order number keeps the assertions about the record this test created.
it('stores new orders under the signed-in user\'s tenant', function () {
$tenantA = Tenant::factory()->create();
$tenantB = Tenant::factory()->create();
$userA = User::factory()->for($tenantA)->create();
$this->actingAs($userA)
->postJson('/api/orders', [
'order_number' => 'ORD-900',
'tenant_id' => $tenantB->id,
])
->assertCreated();
$this->assertDatabaseHas('orders', [
'order_number' => 'ORD-900',
'tenant_id' => $tenantA->id,
]);
$this->assertDatabaseMissing('orders', [
'order_number' => 'ORD-900',
'tenant_id' => $tenantB->id,
]);
});
Both tests assume the models define a tenant relationship, the tests use the RefreshDatabase trait, and the model names are placeholders. If your application rejects a mismatched tenant ID instead, assert that rejection and check that no row with that order number exists.
Repeat the pattern for updates, deletes, and the list, search, and report endpoints. Run the suite in CI on every merge and give the customer a dated report from your pipeline.
4. Check the other access paths
A secure web page does not prove that every other component enforces the same boundary. Review the paths your application actually has.
- File storage: a user must not read, replace, or delete another tenant’s file by changing an identifier or path. A storage prefix alone does not authorise access.
- Cache: tenant-specific values need tenant-aware keys, user-specific values need user or permission context, and intentionally shared data can use global keys. Caching never replaces authorisation.
- Queues and jobs: pass the tenant to each job, validate it when the job runs, and make sure workers never reuse the previous job’s tenant.
- Search: apply a tenant filter to every query, or keep separate indexes per tenant.
- Sessions and tenant switching: check membership again when a user switches tenant.
- Exports, notifications, and webhooks: files, email attachments, and outbound payloads must contain only the authorised tenant’s data. Tenant-specific API credentials should reach only that tenant’s data.
5. Add database-level controls when your architecture calls for them
Database-level controls make the database enforce part of the boundary. They are optional, and Laravel does not require them. Whether you need them depends on your isolation model and the customer’s security requirements.
PostgreSQL row-level security (RLS) is one option. It is a PostgreSQL feature, not a Laravel feature. You enable it on a table and attach policies that decide which rows a query can see. The PostgreSQL documentation describes how it behaves. Four details matter here.
- Superusers and roles with the BYPASSRLS attribute bypass row-level security.
- Table owners normally bypass it too, unless the table has
FORCE ROW LEVEL SECURITYenabled. - Ordinary application requests should use a restricted role with neither privilege. Run migrations and administration with a separate privileged credential.
- Set the tenant with
SET LOCALinside a transaction. The value ends with that transaction, and the command has no effect outside a transaction block. The protected queries must run in the same transaction.
Prefer SET LOCAL over a session-level SET. When a connection pool reuses a database session, session-level tenant state can reach the next request.
6. Provide audit evidence
Application logs and an audit trail are different things. Log::withContext() adds fields, such as a tenant ID, to later log entries in that channel. It does not record reads, updates, or deletes by itself. For sensitive actions, write explicit audit events with the tenant, the actor, the action, and a timestamp.
Laravel’s Context facade captures its data when a job is dispatched and restores it while the job runs. For queued jobs, add the tenant to the job itself and set the log context again when it starts.
Customers also ask who on your team can see their data. Document how support and administrative access is requested, approved, and logged.
7. Add independent assurance and assemble the package
A penetration test that names cross-tenant access as an explicit goal gives the customer an outside view. A SOC 2 or ISO 27001 report shows your controls were audited, but it usually does not test your own tenant boundary. Whether you need either depends on the customer and the risk.
To prove tenant isolation in a security review, prepare one short package. The core is the one-page isolation model, an explanation of how tenant context is enforced, and the dated cross-tenant CI report. Add database-level evidence, audit samples, and a penetration test summary shared under NDA where they apply.
If the customer wants to see it live, run a demonstration with two test accounts in different tenants. Use synthetic data or accounts the customer has approved.
What this evidence does not prove
When you prove tenant isolation, avoid the word “guarantee”. No one can show that a leak is impossible, and a clean test run says nothing about code paths the tests never touch. State what you tested, how often, and what you do not cover. Update the tests whenever you add an endpoint, job, or export. Reviewers trust a stated limit more than a flat assurance.
What to do first
Before you try to prove tenant isolation to a customer, review your actual isolation architecture and list every place a request, job, or export reads tenant data. Fix the paths that lack a tenant check and write cross-tenant tests for them. Then add the defence-in-depth controls that suit your architecture and the customer’s requirements. Our Laravel development services can support that review.
Related Answers
Still need help?
Questions about proving tenant isolation to a customer?
If you're preparing isolation evidence for a customer security review, we're happy to walk through your architecture, your tests, and what to add.
