Skip to content

Fixes 33420: authorize the target domain when an asset is reassigned - #33471

Merged
manerow merged 17 commits into
mainfrom
fix/33420-asset-reassignment-authz
Oct 16, 2026
Merged

manerow merged 17 commits into
mainfrom
fix/33420-asset-reassignment-authz

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #33420

Domain reassignment was authorized only against the domain an asset was already in, never the one it was moving into. The two write paths each checked half the move:

Path Checked Ignored
PATCH /v1/<entity>/{id} on /domains EditAll on the asset, against its old domain the target domain
PUT /v1/domains/{name}/assets/add EditAll on the target domain the assets being pulled in

So a user scoped with hasDomain() could move assets into domains they do not hold, and anyone able to edit their own domain could pull any asset in the catalog into it via the domain asset picker.

The originating report's policy was also misconfigured — Resources: Domain scopes a rule to Domain entities, not to domain assignment on other assets. That is a separate config fix on their side. It is not what this PR addresses: the integration test here uses a correctly scoped policy (Resources: All, EditAll, hasDomain()) and still reproduces the bug without this change.

Type of change:

  • Bug fix

High-level design:

  • New EditDomains operation. There was no operation for domains, so a /domains patch fell through to EditAll — reassignment could not be granted or denied without granting EditAll wholesale. Additive and migration-free: CompiledRule.matchesBySubsumption already grants anything matching startsWith("Edit") under an existing EditAll.
  • Authorize the post-state. After the existing pre-state check, a second decision runs against UpdatedDomainsResourceContext (new), which delegates entity/owners/tags to the stored resource and overrides only getDomains(). That is what keeps the change invisible to policies with no domain conditions — both passes evaluate the same rules and differ only on domains. Gated on the domain set actually changing, and the patch is inspected before the entity is resolved, so an unrelated patch costs nothing.
  • Derive the post-state with JsonUtils.applyPatch — the same helper the repository uses, so authorization sees exactly the post-state that will be persisted rather than a second, drifting reading of the patch. Load-bearing: that helper skips read-only auto-generated fields (href, changeDescription) and converts replace→add for absent paths. Applying the client's diff strictly instead fails, because the UI diffs its own copy of the entity and emits remove /domains/0/href against a field that is never stored.
  • Authorize the assets on the bulk endpoints. Per-asset authorizer.authorize rather than the existing authorizeBulkAssetsPermission, which is a resource-type check matching Access.ALLOW — a conditional rule resolves to CONDITIONAL_ALLOW there, so it would have denied a hasDomain()-scoped admin every asset, including ones they may legitimately edit.
  • Removed PolicyEvaluator.hasDomainPermission — zero callers since its call site was deleted in e77d1940cb (Domain policy must be evaluated during PolicyEvaluator #23302).

Still open, deliberately out of scope: the CSV import path (EntityRepository.updateDomainsForImport) has no target-domain check.

Tests:

Use cases covered

A user scoped to Domain A by a hasDomain() policy cannot move a domainless asset into Domain B, cannot move an asset from A into B, and cannot claim an asset sitting in B via A's asset picker — while still being able to move assets into a sub-domain of A and to claim assets they may edit. An entity owner with no domain policy in play can still set a domain.

Unit tests

  • Added
  • openmetadata-service/.../policyevaluator/UpdatedDomainsResourceContextTest.java (new, 3 tests)
  • openmetadata-service/.../util/JsonPatchUtilsTest.java (+5 tests, plus /domains → EditDomains in the mapping table) — including the verbatim 7-operation patch the UI sends on a domain reassignment
  • openmetadata-service/.../exception/CatalogExceptionMessageTest.java (+2 tests) — the denial must name the domain
  • 91/91 pass across the touched policy-evaluator, util and exception suites

Line coverage on changed classes (mvn test jacoco:report -Pstatic-code-analysis): UpdatedDomainsResourceContext 100%, JsonPatchUtils 83.1%, ResourceRegistry 34.8%. EntityResource / DomainResource / DataProductResource show 0% here — they have no unit tests in this module; their changed paths are covered by the integration test below, which lives in a different module and so does not contribute to this report.

Backend integration tests

  • Added — openmetadata-integration-tests/.../it/tests/DomainReassignmentAuthorizationIT.java (new, 6 tests), all passing.

Verified not to be vacuous — with the enforcement removed, exactly the three security tests fail and the three non-regression tests still pass:

RED  (enforcement removed): Tests run: 6, Failures: 3
  test_patchCannotMoveADomainlessAssetIntoAnUnheldDomain
  test_patchCannotMoveAnAssetOutOfAHeldDomainIntoAnUnheldOne
  test_bulkAddAssetsCannotPullAnAssetOutOfAnUnheldDomain
    ==> Expected ForbiddenException to be thrown, but nothing was thrown

GREEN (this PR):            Tests run: 6, Failures: 0

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable — no UI behaviour change. The UI diff is five regenerated type files plus one entry in the Admin Permission Debugger's operation list.

Manual testing performed

Built and ran the full stack locally (./docker/run_local_docker.sh -m ui -d mysql -i false) and drove the scenario by hand through the UI and the REST API: domains Finance and Marketing, a hasDomain() policy on Resources: All, a BUAdmin role and FinanceTeam scoped to Finance, user bu.admin, and a table starting with no domain.

Move (as bu.admin, scoped to Finance) Result
no domain → Marketing (not held) 403 — the reported bug
no domain → Finance (held) 200 — legitimate action preserved
Finance → Marketing (not held) 403
Principal: CatalogPrincipal{name='bu.admin'} does not belong to domains [Marketing]
to perform the [EditDomains] operations.

This found two defects the test suite missed, both fixed in the follow-up commit and now covered by tests:

  1. Every domain change from the UI returned 400 — for all users, not just restricted ones. The first version derived the post-patch domains with the raw JSON Patch applier; the UI's diff opens with remove /domains/0/href against a field the server never stores, and RFC-6902 remove on a missing path throws. The integration test missed it because it hand-builds a clean add /domains patch that no real client sends.
  2. The denial rendered domains [null] — the references come from the patch and carry no name, defeating the purpose of the domain-specific message.

Also run locally: mvn spotless:check clean on openmetadata-spec, openmetadata-service and openmetadata-integration-tests.

UI screen recording / screenshots:

1-denied-cross-domain-move

No code change to the UI beyond five regenerated type files and one entry in the Admin Permission Debugger's operation list, so there is no interaction or layout change to record.

Verified by hand in the UI: BU Admin scoped to Finance attempts to move a table into Marketing; the toast names the domain and the operation, and the Domains chip still reads Finance (the move was blocked, not applied). The exact toast text is quoted under Manual testing performed above. Screenshot to follow as an attachment.

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 #33420 above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: no migration needed — EditDomains is additive and existing EditAll grants already subsume it.
  • For UI changes: no interaction or layout change to record; the UI-side denial is verified and quoted above, screenshot to follow.
  • I have added tests (unit / integration) and listed them above.
  • I have added a test that covers the exact scenario we are fixing (DomainReassignmentAuthorizationIT, verified to fail without the fix).

🤖 Generated with Claude Code


Summary by Gitar

  • UI permission gating:
    • Domain edit controls now check canEditDomains (EditDomains, falling back to EditAll) in header, team, classification, and test suite components
  • Data product bulk endpoints:
    • Bulk add and remove now authorize each asset individually against EDIT_ALL
  • PUT reassignment:
    • PUT create-or-update authorizes the target domains, resolved by id before the check

This will update automatically on new commits.

RetriggerView in GreptileConfidence Score: 1/5

The PR should not merge until the two previously reported ways to bypass target-domain checks are fixed.

Findings

  1. P1 Security Inherited target domain goes unchecked ▶
  2. P1 Security Whole-document patches bypass domain checks ▶

Summary

The PR adds EditDomains and checks target domains during PATCH and PUT updates.

  • Domain moves now require permission for the destination domain.
  • Domain edit controls now follow the EditDomains permission.
  • Generated maps and schema snapshots change without changing user behavior.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[PATCH or PUT update] --> B[Check permission on stored asset]
  B --> C{Domains change?}
  C -->|No| F[Save update]
  C -->|Yes| D[Resolve supplied target domains]
  D --> E[Check EditDomains with target domains]
  E -->|Allowed| F
  E -->|Denied| G[Reject update]
Loading

Reviews (6) · Last reviewed commit: "Update generated TypeScript types and de..." · Reviewed by Greptile

Domain reassignment was authorized only against the domain an asset was
already in. The PATCH path evaluated the stored entity, so hasDomain() saw
the source domain — and nothing at all for a domainless asset, where it
deliberately returns true. The domain bulk-asset endpoints authorized the
target domain but never the assets, so a domain's asset picker could pull
assets out of domains the caller had no rights over.

Add an EditDomains operation so domain reassignment can be granted without
granting EditAll, re-run the policy decision against the domains an update
moves an asset into, and authorize each asset on the domain and data product
bulk endpoints.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 17, 2026
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 78%
78.18% (128424/164257) 64.84% (81439/125581) 66.14% (27212/41141)

The batched variant of authorizeAssetsOperation enriched each asset with
only its directly-set owners and domains, never the ones inherited from a
parent (schema/database/service). An asset that inherited an unheld domain
then looked domainless to the policy, so hasDomain() returned true and the
cross-domain move this PR blocks was allowed again; an asset owned only
through its parent was wrongly denied.

Go back to the per-asset load, which resolves inherited owners and domains
the same way every other authorization check does. The N+1 this briefly
optimized was a deferrable note, not a blocker, and batching with
inheritance belongs in its own change.

Adds an IT for a table that inherits its schema's unheld domain: pulling
it into the caller's domain must be denied.
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-10-15T05:58:47Z)

The entry left the queue before it was built, so no checks ran against it.

sonika-shah and others added 3 commits October 15, 2026 11:38
The backend now authorizes a domain change with the EditDomains operation,
but the UI still showed the Domains edit control based on EditAll. A policy
that grants EditAll yet denies EditDomains (or grants EditDomains alone)
was therefore not reflected in the UI.

Derive a canEditDomains flag the same way the other field flags are built
(getPrioritizedEditPermission: the field permission, falling back to
EditAll), so the control follows the exact rule the server enforces. Route
the three domain-edit gates through it: the generic DomainLabel hook, the
connection-service header, and the incident-manager header.

Backward compatible: EditAll still subsumes EditDomains, so existing
setups are unchanged.
The first pass moved the generic DomainLabel hook, the connection-service
header and the incident-manager header onto canEditDomains. Auditing every
DomainLabel permission binding surfaced more reassignment controls still
keyed to EditAll: the main data-asset header, the classification page, both
test-suite views, and the team header. Point each at canEditDomains so the
control appears exactly when the server would authorize the change.

Owner/tier/type/experts controls stay on EditAll (those are not domain
operations); read-only and admin-gated domain displays are unchanged.
…0-asset-reassignment-authz

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/resources/domains/DataProductResource.java
#	openmetadata-service/src/main/java/org/openmetadata/service/resources/domains/DomainResource.java
if (entity == null) {
return null;
}
return readDomains(JsonUtils.applyPatch(entity, patch));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Inherited target domain goes unchecked

If a table has explicit domain A but its schema belongs to domain B, removing /domains makes getPatchedDomains() return an empty list. A user scoped to A passes hasDomain() for that list, but the repository then returns the table with inherited domain B. The user can therefore move the asset into a domain they do not hold. Resolve the effective inherited domains before the second permission check.

How this was verified: The PATCH path authorizes the empty list, removes the explicit domain relationship, and then applies the parent’s domains before returning the table.

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-16T12:08:05Z)

Blocked the queue: integration-tests-postgres-opensearch, integration-tests-mysql-elasticsearch

@github-actions

Copy link
Copy Markdown
Contributor

🔄 Playwright impact map auto-refreshed

This PR touched specs or UI source that changed the source→spec routing map. I regenerated .github/playwright/impact-map.generated.json and pushed the diff to this branch.

- source entries: 936 → 937
- 1 added, 0 removed, 11 changed spec-list

New source→spec entries:
  openmetadata-ui/src/main/resources/ui/src/components/Database/Profiler/TableProfiler/QualityTab/QualityTab.component.tsx

Entries whose spec list changed:
  openmetadata-ui/src/main/resources/ui/playwright/e2e/fixtures/pages.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/TableClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/support/entity/service/DatabaseServiceClass.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/admin.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/apiResponse.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/common.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/entity.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/scopedLocators.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/testCases.ts
  openmetadata-ui/src/main/resources/ui/playwright/utils/waitHelpers.ts
  … and 1 more

What is this file? It is the auto-generated half of Playwright's PR planner. It routes "if source X changes, run specs Y" by walking spec imports and cross-referencing getByTestId strings. Hand-authored routing in impact-map.json always wins on conflict.

What if I want to regenerate locally instead? Run this before pushing your next change to skip the bot commit:

python3 .github/scripts/generate_playwright_impact_map.py
git add .github/playwright/impact-map.generated.json
git commit --amend --no-edit  # or a separate commit

Comment on lines +86 to +87
private static boolean isDomainsPath(String path) {
return path != null && (path.equals(DOMAINS_PATH) || path.startsWith(DOMAINS_PATH_PREFIX));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Whole-document patches bypass domain checks

A user with EditAll conditioned on hasDomain() can replace a table’s whole document using op: "replace" and path: "", with its domains changed from held domain A to unheld domain B. The first permission check sees A. But patchTouchesDomains() ignores the empty root path, so the target-domain check never runs. The repository still applies the replacement and stores B.

Treat root replacements as possible domain changes, or reject them before applying the patch.

How this was verified: The PATCH helper accepts the empty root pointer, the domain detector skips it, and the repository validates and stores the replacement’s domain IDs without checking the caller’s access to B.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ UI Checkstyle passed — lint findings in changed files

🔍 ESLint findings in this PR's files — 0 error(s), 14 warning(s)

Errors block the build. Warnings do not yet — they are rules whose backlog is still
being worked down, listed so this PR does not add to it. See docs/ui-code-quality-gate.md.

0 error(s), 14 warning(s) across 5 changed file(s).

Count Rule
8 react-hooks/exhaustive-deps
4 openmetadata-imports/no-lower-layer-page-imports
1 openmetadata-imports/review-sequential-api-calls
1 openmetadata-imports/no-cross-page-imports
All findings
Location Rule Message
🟡 src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx:295:8 react-hooks/exhaustive-deps React Hook useCallback has missing dependencies: 'isVersionView' and 'navigate'. Either include them or remove the dependency array.
🟡 src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx:459:8 react-hooks/exhaustive-deps React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx:535:7 react-hooks/exhaustive-deps React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx:585:8 react-hooks/exhaustive-deps React Hook useEffect has missing dependencies: 'fetchClassificationChildren', 'handlePageChange', and 'isAddingTag'. Either include them or remove the dependenc
🟡 src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/useTestCaseIncidentHeader.ts:29:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/DataQuality/IncidentManager/IncidentManagerPageHeader/useTestCaseIncidentHeader.ts:222:27 openmetadata-imports/review-sequential-api-calls Review these sequential API requests. If they are independent, start them together with Promise.all/Promise.allSettled; keep sequencing only when data-dependent
🟡 src/components/Settings/Team/TeamDetails/TeamsHeaderSection/TeamsInfo.component.tsx:110:9 react-hooks/exhaustive-deps The 'onEmailSave' function makes the dependencies of useMemo Hook (at line 289) change on every render. Move it inside the useMemo callback. Alternatively, wrap
🟡 src/components/Settings/Team/TeamDetails/TeamsHeaderSection/TeamsInfo.component.tsx:136:5 react-hooks/exhaustive-deps React Hook useCallback has a missing dependency: 'updateTeamHandler'. Either include it or remove the dependency array. If 'updateTeamHandler' changes too often
🟡 src/components/Settings/Team/TeamDetails/TeamsHeaderSection/TeamsInfo.component.tsx:185:5 react-hooks/exhaustive-deps React Hook useCallback has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/components/Settings/Team/TeamDetails/TeamsHeaderSection/TeamsInfo.component.tsx:355:6 react-hooks/exhaustive-deps React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array.
🟡 src/components/observability/TestSuiteDetail/TestSuiteDetail.tsx:36:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/TestSuiteDetail/TestSuiteDetail.tsx:37:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/components/observability/TestSuiteDetail/TestSuiteDetail.tsx:38:1 openmetadata-imports/no-lower-layer-page-imports Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here.
🟡 src/pages/TestSuiteDetailsPage/TestSuiteDetailsPage.component.tsx:55:1 openmetadata-imports/no-cross-page-imports Page features must not import another page feature. Move shared code to components, hooks, interfaces, or pure utilities.

Fix locally (fast - only checks files changed in this branch):

make ui-checkstyle-changed

@github-actions

Copy link
Copy Markdown
Contributor

✅ Generated Sources Auto-Updated

The generated TypeScript types (src/generated/) and dereferenced JSON
schemas (src/jsons/, public/jsons/) have been automatically updated
based on JSON schema changes in this PR.

@gitar-bot

gitar-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · Adding target-domain checks to asset PATCH/PUT and bulk reassignment changes authorization; bypasses could let users move assets into domains they cannot access.

Adds an EditDomains operation and checks target domains on asset PATCH and PUT reassignment, so users scoped by hasDomain() can no longer move assets into domains they do not hold. Bulk asset endpoints now authorize each asset individually. Resolved: per-asset authorization no longer relies on bulk hydration, and the patch domain check now resolves the persisted domain by id rather than trusting the client FQN. No open issues found.

✅ 2 closed
✅ Performance: Per-asset authorize resolves each asset without bulk hydration

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/EntityResource.java:701-709
authorizeAssetsOperation loops over every asset and calls authorizer.authorize with a single-entity ResourceContext<>(type, id, fqn) that has no BulkFieldHydrator. Each iteration lazily resolves the asset from the DB (and on-demand loads tags per condition), so a domain asset picker submitting N assets triggers N separate entity loads and policy evaluations before the bulk repository operation then loads them again. The replaced authorizeBulkAssetsPermission did this with a single listPermissions call. For large bulk add/remove requests this is an N+1-style cost. Consider building the per-asset ResourceContexts with a shared BulkFieldHydrator (the bulk constructor) so on-demand fields are batch-loaded once for the whole request.

✅ Security: Domain check trusts client FQN in patch; persisted domain is by id

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/EntityResource.java:704-718 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/EntityResource.java:812-813 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/EntityResource.java:844-845 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/EntityResource.java:890-891
JsonPatchUtils.getPatchedDomains returns the EntityReferences exactly as the client sent them in the patch, and authorizeDomainChange hands them unresolved to UpdatedDomainsResourceContext. hasDomain() then calls SubjectContext.checkDomainHierarchyAccess, which compares only getFullyQualifiedName(). The repository, though, persists the domain by id (validateDomainsByRef → Entity.getEntityReferenceById(DOMAIN, domain.getId(), …)).

That leaves two problems:

  • Bypass: a domain-scoped user can send {"op":"add","path":"/domains","value":[{"id":"<otherDomainId>","type":"domain","fullyQualifiedName":"<heldDomainFqn>"}]}. The check passes because the FQN matches the held domain, and the asset is then stored in the other domain, which is the exact move this PR is meant to block.
  • Crash: an id-only reference, which is common from API clients, has a null FQN. isDomainParentOrEqual then calls FullyQualifiedName.getParentFQN(null), so CharStreams.fromString(null) throws an NPE and the request returns 500 instead of being authorized.

The ITs always send a matching id and FQN, so they don't cover either case. Fix: resolve each target domain from its id on the server before building the context, and authorize against the resolved references.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

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

Labels

backend 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.

Domain reassignment is authorized against the source domain only — a domain-scoped user can move assets into domains they do not hold

5 participants