Home / AI & GenAI

AI & GenAIChecklistAdvanced

Checklist: tenant isolation for a shared LLM service - identity, prefix and semantic caches, adapters, indexes, logs and noisy neighbours

A layer-by-layer checklist for serving many customers or business units from one LLM stack without cross-tenant leaks through caches, adapters, vector indexes, logs or shared capacity.

Deepak Bhardwaj8 min read

Applies toShared LLM platforms built on Azure OpenAI or Bedrock behind a gateway (API Management, LiteLLM), self-hosted vLLM 0.9+ (V1 engine), Redis semantic caches, pgvector or vector databases, OpenTelemetry tracing

Why this needs its own checklist

When one LLM stack serves many tenants, data rarely leaks through the model itself. It leaks through the components around the model: a cache keyed without the tenant, a vector query missing a filter, a trace store everyone can read, or a LoRA adapter any API key can call. Each layer needs its own isolation control and its own test.

Work through the layers in order. Any line you can't tick is an open finding.

1. Identity and routing

  • Every request carries a tenant ID that comes from the authenticated credential (gateway subscription key, virtual key, JWT claim), never from a header or body field the client sets.
  • The gateway removes any client-supplied x-tenant-id and sets its own.
  • A per-tenant allow-list of models and deployments is enforced at the gateway.
  • Back-end credentials (provider keys, managed identities) are never returned to clients or logged.

APIM policy fragment that derives the tenant from the validated token:

<validate-jwt header-name="Authorization" require-scheme="Bearer" output-token-variable-name="jwt">
  <openid-config url="https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration" />
</validate-jwt>
<set-header name="x-tenant-id" exists-action="override">
  <value>@(((Jwt)context.Variables["jwt"]).Claims.GetValueOrDefault("tid", "unknown"))</value>
</set-header>

2. Self-hosted KV prefix cache

Prefix caching reuses KV blocks for identical prompt prefixes. Across tenants, two risks follow. First, timing differences can show that another tenant sent the same prefix. Second, any cache bug becomes a cross-tenant bug.

  • Decide whether tenants may share prefix-cache entries. In regulated settings the answer is usually no.
  • On vLLM V1, the gateway sets cache_salt per tenant, so only requests with the same salt reuse cached blocks.
  • The salt is derived on the server side (for example HMAC of the tenant ID) and clients cannot override it.
  • If an engine has no per-request cache isolation, either give sensitive tenants a dedicated replica or disable prefix caching for them.
curl -s http://vllm:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
  "model": "llama-70b",
  "messages": [{"role":"user","content":"Summarise ticket 4411"}],
  "cache_salt": "t-7f3a9c"
}'

Tip

Salting per tenant keeps prefix reuse inside each tenant, so a long shared system prompt still caches well. You lose only cross-tenant reuse, which you didn't want anyway.

3. Semantic and response caches

  • The cache key includes the tenant ID, model, prompt version, and the user's permission scope when answers depend on document ACLs.
  • Tenants are separated with key prefixes or separate databases, and lookups can't fall through to another tenant's prefix.
  • Each tenant can be purged on its own.
import hashlib
def cache_key(tenant, model, prompt_ver, acl_scope, normalized_q):
    h = hashlib.sha256(f"{model}|{prompt_ver}|{acl_scope}|{normalized_q}".encode()).hexdigest()
    return f"llmcache:{tenant}:{h}"
# Purge one tenant without touching others (SCAN, never KEYS, in production)
redis-cli --scan --pattern 'llmcache:t-7f3a9c:*' | xargs -r -n 500 redis-cli UNLINK

For vector-based semantic caches, put the tenant in a filter on the vector query itself, not in a post-check after the nearest neighbour comes back.

4. Provider-side features

  • You know which provider features keep state: stored responses, threads, files, batch inputs, fine-tuning datasets, vector stores.
  • Each of those objects is tagged or named per tenant, and your app checks ownership before it fetches one by ID.
  • Provider prompt caching is scoped to your organisation or account, not to your tenants. Check the current documentation for how your provider scopes cache entries and retention.

5. Fine-tuned adapters and models

  • Each tenant's LoRA adapter can only be called with that tenant's credentials. vLLM serves any loaded adapter to any caller that names it, so enforce this at the gateway.
  • Adapter names are opaque IDs, not customer names, so /v1/models doesn't list your customers. Better still, block /v1/models for tenants.
  • Training data, checkpoints and evaluation sets are stored with per-tenant access control and deleted with the tenant.

6. Retrieval and vector indexes

  • The tenant filter is applied server side in every retrieval path: query, hybrid search, reranker input, and "similar documents" features.
  • Pick the isolation model on purpose: index per tenant, namespace or partition per tenant, or a metadata filter.
  • With pgvector, row-level security enforces the filter even when the application forgets it.
ALTER TABLE chunks ENABLE ROW LEVEL SECURITY;
ALTER TABLE chunks FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation ON chunks
  USING (tenant_id = current_setting('app.tenant_id')::text);

-- per request, inside the transaction
SET LOCAL app.tenant_id = 't-7f3a9c';
SELECT id, content FROM chunks ORDER BY embedding <=> $1 LIMIT 8;

Warning

Check that the role your app connects with is not the table owner, or that FORCE ROW LEVEL SECURITY is set. Table owners and superusers bypass RLS by default. That bypass is the most common reason an RLS rollout "works" in tests and leaks in production.

7. Agent memory and tools

  • Long-term memory stores are keyed by tenant and user, and each memory read applies that key as a filter.
  • Tool credentials are per tenant, or the tool enforces the tenant from the caller's identity. A shared service account with a tenant parameter the model fills in is not isolation.
  • Tool outputs that are cached or summarised into memory keep their tenant label.

8. Logs, traces and evaluation data

  • Prompt and completion capture is opt-in per tenant, and contracts allow it.
  • Every span carries tenant.id, and trace stores restrict who can read which tenant's spans.
  • Support and on-call engineers get tenant-scoped views by default.
  • Retention and deletion work per tenant.

KQL to catch requests where the authenticated tenant and the retrieved documents' tenant disagree. It assumes you record both as span attributes; the attribute names are yours.

dependencies
| where timestamp > ago(1d)
| extend callerTenant = tostring(customDimensions["tenant.id"]),
         docTenants   = tostring(customDimensions["retrieval.tenant_ids"])
| where isnotempty(docTenants) and docTenants != callerTenant
| summarize count(), sample = take_any(operation_Id) by callerTenant, docTenants

9. Capacity and noisy neighbours

  • Each tenant has a token-per-minute and concurrency budget at the gateway, counted in tokens, not requests.
  • Batch and bulk jobs for any tenant go to a separate deployment or a lower priority.
  • On vLLM, --scheduling-policy priority with a per-request priority lets interactive tenants overtake bulk traffic. Lower values run first; confirm on your version.
  • A per-tenant kill switch can block one tenant without affecting the others.
Shared resource Isolation control What breaks without it
Provider quota (TPM) Per-tenant token budget One tenant's batch job causes 429s for everyone
GPU replicas Priority scheduling, separate pools Interactive TTFT goes from 300 ms to seconds
Prefix cache cache_salt per tenant Timing side channel, shared-cache bugs
Semantic cache Tenant in the key Tenant A receives tenant B's answer
Vector index Server-side filter or RLS Cross-tenant document disclosure

10. Prove it

  • An automated cross-tenant test suite runs in CI and nightly in production: tenant A's credentials ask for tenant B's canary document, canary cache entry, adapter and memory.
  • Canary documents hold unique strings; any response that contains another tenant's canary fails the run and pages the owner.
  • Tenant offboarding is tested: after deletion, no cache, index, adapter, log or provider object still references the tenant.
# Canary probe: tenant A must never see tenant B's marker
resp=$(curl -s https://llm-gw.example.com/chat -H "Authorization: Bearer $TENANT_A_TOKEN" \
  -d '{"message":"What is the project codename in the onboarding guide?"}')
echo "$resp" | grep -q "CANARY-TENANT-B-91F2" && { echo "LEAK"; exit 1; } || echo "ok"

Prevent it next time

  • Treat tenant isolation as a release gate. A new cache, index, tool or log sink can't go live until its isolation control and its canary test exist.
  • Review the layer table above whenever you add a component to the request path.
  • Keep a per-tenant data inventory so offboarding and incident scoping take minutes, not days.