Prompt

I'm building a multi-tenant app and need search that respects row-level permissions

Technology / Search & Discovery Tools2 observationsLast seen Nov 7, 2026

Latest observation

Nov 7, 2026OpenAI APIWeb search: off

For a multi-tenant app, the safest pattern is:

  1. Store tenant and permission scope in the data model
  2. Apply authorization filters at query time
  3. Make search index documents carry the same access metadata
  4. Enforce permissions again on the application side before returning results

Recommended design

1) Data model

At minimum, every row/document should include:

  • tenant_id
  • owner_id or created_by
  • visibility flags or ACL references, such as:
    • public
    • team_ids
    • role_ids
    • explicit user_ids
    • resource-specific grants

Example:

{
  "id": "doc_123",
  "tenant_id": "tenant_a",
  "title": "Quarterly Plan",
  "content": "…",
  "visibility": "restricted",
  "owner_id": "user_42",
  "allowed_user_ids": ["user_42", "user_77"],
  "allowed_role_ids": ["manager"]
}

2) Search architecture

If you’re using an external search engine like Elasticsearch/OpenSearch/Meilisearch/Typesense, index the document plus access metadata. Then query with both:

  • the search terms
  • permission filters for the current user

Example filter logic:

  • tenant_id == current_tenant
  • AND one of:
    • public == true
    • owner_id == current_user
    • allowed_user_ids contains current_user
    • allowed_role_ids intersects user_roles

3) Avoid post-filtering only

Do not search first and then filter results in memory as your only control. That can cause:

  • leaking result counts
  • pagination bugs
  • timing side channels
  • accidental exposure if someone forgets to filter

Use pre-filtering in the search query whenever possible.

4) Database-backed search

If search is in SQL, use row-level predicates directly:

SELECT *
FROM documents
WHERE tenant_id = :tenant_id
  AND (
    visibility = 'public'
    OR owner_id = :user_id
    OR EXISTS (
      SELECT 1
      FROM document_acl acl
      WHERE acl.document_id = documents.id
        AND acl.user_id = :user_id
    )
  )
  AND to_tsvector('english', title || ' ' || content) @@ plainto_tsquery(:q)
ORDER BY created_at DESC
LIMIT 20;

5) Use database RLS if available

If your database supports row-level security (for example PostgreSQL), it’s a strong choice for defense in depth.

  • Enable RLS on tenant-owned tables
  • Set session variables for current user/tenant
  • Let the database enforce access automatically

This helps prevent accidental bypass through ad hoc queries.

6) Multi-tenant isolation

For stronger isolation, consider one of these approaches:

  • Shared table + tenant_id filter: simplest, most common
  • Schema per tenant: more isolation, more operational overhead
  • Database per tenant: strongest isolation, highest overhead

Most apps start with shared tables and strict RLS.

7) Search index security

If using external search, remember the index is a copy of data. Treat it as sensitive:

  • never index fields you wouldn’t want exposed
  • secure the search service itself
  • rotate credentials
  • restrict direct client access if permission logic is server-side
  • if clients query search directly, use scoped tokens or signed filters

Practical pattern

A solid implementation usually looks like:

  • API authenticates user
  • API loads tenant context and user permissions
  • API builds a search query with mandatory ACL filters
  • Search engine returns only permitted hits
  • API re-validates authorization before responding
  • Logs and metrics avoid exposing sensitive result content

If you want the simplest robust answer

Use:

  • tenant_id on every row
  • PostgreSQL RLS for base authorization
  • a search index that stores tenant_id and ACL metadata
  • server-side query building that always adds permission filters

If you want, I can give you:

  1. a PostgreSQL RLS example,
  2. an Elasticsearch/OpenSearch permission-filtering example, or
  3. a full schema design for document-level ACLs.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.