PraneoTech
Multi-Tenant File Storage Is More Than Adding a tenant_id Column
Why keeping customer files separated is an authorization and ownership problem and how Orvex models that boundary.

Most SaaS teams learn the same lesson the hard way: once files enter the product, multi-tenancy stops being a database modeling exercise.
A tenant_id on a row is useful. It is not isolation.
File systems make that obvious. Metadata lives in your database. Bytes live in object storage. Temporary URLs can leave your API entirely. Folder names collide across customers. Identifiers leak through logs, support tools, and client-side state. If authorization is incomplete on even one path—download, delete, replace, list, or “get URL”—tenant boundaries become aspirational.
That is the problem Orvex was built around as it moved from a single-application image server into a shared file service.
Isolation is not a column. It is a chain of enforcement.
In a shared-database design, every tenant’s records sit next to every other tenant’s records. Relationships can express ownership. They cannot enforce it.
Orvex uses logical separation in one PostgreSQL database. Its ownership model follows four connected levels:
User: The credential principal authenticated through an API key.
Domain: An application or logical scope owned by that user.
Folder: An organizational namespace belonging to a domain.
File: An individual file belonging to a folder, with a storageId referencing its object in R2.
A file does not carry a free-floating tenant_id as its primary security boundary. Its ownership is resolved through its parent relationships. When a request arrives with an API key, Orvex has to answer a concrete question:
Does this authenticated principal own the domain that owns this file?
If that check is missing, the schema still looks multi-tenant. The system is not.
Storage makes the same point from another angle. Even when object keys are namespaced—Orvex stores objects under paths shaped like /{userId}/{domainId}/{folder}/{fileId}.ext—path conventions are not authorization. Anyone who can call delete or download with a file ID still needs a server-side ownership check before the provider operation runs.
Tenant isolation therefore spans:
Database queries scoped by ownership.
API authorization on every mutating and reading path.
Careful handling of provider URLs and object identifiers.
Operational discipline around who receives which credentials.
A column helps you query. Authorization keeps customers apart.
Domain scoping prevents namespace collisions
In Orvex, a domain represents an application or logical scope owned by a user. It does not necessarily refer to a public DNS name. One user can own multiple domains, and folders are unique within each domain using name + domainId.
This allows two different domains to have folders with identical names, such as invoices, without creating a shared namespace.
The distinction becomes important when an application makes a request using only a folder name. Listing folder=invoices without binding the request to a domain leaves the system to resolve an ambiguous scope.
To avoid that ambiguity, Orvex requires an explicit domainId on upload, list, and folder operations when a user owns multiple domains. A single-domain user can omit it; multi-domain users cannot. The service refuses to guess which scope the caller intended.
That is a small API detail with a large security implication: ambiguous scope is a cross-tenant bug waiting to happen.
Authorization has to live at the file-operation level
Authenticating the caller is not enough. Knowing who they are does not answer what they may touch.
In Orvex, application traffic authenticates with X-API-Key. For operations on a specific fileId—download, update, delete, and protected URL access—the flow is:
Resolve the API key to a user.
Load the file with its folder and domain.
Compare file.folder.domain.userId to the authenticated user.id.
Only then talk to storage or return bytes.
If the ownership check fails, the response is 403, not a silent filter miss or a provider error.
Listing is scoped differently but follows the same principle: resolve the caller’s domains, select one domain, resolve the folder inside that domain, then list files for that folder only. You never list “all files in the database matching this folder name.”
Every file operation needs the appropriate authorization boundary:
Upload: Into a domain the user owns.
List: Within a domain/folder the user owns.
Download / Update / Delete: File whose owning domain belongs to the user.
Protected URL: Same ownership gate as download.
Miss one operation and the others cannot save you.
API keys and domain IDs are part of the security model
Orvex separates two planes:
Application plane: File operations with user API keys (X-API-Key).
Control plane: SuperAdmin JWT API for creating users, attaching domains, and key recovery.
That split is deliberate. The file API should not invent tenants ad hoc on every upload. Someone has to decide:
Which applications get which Orvex user.
Which domains those users own.
Which backend service receives which API key.
Which domainId that backend passes on each request.
Orvex can enforce “this key may only act inside its domains.” It cannot decide whether your billing service and your support tool should share a key, or whether your frontend should ever see a key at all.
For SaaS developers integrating a shared file service, that responsibility usually sits in the consuming application:
Map your customer/org to an Orvex domain (or to an Orvex user + domains).
Keep API keys in server-side secrets, not browsers.
Pass the correct domainId when a principal spans multiple scopes.
Rotate or recover keys through the control plane when credentials leak.
Multi-tenant file storage fails socially as often as it fails technically: the wrong key in the wrong service, or the wrong domain ID on the right key.
Common mistakes in multi-tenant file systems
These show up repeatedly—including in systems that “already have tenants.”
1. Trusting the schema to enforce isolation
Foreign keys preserve structure. They do not stop findUnique({ id: fileId }) from returning another tenant’s row if you skip the ownership comparison.
2. Authorizing create but not read/update/delete
Upload paths often get the most attention. IDOR bugs love GET /files/:id/download and DELETE /files/:id.
3. Using folder names as global namespaces
folder=documents across tenants is not a boundary unless the query is domain-scoped.
4. Treating object storage paths as security
Prefixing keys with tenantId/ helps operations and reduces accidents. It does not replace API checks.
5. Forgetting indirect access paths
Temporary URLs, public buckets, CDN caches, and “unprotected file URL” endpoints expand the attack surface.
In Orvex, unprotected files can obtain a temporary storage URL without an API key; protected files require a key and an ownership check. That distinction is a product decision with security consequences. If a file should not be world-reachable via ID, it should not be unprotected.
6. Letting clients choose tenant context freely
Accepting a client-supplied tenantId / domainId without verifying membership is equivalent to optional isolation. Orvex only accepts a domainId that already belongs to the authenticated user.
7. Shared credentials across products
One API key for “all internal apps” collapses blast radius planning. Domain scoping helps, but key distribution still matters.
What developers should test to prevent cross-tenant access
If you only test happy paths, you will ship a multi-tenant UI on a single-tenant security model. Prefer explicit negative tests.
Identity and scope
Request with missing/invalid API key → 401 on protected operations.
User A’s key + User B’s fileId on download/update/delete → 403.
User with domains D1 and D2 uploads to D1, then lists with D2 + same folder name → no D1 files.
Multi-domain user omits domainId → rejected; does not fall back to “first domain” silently for write/list if your policy forbids guessing.
User supplies another user’s domainId → rejected.
Enumeration and metadata
Cross-tenant fileId does not leak storage paths, encryption metadata, or domain details in error bodies beyond what you intend.
Listing never returns files outside the resolved domain/folder.
Storage side effects
Failed auth does not delete or overwrite provider objects.
Successful delete/update only affects objects owned through the verified chain.
URL and protection modes
Protected file URL/download without key → denied.
Protected file with wrong key → denied.
Unprotected URL behavior matches your threat model; if IDs are guessable or leakable, unprotected may be the wrong default for sensitive content.
Control plane
Domain values cannot be attached in ways that collide across tenants unexpectedly.
Recovered/rotated keys invalidate old credentials for file access.
These tests are not exotic. They are the minimum proof that ownership is enforced where bytes move.
The core argument
Multi-tenancy for files is not “we added a tenant foreign key.”
It is:
An ownership model you can explain.
Authorization on every operation that touches an ID.
Explicit scope when a caller spans multiple domains.
Disciplined assignment of API keys and domain IDs.
Honesty about shared databases and indirect access paths like temporary URLs.
Orvex exists because file handling is easy to underestimate until several applications need the same guarantees. The service’s job is not merely to store objects. It is to keep the relationship between principal, domain, folder, and file intact on every request—while the consuming application stays focused on its own product logic.
A tenant_id column can start that design. Only consistent authorization finishes it.