Skip to content

Fixes #35086: enforce RBAC on /v1/search/aggregate endpoint - #35148

Merged
mohityadav766 merged 2 commits into
mainfrom
detail/bug-fix/fixes-35086-enforce-rbac-on-v1-search-aggregate-en-d14b0b
Oct 12, 2026
Merged

mohityadav766 merged 2 commits into
mainfrom
detail/bug-fix/fixes-35086-enforce-rbac-on-v1-search-aggregate-en-d14b0b

Conversation

@detail-app

@detail-app detail-app Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #35086

I worked on closing an RBAC bypass in the /v1/search/aggregate endpoint (both GET and POST) because the aggregation query was built from the caller-supplied request with only the org-wide ContextMemory privacy filter applied — the caller's RBAC policy conditions were never evaluated, even though the parallel search-listing path (/v1/search) enforces them for the same caller.

Type of change:

  • Bug fix

High-level design:

Root cause: SearchResource.aggregate / aggregateSearchRequest captured @Context SecurityContext securityContext (auth required) but never called getSubjectContext(securityContext) and never threaded a SubjectContext into searchRepository.aggregate(AggregationRequest). The AggregationManagementClient interface had no aggregate(AggregationRequest, SubjectContext) overload, so the handler had no way to supply a subject even if it wanted to. The class's own applyRbacQuery helper and Javadoc warning about aggregations leaking denied documents already existed — the HTTP endpoint was simply never wired to use them.

Fix: Thread a SubjectContext from SecurityContext through to both search backends, mirroring the listing path (SearchResource.search → searchRepository.search(request, subjectContext)):

  • SearchResource — both aggregate endpoints now resolve SubjectContext via DefaultAuthorizer.getSubjectContext(securityContext) and call searchRepository.aggregate(aggregationRequest, subjectContext).
  • AggregationManagementClient / SearchRepository / ElasticSearchClient / OpenSearchClient — new aggregate(AggregationRequest, SubjectContext) overload (default delegates to the subject-less overload for backward compat).
  • ElasticSearchAggregationManager / OpenSearchAggregationManager — the new overload replaces the unconditional restrictToOrgWideMemories(query) terminator with applySubjectFilters(query, subjectContext), which:
    1. ANDs the caller's RBAC policy via applyRbacQuery (fail-closed with matchNone when policies had to apply but produced no query).
    2. ANDs the per-subject ContextMemory visibility filter (or falls back to the org-wide memory filter for admin/unidentifiable subjects).

When subjectContext is null, admin, or access control is disabled, behavior is unchanged — RBAC is skipped and the org-wide memory filter applies, preserving exact backward compatibility for internal callers that do not thread a SubjectContext.

Both Elasticsearch and OpenSearch backends are fixed with identical security semantics.

Tests:

Use cases covered

  • Non-admin user with enableAccessControl=true and DomainOnlyAccessRole sees aggregation buckets and topHits snippets only for documents in their own domains (GET and POST endpoints).
  • Admin user sees aggregation buckets and topHits over all documents (unfiltered by RBAC).
  • With enableAccessControl=false, a non-admin user sees aggregation buckets over all documents (backward compat — no RBAC filtering).
  • The subject-less aggregate(AggregationRequest) overload produces a query identical to aggregate(AggregationRequest, null) — no regression for internal callers.
  • Both Elasticsearch and OpenSearch backends enforce the same semantics.

Unit tests

  • I added unit tests for the new/changed logic.

  • Files added/updated:

    • openmetadata-service/src/test/java/org/openmetadata/service/search/elasticsearch/ElasticSearchAggregationRbacTest.java (new — 5 tests)
    • openmetadata-service/src/test/java/org/openmetadata/service/search/opensearch/OpenSearchAggregationRbacTest.java (new — 5 tests)
    • openmetadata-service/src/test/java/org/openmetadata/service/search/SearchRepositoryBehaviorTest.java (updated — added subject-aware delegation assertion)

    These verify that the aggregation query sent to the search engine includes the RBAC policy filter (e.g., domains.id terms for the caller's own domains) for non-admin subjects with access control on, and does NOT include it for admin, null, or access-control-off subjects.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.

  • Files added/updated:

    • openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/search/SearchAggregateRbacIT.java (new — 4 tests)

    This IT creates two domains with tables, a non-admin user with DomainOnlyAccessRole assigned to one domain, enables enableAccessControl=true, and asserts via the real HTTP endpoint that:

    • The restricted user's aggregate bucket count is 1 (own domain only) and the foreign table name does NOT appear in topHits snippets.
    • Admin sees bucket count 2 with both domain names in topHits.
    • The POST endpoint enforces the same restrictions as GET.
    • With enableAccessControl=false, the restricted user sees both domains (backward compat).

    Ran locally against both Elasticsearch (-Pmysql-elasticsearch) and OpenSearch (-Ppostgres-opensearch) — all 4 tests pass on both backends.

    Existing regression ITs also pass: SearchResourceIT (77 tests, including testAggregateQuery, testAggregateQueryWithQueryText, testAggregateQueryWithEmptyQueryText) on both backends; DomainIsolationIT (9 tests) on Elasticsearch.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Verified the full end-to-end flow through SearchAggregateRbacIT against live Testcontainers Elasticsearch and OpenSearch instances: created domains, ingested tables, created a restricted user with DomainOnlyAccessRole, toggled enableAccessControl via the /v1/system/settings PUT endpoint, and confirmed the aggregation endpoint and the listing endpoint return consistent document sets for the same caller.

UI screen recording / screenshots:

Not applicable.

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 (unit / integration / Playwright as applicable) and listed them above.

Automatic Fixes PRs can be configured here.

@detail-app
detail-app Bot requested a review from a team as a code owner October 10, 2026 02:16
@detail-app
detail-app Bot requested a review from harshach October 10, 2026 02:16
@github-actions

Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

@detail-app detail-app Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 10, 2026
…, add fail-closed coverage

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mohityadav766
mohityadav766 added this pull request to the merge queue Oct 12, 2026
@sonarqubecloud

Copy link
Copy Markdown

Merged via the queue into main with commit 728937d Oct 12, 2026
75 checks passed
@mohityadav766
mohityadav766 deleted the detail/bug-fix/fixes-35086-enforce-rbac-on-v1-search-aggregate-en-d14b0b branch October 12, 2026 13:52
timothybrush pushed a commit to timothybrush/OpenMetadata that referenced this pull request Oct 16, 2026
…cluster (open-metadata#35477)

The restricted user's client signs its token with the harness key, which a deployed cluster
rejects. Three of the four tests have failed with 401 on every nightly cluster run since open-metadata#35148,
and scale-it, which runs only when search-it passes, was skipped with them. They now skip in
external mode, as the other search ITs that cannot run against a cluster do. Embedded runs are
unchanged.
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.

[Detail Bug] Search: /v1/search/aggregate bypasses RBAC and leaks denied-document metadata (and topHits snippets)

2 participants