Repository navigation
fix(search): enforce ContextMemory shareConfig visibility in search - #29384
Conversation
Private/Shared context memories were filtered only on the REST /v1/contextCenter/memories read endpoints, so global search and search-backed listings returned other users' memory content. Add ContextMemorySearchVisibility (mirroring ContextMemoryVisibility) and AND it into the Elasticsearch and OpenSearch query paths for every non-admin subject, independent of the RBAC access-control toggle. Covered by ContextMemorySearchVisibilityTest (8 ES+OS unit tests). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
🔴 Playwright Results — 2 failure(s), 16 flaky✅ 4378 passed · ❌ 2 failed · 🟡 16 flaky · ⏭️ 88 skipped
Genuine Failures (failed on all attempts)❌
|
Address PR review (greptile P1): the sharedWithIds clause matched regardless of the stored visibility, so a Private memory carrying a stale sharedWithIds (e.g. flipped Shared->Private without clearing the list) would leak to those principals via search, while the REST guard ContextMemoryVisibility.isInSharedWithList consults sharedWith only when visibility==SHARED. AND the sharedWithIds match with visibility=Shared and add a regression test asserting sharedWithIds is never a bare (ungated) should clause. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
|
Code Review 🚫 Blocked 0 resolved / 1 findingsIntroduces 🚨 Security: NLQ main success path bypasses ContextMemory visibility filter📄 openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java:588-602 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:576-590 The whole point of this PR is to AND the Elasticsearch ( OpenSearch ( Impact: a non-admin user issuing an NLQ search ( Fix: call ES: apply the visibility filter on the NLQ success path before executing. Mirror the same addition in OpenSearchSearchManager.searchWithNLQ after requestBuilder.query(nlqQuery).🤖 Prompt for agentsOptionsDisplay: compact → Showing less information. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
…pagination Review (lautel): filtering the search-backed contextMemory list in Java and falling back to new ResultList<>(visible) whenever an item was dropped loses the engine's paging metadata (total, cursors) and truncates the page below the requested limit, so a client paging by offset silently stops short of the real result set. The post-filter was also redundant: ContextMemory shareConfig visibility is already enforced at query time by ContextMemorySearchVisibility (#29384), applied in both search managers on the listWithOffset path the search-backed listing uses. So the search already excludes memories the caller may not see. Remove the post-filter and return the search result as-is, restoring correct offset pagination while keeping the visibility guarantee. Verified: ContextMemoryIT 189/189. Co-Authored-By: Claude Fable 5 <[email protected]>
…query (#29541) * fix(search): enforce ContextMemory visibility at index time, not per-query Private/Shared ContextMemory could leak through search paths the per-query applyContextMemoryVisibility filter (#29384) did not cover. Instead of filtering on every search path, only org-wide (ENTITY) memories are written to the index: ContextMemoryRepository.isSearchIndexable gates the live create/update/embedding paths and getReindexFilter applies the same rule to the bulk reindex reader and counts (so partition totals stay balanced and the staged index promotes). Removes the applyContextMemoryVisibility apparatus from both search managers. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): gate bulk live-index paths on isSearchIndexable too createEntitiesIndex and updateEntitiesIndex (the bulk live paths reached via SearchIndexHandler.onEntitiesCreated/onEntitiesUpdated) bypassed the isSearchIndexable gate, so a PRIVATE/SHARED ContextMemory created or updated through a bulk lifecycle dispatch (import/batch extraction) could still be indexed. Apply the same gate: skip non-indexable entities on bulk create; on bulk update drop them and delete their stale docs, mirroring updateEntityIndex's ENTITY->PRIVATE flip handling. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): make isSearchIndexable safe for repository-less types checkIfIndexingIsSupported gates on the index mapping, not repository existence, so an indexable but repository-less type (e.g. an index-only/time-series sub-entity) reaching createEntityIndex/updateEntityIndex would throw EntityNotFoundException at the getEntityRepository().isSearchIndexable call added in the prior commits. Route all live index-path gates through a new Entity.isSearchIndexable facade that defaults to indexable when no repository is registered, so the rule still lives in ContextMemoryRepository but repository-less types index exactly as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(search): document reindex-only scope of MEMORY_SEARCH_VISIBILITY_PARAM Warn that the filter param is set only by ContextMemoryRepository.getReindexFilter and must not be applied to the REST /contextCenter/memories listing (owners must still read their own PRIVATE/SHARED memories there). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): clean up hidden memory vector chunks * fix(search): handle time-series indexability * fix(search): derive memory visibility bind parameter * fix(ci): address reindex and Playwright failures * test(search): use context memory table name * test(search): stabilize term boost previews * test(incidents): isolate pagination fixtures * fix(search): harden indexability handling * fix(search): preserve visibility defense in depth * fix(search): purge stale non-indexable documents * fix(search): align distributed cursor filters --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Mohit Yadav <[email protected]>
…query (#29541) * fix(search): enforce ContextMemory visibility at index time, not per-query Private/Shared ContextMemory could leak through search paths the per-query applyContextMemoryVisibility filter (#29384) did not cover. Instead of filtering on every search path, only org-wide (ENTITY) memories are written to the index: ContextMemoryRepository.isSearchIndexable gates the live create/update/embedding paths and getReindexFilter applies the same rule to the bulk reindex reader and counts (so partition totals stay balanced and the staged index promotes). Removes the applyContextMemoryVisibility apparatus from both search managers. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): gate bulk live-index paths on isSearchIndexable too createEntitiesIndex and updateEntitiesIndex (the bulk live paths reached via SearchIndexHandler.onEntitiesCreated/onEntitiesUpdated) bypassed the isSearchIndexable gate, so a PRIVATE/SHARED ContextMemory created or updated through a bulk lifecycle dispatch (import/batch extraction) could still be indexed. Apply the same gate: skip non-indexable entities on bulk create; on bulk update drop them and delete their stale docs, mirroring updateEntityIndex's ENTITY->PRIVATE flip handling. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): make isSearchIndexable safe for repository-less types checkIfIndexingIsSupported gates on the index mapping, not repository existence, so an indexable but repository-less type (e.g. an index-only/time-series sub-entity) reaching createEntityIndex/updateEntityIndex would throw EntityNotFoundException at the getEntityRepository().isSearchIndexable call added in the prior commits. Route all live index-path gates through a new Entity.isSearchIndexable facade that defaults to indexable when no repository is registered, so the rule still lives in ContextMemoryRepository but repository-less types index exactly as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(search): document reindex-only scope of MEMORY_SEARCH_VISIBILITY_PARAM Warn that the filter param is set only by ContextMemoryRepository.getReindexFilter and must not be applied to the REST /contextCenter/memories listing (owners must still read their own PRIVATE/SHARED memories there). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(search): clean up hidden memory vector chunks * fix(search): handle time-series indexability * fix(search): derive memory visibility bind parameter * fix(ci): address reindex and Playwright failures * test(search): use context memory table name * test(search): stabilize term boost previews * test(incidents): isolate pagination fixtures * fix(search): harden indexability handling * fix(search): preserve visibility defense in depth * fix(search): purge stale non-indexable documents * fix(search): align distributed cursor filters --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Mohit Yadav <[email protected]>



Describe your changes:
ContextMemoryenforces its per-memoryshareConfigvisibility (Private = owner-only, Entity = everyone, Shared = listed principals; admins bypass) only on the REST/v1/contextCenter/memoriesread endpoints. Global search (/search/queryon theallalias) and the search-backed listing/NLQ paths applied only domain + RBAC filters, neither of which understandsshareConfig, so any user could see other users' Private/Shared memorytitle/question/answerin search results. This PR addsContextMemorySearchVisibility— an engine-agnostic search filter that mirrorsContextMemoryVisibility— and ANDs it into the Elasticsearch and OpenSearch query paths for every non-admin subject, deliberately independent of the RBAC access-control toggle so disabling RBAC can never expose private memories. The filter isentityType-guarded so non-memory documents are untouched, and the index still stores every memory so owners can always find their own.Fixes 29490
Type of change:
High-level design:
ContextMemorySearchVisibilitybuilds a per-subjectOMQueryBuilderusing the sameQueryBuilderFactoryabstractionRBACConditionEvaluatoruses, so one builder serves both engines:should[ NOT(entityType=contextMemory) , (entityType=contextMemory AND should[ visibility=Entity, nested owners.id=me, sharedWithIds ∋ {me + teams + domains} ]) ]. It is applied wherever RBAC is applied —ElasticSearchSearchManager(folded intoapplyRbacCondition, plus the inline direct-query and NLQ-fallback paths) andOpenSearchSearchManager(the inlinelistWithOffsetpath plus after eachapplyRbacQueryWithCachingcall) — gated only on!isAdmin. Correctness rests on each OR-group being a should-only bool (engine defaultminimum_should_match=1, the same defaultRBACConditionEvaluatoralready relies on); a unit test pins that invariant so a straymust/filtercan't silently turn the filter into a fail-open no-op. No DB migration or schema change (visibility data was already indexed); reindex already coverscontextMemory. The AI/RAG vector-retrieval path (VectorSearchResource→OpenSearchVectorService) is a deliberate follow-up — it ignores the subject today and needs subject plumbing plus an acting-principal decision.Tests:
Use cases covered
Unit tests
ContextMemorySearchVisibilityTest(8 tests, Elasticsearch + OpenSearch):entityTypeguard, the three visibility clauses,sharedWithIds= {user, teams, domains}, admin/null → no filter, and the should-onlyminimum_should_match=1invariant.Backend integration tests
Ingestion integration tests
Playwright (UI) tests
Manual testing performed
mvn -pl openmetadata-service test -Dtest=ContextMemorySearchVisibilityTest→ 8/8 green;mvn spotless:applyclean.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.Greptile Summary
This PR introduces
ContextMemorySearchVisibility, a new engine-agnostic filter that ANDs per-memoryshareConfigvisibility (Private = owner-only, Entity = everyone, Shared = listed principals with avisibility=Sharedguard to prevent stale-list leaks) into search query paths for non-admin subjects, independent of the RBAC toggle.sharedWithIdsbranch is properly gated byvisibility=Shared(addressing a prior review concern).searchWithNLQsuccess path in both engines (when the NLQ service returns a transformed query) executesclient.searchwithout applying either RBAC or the new visibility filter — private ContextMemory documents remain reachable via NLQ search, which is the scenario this PR specifically targets.Confidence Score: 3/5
Not safe to merge as-is — the NLQ success path in both engines executes without the visibility filter, which is the primary attack vector this PR aims to close.
The filter implementation and wiring are correct for listing, direct-query, and fallback paths, but both ElasticSearchSearchManager.searchWithNLQ and OpenSearchSearchManager.searchWithNLQ execute the engine query directly when the NLQ service returns a transformed query, skipping both RBAC and the new visibility filter. A non-admin user with NLQ access can retrieve private ContextMemory documents owned by others — the exact exposure the PR describes fixing.
ElasticSearchSearchManager.java and OpenSearchSearchManager.java — specifically the searchWithNLQ success branch in each file (the block between requestBuilder.query(nlqQuery) and client.search).
Security Review
ElasticSearchSearchManager.searchWithNLQandOpenSearchSearchManager.searchWithNLQboth skipapplyContextMemoryVisibility(and RBAC) when the NLQ service successfully transforms a query. A non-admin user can retrieve private ContextMemory documents owned by other users via the NLQ search endpoint whenever the NLQ service is configured and returns results.Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Search Request] --> B{Search Path} B --> C[listWithOffset] B --> D[searchWithDirectQuery] B --> E[searchWithNLQ] B --> F[main search / buildSearchRequestBuilder] C --> C1[applyRbacCondition] --> C2[applyContextMemoryVisibility ✅] --> C3[Execute] D --> D1[inline RBAC] --> D2[applyContextMemoryVisibility ✅] --> D3[Execute] E --> E1{NLQ transform} E1 -->|success| E2[Execute query - NO RBAC - NO visibility filter ❌] E1 -->|failure/null| E3[fallbackToBasicSearch] E3 --> E4[inline RBAC] --> E5[applyContextMemoryVisibility ✅] --> E6[Execute] F --> F1[applyRbacQueryWithCaching] --> F2[applyContextMemoryVisibility ✅] --> F3[Execute] style E2 fill:#ff6b6b,color:#fff style C2 fill:#51cf66,color:#fff style D2 fill:#51cf66,color:#fff style E5 fill:#51cf66,color:#fff style F2 fill:#51cf66,color:#fff%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[Search Request] --> B{Search Path} B --> C[listWithOffset] B --> D[searchWithDirectQuery] B --> E[searchWithNLQ] B --> F[main search / buildSearchRequestBuilder] C --> C1[applyRbacCondition] --> C2[applyContextMemoryVisibility ✅] --> C3[Execute] D --> D1[inline RBAC] --> D2[applyContextMemoryVisibility ✅] --> D3[Execute] E --> E1{NLQ transform} E1 -->|success| E2[Execute query - NO RBAC - NO visibility filter ❌] E1 -->|failure/null| E3[fallbackToBasicSearch] E3 --> E4[inline RBAC] --> E5[applyContextMemoryVisibility ✅] --> E6[Execute] F --> F1[applyRbacQueryWithCaching] --> F2[applyContextMemoryVisibility ✅] --> F3[Execute] style E2 fill:#ff6b6b,color:#fff style C2 fill:#51cf66,color:#fff style D2 fill:#51cf66,color:#fff style E5 fill:#51cf66,color:#fff style F2 fill:#51cf66,color:#fffComments Outside Diff (2)
openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchSearchManager.java, line 573-623 (link)When the NLQ service is configured and
transformNaturalLanguageQueryreturns a non-null result, the query is executed directly (lines 595–612) without going through either RBAC orapplyContextMemoryVisibility. Only thefallbackToBasicSearchpath has the filter applied. A non-admin user can issue an NLQ query, receive a transformed ES query, and get back private ContextMemory documents belonging to other users — the exact leak this PR is meant to close. The fix is to callapplyContextMemoryVisibility(subjectContext, requestBuilder)(and RBAC, which is also absent here) beforeclient.search(...)in the success branch. The same gap exists in the OpenSearchsearchWithNLQsuccess path for the same reason.openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java, line 558-602 (link)Same gap as the Elasticsearch counterpart: when
nlqService.transformNaturalLanguageQueryreturns a non-null result, the code sets the query, adds aggregations, and callsclient.searchwithout callingapplyRbacQueryWithCachingorapplyContextMemoryVisibility. Only thefallbackToBasicSearchpaths carry the filter.applyRbacQueryWithCaching(subjectContext, requestBuilder)andapplyContextMemoryVisibility(subjectContext, requestBuilder)should both be called afterrequestBuilder.query(nlqQuery)and beforeclient.search(...).Reviews (2): Last reviewed commit: "fix(search): gate ContextMemory sharedWi..." | Re-trigger Greptile