MemShield System Architecture
Language models never connect directly to a database — they only generate answers from the text your application places into the prompt. MemShield enforces multi-tenant and multi-agent memory isolation inside PostgreSQL using FORCE ROW LEVEL SECURITY, verified identity tokens, a pre-write semantic Memory Guard, and continuous canary monitoring.
1. Agent Request Flow
Your backend agent (for example, Google ADK Runner) retrieves top-k memories by semantic similarity, builds the prompt for the model, runs tools, and writes new facts back to the vector store. Preventing leaks means enforcing strict authorization on Read (step 3) and Write (step 7b).
2. Shared Vector Store Failure Points (A–E)
Most multi-tenant AI applications store all customers in one shared vector table and trust application code to attach WHERE tenant_id = ? on every query. A single missed filter, spoofed user ID, privileged database role, raw SQL tool, or poisoned write exposes data across tenants.
| Reference | Date | Documented Failure Pattern |
|---|---|---|
| Asana MCP Server | Jun 2025 | Missing tenant boundary check on an AI connector lookup exposed tasks and projects across roughly 1,000 organizations (failure A). |
| Supabase MCP + Cursor | Jul 2025 | An AI agent using a privileged service_role credential bypassed PostgreSQL RLS via prompt injection (failures C & D). |
| AgentPoison (NeurIPS) | Dec 2024 | Under 0.1% poisoned entries written into agent memory achieved at least 80% attack success rate with no model retraining (failure E). |
3. MemShield Enforcement Architecture
MemShield binds verified identity claims (tenant_id, user_id, clearance, compartments) from a signed JWT into each PostgreSQL transaction using set_config(..., is_local => true) under a restricted memshield_app role (NOSUPERUSER, NOBYPASSRLS, non-owner). Before writes land, Memory Guard inspects candidate text with Gemini Flash-Lite under a strictly tighten-only contract.
4. Silent Row Filtering on Reads
On SELECT, PostgreSQL evaluates the RLS policy before distance ranking returns rows. Unauthorized rows are silently excluded — they never cross the wire into the prompt and never return an "access denied" existence oracle. On INSERT and UPDATE, policy violations fail closed with a PostgreSQL error.
5. Silo vs. Pool & Within-Company Isolation
Running a dedicated database per customer (Silo) multiplies compute and operational cost across thousands of tenants. Even when a regulated enterprise runs its own dedicated Silo database, it cannot provision a separate database per employee or specialist sub-agent — clearance levels (1–5) and compartments are still required inside the database.
6. Scope & Security Boundaries
Enforced by MemShield Today
- Cross-tenant and cross-user isolation on
SELECT,INSERT,UPDATE, andDELETEvia PostgreSQLFORCE ROW LEVEL SECURITY. - No read-up, no write-up, no cross-compartment read, and no low-clearance declassification on update.
- Fail-closed pre-write screening (
memshield-guard) blocking prompt injections and downlabeling overshared PII/credentials. - Connection-pool cleanup (
RESET ALL), custom plan pinning (force_custom_plan), and startup refusal on admin/bypass roles.
Outside Memory Store Scope & Roadmap
- Token issuance: Identity verification trusts your IdP's signing keys (Okta, Entra ID, Auth0).
- Adjacent infrastructure: Response caches (e.g., Redis), conversation logs, ADK
SessionService, and direct company-DB tools require their own controls. - Roadmap — Session Write-Down Taint Floor: Automatic high-water-mark tracking so a turn reading a Clearance 4 row enforces
min_clearance >= 4on new writes in that turn. - Roadmap — Tear Lines & In-VPC Gemma: Sanitized low-clearance summaries alongside restricted rows, and air-gapped Gemma 3 screening.