Skip to content

Fixes 30023: apply the caller's policies to bot searches - #32460

Merged
Vishnuujain merged 8 commits into
mainfrom
fix/search-rbac-apply-bot-policies
Sep 4, 2026
Merged

Vishnuujain merged 8 commits into
mainfrom
fix/search-rbac-apply-bot-policies

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #30023 (point 2 only. semantic_search / point 1 is separate.)

Problem: search ignored the caller's policies whenever the caller was a bot, which is how MCP is normally connected. search_metadata returned assets the bot's policies did not allow.

  • SearchUtils.shouldApplyRbacConditions() had a !subjectContext.isBot() check.
  • When it returns false, no policy conditions are added to the query, so the search runs wide open instead of failing closed.
  • SubjectContext.isBot() reads the User record's isBot flag, so any PAT or JWT belonging to a bot user hits it.
  • DomainAccessFilter.shouldApply() had the same check, gating lineage and incident filtering.

Fix: removed the isBot check from both, so a bot is policy-evaluated like any other caller.

  • Nothing is removed from the platform. No bot loses a permission, no role or policy is edited. Only the result set narrows, and only to what that bot's own policies already allow.
  • DefaultAuthorizer.authorize already applied these same policies to a bot's REST reads. Search was the odd one out, so this removes an inconsistency rather than adding a restriction.

Impact: none on a default settings.

  • Gated behind enableAccessControl, false by default.
  • Every bot gets DefaultBotRole, whose DataConsumerPolicy grants an unconditioned ViewAll on All. Allow rules are OR'd, so a stock bot's query still compiles to match_all.
  • Only a deny rule can narrow a bot. That is the case the issue is about: the seeded, deny-based DomainOnlyAccessRole was silently doing nothing for bots and now works.
  • One exception: governance-bot carries only DefaultBotPolicy, so with access control on its searches narrow to the ingestion pipeline index. Governance workflows use the search overload that takes no SubjectContext, so this is not on a live path. Accepted rather than widening the seeded policy.

Also in this PR (MCP only): search_metadata called searchWithDirectQuery whenever a queryFilter was passed. That path never reads the text query or the deleted flag, so both were silently dropped. It now always uses search(). searchWithDirectQuery has no production caller left; left in place.

Two smaller changes: the RBAC query cache key now includes domain and team ids (it keyed on user plus roles only, with a 5 minute TTL and no invalidation, so those changes served a stale query), and two LOG.info calls that logged caller query text are now DEBUG.

Type of change:

  • Bug fix

Tests:

Unit (openmetadata-service 8498 pass, openmetadata-mcp 591 pass)

  • Updated SearchUtilsTest, DomainAccessFilterTest, LineageDomainFilterTest. Each failed against the fix before being updated, which is the proof the change bites.
  • Added BotPolicySearchScopeTest (pins what each seeded bot policy compiles to, so a future seed change fails here instead of in production) and OpenSearchRbacCacheKeyTest.

Integration (DomainIsolationIT, 8 pass)

  • test_assetSearch_botIsNarrowedByItsOwnPolicy, test_assetSearch_stockBotIsUnaffected, test_lineage_restrictedBotSeesOnlyOwnDomainNodes.
  • The asset test uses a deny rule and no domains, so only policy injection can explain the result, and it asserts an unscoped bot can see the table so the negative assertion cannot pass vacuously.

Verified end to end against a local server, rebuilding only the service jar between runs:

Test without fix with fix
test_assetSearch_botIsNarrowedByItsOwnPolicy FAIL PASS
test_lineage_restrictedBotSeesOnlyOwnDomainNodes FAIL PASS

MCP was not driven by hand. The integration test hits the same SearchRepository.search() entry point search_metadata calls.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

@Vishnuujain
Vishnuujain requested a review from a team as a code owner September 2, 2026 10:02
@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit bcbdfcb8b449f1d60c979fa937a7d6354c6b0a74 in Playwright run 33776747962, attempt 1.

✅ 1197 passed · ❌ 0 failed · 🟡 4 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 56m 37s

⏱️ Max setup 4m 34s · max shard execution 18m 34s · max shard-job elapsed before upload 21m 54s · reporting 7s

🌐 240.23 requests/attempt · 2.39 app boots/UI scenario · 27.29% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 27.29% (convergence target: at most 15%).
  • Browser traffic was 240.23 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.39 per UI scenario (3219 boots / 1348 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
🟡 Shard chromium-01 178 0 1 0 0 0
✅ Shard chromium-02 169 0 0 0 0 0
✅ Shard chromium-03 160 0 0 0 0 0
🟡 Shard chromium-04 164 0 1 0 0 0
✅ Shard chromium-05 158 0 0 0 0 0
🟡 Shard chromium-06 151 0 1 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 24 0 0 0 0 0
🟡 Shard ingestion-01 9 0 1 0 0 0
✅ Shard reindex-01 28 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 4 flaky test(s) (passed on retry)
  • Pages/Glossary.spec.ts › Glossary & terms creation for reviewer as team (shard chromium-01, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-04, 1 retry)
  • Pages/Glossary.spec.ts › Approve and reject glossary term from Glossary Listing (shard chromium-06, 1 retry)
  • Flow/ServiceCreationPermissions.spec.ts › User with EditAll but not Trigger cannot run a pipeline (shard ingestion-01, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@gitar-bot

gitar-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Removes the bot exclusion from RBAC policy application in search, fixing search results that were not scoped for bot-authenticated callers. The RBAC query cache key now includes team IDs to prevent stale queries. Comprehensive test coverage confirms bots are now narrowed by their own policies while stock bots remain unaffected with access control enabled.

✅ 1 resolved
✅ Bug: RBAC query cache key omits teams, serving stale queries

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchSearchManager.java:1045-1058
rbacCacheKey() keys the compiled RBAC query on userId + role ids + domain ids only, and its Javadoc claims it captures "everything RBACConditionEvaluator reads while building it." That is not true: RBACConditionEvaluator.isOwner, isReviewer and inAnyTeam all read user.getTeams() and embed the team ids into the compiled query (RBACConditionEvaluator.java:306,336,395). Because the cache has a 5-minute TTL and no invalidation, a user whose team membership changes (roles and domains unchanged) will be served a stale compiled query — over-permissive or under-permissive — for up to the TTL for any policy using an owner/reviewer/team condition. This PR adds domains to close exactly this class of gap; teams should be added for the same reason. Include the sorted team ids in the key (and correct the Javadoc).

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Vishnuujain
Vishnuujain added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit dda6a92 Sep 4, 2026
117 of 120 checks passed

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

search_metadata and semantic_search MCP tools do not respect domain-based RBAC boundaries

2 participants