A Practical Pattern to Implement Secure Enterprise AI Search
From the publisher’s feed, collected in the ZeroLabs newsroom.
Normalize every source into one index, and enforce access control inside the query, not in the application that reads its results.The problemEnterprises rarely keep knowledge in one place. The information an employee needs is spread across a wiki, an ITSM knowledge base, a digital asset library, an FAQ corpus, a people directory, and several more systems, each with its own API, its own schema, and its own permission model. When an organization sets out to put a single search box or an AI assistant in front of all of it, two requirements collide. Retrieval has to span every source uniformly so a query returns the best answer regardless of where it lives. At the same time, retrieval has to respect the access boundaries each source already enforces, so an employee never sees a document they were not entitled to see in the originating system.Most early implementations get the first requirement right and the second one wrong. They index everything into one store for recall, then filter the results in application code after the search returns. That ordering is the defect. Filtering after retrieval means the search engine has already ranked, counted, and paginated over documents the user is not allowed to see. Result counts and facet aggregations leak the existence of restricted content. Top-k truncation silently drops authorized results because unauthorized ones consumed the slots. The authorization logic ends up reimplemented in the worst possible layer, far from the data, and drifts out of sync with the source systems it is supposed to mirror.The claimEnterprises building retrieval over many heterogeneous internal sources should normalize every source through a uniform connector contract into a single Azure AI Search index, where each document carries a principal or group ACL field populated at ingest, and enforce access control at query time by injecting the caller’s identity into the index query as a security filter. Filtering belongs inside the query sent to the search service, not in the application that consumes the results. And the index itself should be a managed search service rather than a hand-assembled retrieval stack, because security trimming, hybrid retrieval, and multi-source ingestion are the parts most expensive to build correctly and most damaging to get wrong.Authorization that runs after retrieval is not authorization. It is a redaction step layered over a search that already saw everything.The pattern: Security-Trimmed Index (STI)Sources are normalized into one index at ingest with an ACL field per document. At query time the caller’s group claims become a security filter, so the index returns only documents the user is entitled to.Source: Image by the author.The pattern has two halves that meet at the index. The ingest half consolidates heterogeneous sources into one searchable index. A per-source connector reads from its system, maps that system’s records into a single shared document schema, and writes each document’s authorized principals into a dedicated ACL field on the index. The connector is the only component that understands a given source. Everything downstream sees uniform documents, which is what makes adding a new source a connector change rather than a query change.The query half spends the identity that the ingest half recorded. When a request arrives, the application resolves the caller’s group and principal claims from their authenticated identity, then issues the search with those claims expressed as a filter over the ACL field. The search service evaluates that filter as part of retrieval, so ranking, counting, faceting, and paging all operate over the authorized subset only. Nothing the user cannot access ever enters the candidate set. The application receives a result list it can render verbatim, because trimming already happened at the boundary where the data lives.This is where STI connects to a pattern earlier in this series. The Delegated Boundary OAuth (DBO) pattern [4] argues that the calling user’s identity must survive every hop through an agent or gateway stack rather than terminating at a service account. STI is what that propagated identity is for at the retrieval layer. DBO carries the user’s identity to the point of retrieval; STI consumes it as the security-filter key. The two patterns describe one continuous chain: propagate the identity, then spend it where the data is read.ImplementationThree pieces make the pattern concrete: an index schema with an ACL field, an ingest step that populates it, and a query that filters on it. The examples below use Azure AI Search [1]; the shapes translate to any search service that supports filterable collection fields.Define the ACL as a filterable collection on the index. Each document also carries the normalized fields every source maps into, plus a vector field for semantic retrieval.{ "name": "enterprise-content", "fields": [ { "name": "id", "type": "Edm.String", "key": true }, { "name": "title", "type": "Edm.String", "searchable": true }, { "name": "content", "type": "Edm.String", "searchable": true }, { "name": "sourceType", "type": "Edm.String", "filterable": true, "facetable": true }, { "name": "allowedGroupIds", "type": "Collection(Edm.String)", "filterable": true }, { "name": "contentVector", "type": "Collection(Edm.Single)", "dimensions": 1536, "vectorSearchProfile": "default" } ]}A single indexed document then looks like the following. This one came from a wiki connector; the same shape holds for every source because the connector normalized it. The allowedGroupIds values are the two groups that could read the original wiki page, copied from the wiki's own permission model at ingest. The content vector is elided for length.{ "id": "wiki-4821", "title": "Rotating a production API key", "content": "To rotate a production API key, open the secrets console, issue a new key, update the dependent services, then revoke the old key after traffic has drained.", "sourceType": "wiki", "allowedGroupIds": ["grp-engineering", "grp-platform-secops"], "contentVector": [0.0123, -0.0456, 0.0789]}At ingest, the connector resolves the document’s authorized principals in the source system and writes them into allowedGroupIds. The authorization data is captured once, at the moment the document is indexed, from the system that is authoritative for it.def to_index_document(source_record, acl_resolver): return { "id": source_record.id, "title": source_record.title, "content": source_record.body, "sourceType": source_record.connector_name, # ACL captured at ingest from the authoritative source system "allowedGroupIds": acl_resolver.group_ids_for(source_record), "contentVector": embed(source_record.body), }At query time, the application resolves the caller’s group memberships from their authenticated identity and injects them as a filter. The same request asks for hybrid retrieval and semantic ranking [2], so keyword and vector matches are fused and reranked, all within the authorized subset.def search(query_text, caller_group_ids, search_client): groups = ",".join(caller_group_ids) return search_client.search( search_text=query_text, # security trimming evaluated as part of retrieval, not after it filter=f"allowedGroupIds/any(g: search.in(g, '{groups}', ','))", vector_queries=[VectorizableTextQuery(text=query_text, fields="contentVector")], query_type="semantic", semantic_configuration_name="default", top=10, )Concretely, that call resolves to a single request against the search service. Suppose the caller is a member of grp-engineering and grp-design, and asks a natural-language question.POST https://{service}.search.windows.net/indexes/enterprise-content/docs/search?api-version=2024-07-01Content-Type: application/jsonapi-key: {query-key}{ "search": "how do I rotate a production API key", "filter": "allowedGroupIds/any(g: search.in(g, 'grp-engineering,grp-design', ','))", "queryType": "semantic", "semanticConfiguration": "default", "vectorQueries": [ { "kind": "text", "text": "how do I rotate a production API key", "fields": "contentVector" } ], "top": 10}The wiki-4821 document above is returned, because its allowedGroupIds includes grp-engineering, which the caller holds. A document restricted to grp-platform-secops alone would not appear in the response at all, even if it were the single best semantic match for the question. The user query and the security boundary are evaluated together, in one pass, inside the engine.The filter is the load-bearing line. Because it is part of the query, every downstream property of the result set, including the count and the facets, is computed over authorized documents only. There is no second pass, and there is no window in which the application holds rows the user may not see.This is also where the build-versus-buy decision earns its place in the design. The reason to adopt a managed search service rather than assemble a retrieval stack from a raw vector database is that the hardest and most security-sensitive parts come built in.Source: Image by the author.The columns that matter most for an enterprise are the middle two. Security trimming and retrieval quality are precisely the areas where a hand-built stack accumulates the most subtle, highest-consequence bugs. Buying them removes the two risks that a search platform is least forgiving about.When this pattern fits / when it doesn’tFits when:Content spans multiple systems with different permission models and you need one retrieval surface across all of them.Source systems can express their authorization as group or principal identifiers that you can capture at ingest.Recall and ranking quality matter enough that hybrid and semantic retrieval are worth adopting.Doesn’t fit when:All content lives in one system that already exposes good security-trimmed search. Indexing a copy adds an ACL-synchronization problem you did not have.Authorization depends on attributes that change faster than you can reindex, such as per-request contextual rules. Static-at-ingest ACLs will lag.The corpus is tiny and uniformly accessible, where the cost of the pattern exceeds its benefit.Operational considerations:ACLs change after a document is indexed. You need a reindex or update path triggered by permission changes in the source, not only by content changes.A user’s group membership must be resolved at query time from a trustworthy identity, and that lookup sits on the latency path. Cache it carefully.Filter cardinality matters. Users in very large numbers of groups produce large filter expressions; plan for the ceiling.Where this pattern is incompleteSTI secures which documents a user can retrieve. It does not secure what a document contains below the document grain. If a single indexed document mixes content with different sensitivity levels, a per-document ACL is too coarse, and the pattern offers no field-level or passage-level trimming on its own. Organizations with mixed-sensitivity documents must split them at ingest or add field-level security, which the search service supports but the base pattern does not mandate.The pattern also assumes the ACL captured at ingest stays faithful to the source. It does not. Permissions in the originating system drift the moment they change, and the index reflects the world as of the last reindex. Adopters should treat ACL freshness as a first-class reliability concern with its own monitoring, not as a property they get for free. A stale ACL that grants too much is a security incident, not a search-quality issue.Finally, STI says nothing about how the caller’s identity arrives at the query layer. It assumes a trustworthy set of group claims is available to inject. Producing that identity safely across an agent or gateway stack is a separate concern, addressed by Delegated Boundary OAuth. STI is only as sound as the identity it is handed.Adoption checklistDefine one normalized document schema and route every source through a connector that maps into it.Add a filterable ACL field to the index and populate it at ingest from each source’s authoritative permission model.Inject the caller’s resolved group claims as a security filter on every query; never filter results after retrieval.Build a reindex path triggered by permission changes, not only content changes, and monitor ACL freshness.Adopt the managed service’s hybrid and semantic retrieval rather than reassembling those capabilities, and reserve custom engineering for what the platform does not provide.A later post in this series will take up the next question this one leaves open: once retrieval is both consolidated and access-trimmed, how do you measure whether it is actually returning the right documents? Security trimming guarantees a user sees nothing they should not. It says nothing about whether they see everything they should. That is a retrieval-quality problem, and it deserves its own treatment [5].References[1] Microsoft, Security filters for trimming results in Azure AI Search. Microsoft Learn.[2] Microsoft, Hybrid search and semantic ranking in Azure AI Search. Microsoft Learn.[3] Microsoft, Indexers and connectors in Azure AI Search. Microsoft Learn.[4] N. Selvaraj, The Delegated Boundary OAuth Pattern: Identity Propagation Across MCP Gateways for Enterprise. Medium.[5] N. Selvaraj, Unified RAG Evaluation Schema: Cross-Supplier Quality Measurement for Amazon Bedrock and Agentic Systems. Medium.A Practical Pattern to Implement Secure Enterprise AI SearchReferences[1] Microsoft, Security filters for trimming results in Azure AI Search. Microsoft Learn.[2] Microsoft, Hybrid search and semantic ranking in Azure AI Search. Microsoft Learn.[3] Microsoft, Indexers and connectors in Azure AI Search. Microsoft Learn.[4] N. Selvaraj, The Delegated Boundary OAuth Pattern: Identity Propagation Across MCP Gateways for Enterprise. Medium.[5] N. Selvaraj, Unified RAG Evaluation Schema: Cross-Supplier Quality Measurement for Amazon Bedrock and Agentic Systems. Medium.A Practical Pattern to Implement Secure Enterprise AI Search was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.