多租戶 AI 智能體的儲存設計:子目錄並非安全隔離邊界
Per-tenant storage for multi-tenant AI agents: a subdirectory is not a security boundary
作者指出,多租戶 AI 智能體共用儲存卷時,單靠子目錄不足以隔離不受信任的程式碼。原因是掛載憑證可能涵蓋整個儲存卷,而 POSIX 權限也無法阻止可變更 UID 的程序存取其他租戶目錄。文章比較 EFS access point、具範圍限制憑證的 S3 prefix、每租戶一個 volume 及 Archil disk;Archil 磁碟的憑證只可存取該磁碟,檔案可在沙盒重啟後保留。
If you run a multi-tenant agent product, every customer's agent eventually needs somewhere to keep files: uploaded documents, a cloned repo, intermediate results, a SQLite database it builds up over days. The obvious first design is one shared volume with a directory per tenant. It works in a demo, and it's the wrong isolation boundary once the agent runs code you didn't write.
This post walks through the options I see teams use, what each one actually isolates, and where each one fits.
Why a subdirectory per tenant isn't isolation
Say every tenant's sandbox mounts the same volume, and tenant A's agent is supposed to stay in /data/tenant-a. Two things undo that:
-
The credential covers the whole volume. Whatever lets the sandbox mount
/data/tenant-a(an NFS export, a mount token, an IAM grant) usually lets it mount/data. If the agent can read its own environment or a config file, it can mount everything. -
POSIX permissions aren't a boundary against untrusted code. Agents run generated code, often as root inside the sandbox.
chmod 700doesn't protect tenant B's directory from a process that can become any UID.
Subdirectories are great for organizing work within one tenant, such as a directory per agent or per task. Between tenants you want a boundary that the credential itself enforces.
Option 1: Amazon EFS with an access point per tenant
If everything runs on AWS, this is a solid pattern. An EFS access point pins a client to a root directory and a POSIX identity, so a client mounted through tenant A's access point can only see tenant A's directory tree. To make that a real boundary, require IAM authorization and write a policy that only lets tenant A's role mount through tenant A's access point (the elasticfilesystem:AccessPointArn condition key).
Things to know:
- A file system supports 10,000 access points by default, so very large tenant counts mean several file systems or a quota increase.
- Clients mount with the EFS mount helper using the
iamoption; it's NFS, so it's AWS-only in practice. - Each tenant needs an IAM role or session policy that names its access point.
Option 2: An S3 prefix per tenant with scoped credentials
Give each tenant a prefix such as s3://bucket/tenants/<id>/, and hand its workers short-lived credentials from AssumeRole with a session policy that only allows that prefix. This is strong isolation and cheap at any tenant count.
The catch is that agents want files, not objects. You're back to either downloading and uploading around every agent step, or running a FUSE client over the prefix. Most S3 FUSE clients don't handle in-place edits, renames or SQLite well; I covered that in Giving an AI agent file access to an S3 bucket.
Option 3: A volume per tenant
The cleanest boundary is one volume per tenant, with credentials that can only reach that volume. Block volumes (EBS) give you this but attach to one machine at a time, which doesn't fit agents that run in short-lived sandboxes or several workers at once. An EFS file system per tenant works too, but accounts start with a quota of 1,000 file systems per Region, and each tenant still needs its own mount targets and IAM setup.
Option 4: A disk per tenant on Archil
This is what we built Archil for. A disk is the isolation unit: its credentials are scoped to that one disk, including its branches and checkpoints. Creating one is a single API call (9.3 ms at p50), so you can create it at tenant signup, or lazily the first time that tenant's agent runs.
import * as archil from "disk";
// On your backend, with your Archil API key.
const { disk, token } = await archil.createDisk({ name: `tenant-${tenantId}` });
// Store disk.id with the tenant. `token` mounts this disk only and is returned once.
// Later: issue a token for one worker, or revoke it.
const user = await disk.createToken(`worker-${workerId}`);
await disk.removeUser("token", user.identifier);
Run that tenant's agents in a sandbox that mounts only its disk. With Archil's own sandboxes, the mount is authenticated for you, so the sandbox never holds a token:
import { Archil } from "disk";
const client = new Archil({ apiKey: process.env.ARCHIL_API_KEY, region: "aws-us-east-1" });
const sandbox = await client.sandboxes.create({
baseImage: "ubuntu:24.04",
mounts: [{ disk: tenantDiskId, path: "/mnt/archil" }],
});
The files live on the disk, not the sandbox, so they survive sandbox restarts, and the next sandbox for that tenant sees the same files. The same disk mounts over FUSE in other providers' sandboxes (E2B, Modal, Daytona, Vercel Sandbox) and is readable from your web app over an S3 API with per-tenant, expiring credentials.
Two things that matter at thousands of tenants:
- Idle tenants are cheap. Storage is metered on the data each disk holds, not on the number of disks. Data stays at the active rate for up to an hour after its last access, then an idle tenant's disk falls back to the lower archive rate (or, if the disk syncs to the tenant's own bucket, to just that bucket). Most tenants are idle most of the time.
- Offboarding is one call. Revoke the tenant's tokens and delete the disk. If a tenant brought their own bucket, deleting the disk stops syncing and leaves their objects with them.
The docs have the full guide, including tenants who bring their own bucket: Isolated per-tenant storage.
A checklist, whatever you pick
- Keep org-wide credentials (API keys, admin IAM roles) on your backend. Never put them in a tenant's sandbox.
- Give each tenant's workers credentials that can reach only that tenant's data, and give them expiries.
- Use subdirectories, branches or separate mounts to separate agents within a tenant, not between tenants.
- Decide up front what deleting a tenant means for their data, and test it.
How are you isolating tenant data for agents today? I'm curious what's worked, and what hasn't, in the comments.
來源:DEV Community · dev.to