Skip to content

Fixes #38982: Keep another domain's data contracts from domain-only users - #39118

Open
Vamsi-klu wants to merge 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/38982-data-contract-domain-scope
Open

Vamsi-klu wants to merge 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/38982-data-contract-domain-scope

Conversation

@Vamsi-klu

@Vamsi-klu Vamsi-klu commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #38982

A user who holds the DomainOnlyAccessRole in one domain could read, list, search, patch, delete and create the data contract of another domain's table, while the table itself was refused to them. This PR decides a contract in the domains of the entity it governs, so the contract is refused exactly when its table is.

Root cause

  • dataContract.json has no domains field, so ResourceContext.getDomains() returned entity.getDomains(), which is null for a contract (openmetadata-service/.../security/policyevaluator/ResourceContext.java:420-428 on main).
  • RuleEvaluator.hasDomain() returns true for a resource with no domains (RuleEvaluator.java:216-221). So DomainAccessDenyRule (!hasDomain()) never fired for a contract.
  • On main the seeded DomainOnlyAccessPolicy also has DomainAccessAllowRule (allow All when hasDomain()). That is why DELETE, PUT and POST went through on main, even though the reporter saw a 403 for DELETE on 2.1.1.
  • Create had the same hole: CreateResourceContext.getContainerDomains() found no container for a contract (CreateResourceContext.java:121-132), so hasDomainForCreate passed.

The fix

  • ResourceContext.getDomains() resolves a DATA_CONTRACT's domains through the new DataContractRepository.getGovernedEntityDomains: the current domains of the governed entity, inherited ones included. Every endpoint that authorizes through ResourceContext follows: GET /{id}, /name/{fqn}, /{id}/odcs, /{id}/odcs/yaml, /name/{fqn}/odcs, /{id}/versions, /{id}/versions/{v}, /{id}/results, PATCH, PUT, DELETE and validate. So do the rows of GET /dataContracts and /dataContracts/search, which go through readableRows.
  • CreateResourceContext counts those domains as the contract's container domains. A member can only create a contract for an entity in their domains (POST, PUT, ODCS import), as ADR:2026-11-03-a-create-is-authorized-against-its-stored-container has it for every other create.
  • DataContractRepository.validatePatch keeps the stored entity. Without this, a member could PATCH /entity on their own contract and move it onto another domain's table, past the create check. It follows IngestionPipelineRepository.validatePatch, which keeps the pipeline's service. The updater never tracked an entity change, and the contract's FQN and CONTAINS row kept pointing at the old entity anyway.
  • DataContractResource reuses the repository's new isSupportedTarget instead of its own copy.
  • Contracts of entities in no domain resolve to no domains and are decided exactly as before.

Design choice. I picked option (b), scoping the decision to the governed entity, over (a), an inherited domains field on the schema. Option (b) needs no schema change, no generated-model change, no search-mapping change and no migration. It cannot drift from the entity either: a domain move on a table applies to its contract on the next request. Option (a) would add a stored field that a PATCH or PUT could set apart from the entity's, plus a reindex and a UI surface. The existing ResourceContext already branches by type for domains and parents (DOMAIN, GLOSSARY_TERM, TAG, DATA_PRODUCT), so the contract case sits next to them. The rule is recorded in docs/decisions/2026-11-27-a-data-contract-is-in-the-domains-of-the-entity-it-governs.md.

Behavior changes to note

  • A domain-only user now gets a 403 on another domain's contract wherever they get a 403 on its table, and no longer sees it in lists or /dataContracts/search.
  • A PATCH that changes or removes /entity is now ignored and the stored entity is kept. Removing /entity used to answer 400.

Still open (follow-up, not in this PR). The dataContract search index (/v1/search/query?index=dataContract, its aggregations and the search CSV export) still returns other domains' contracts to a domain-only user when search access control is on. The contract document carries no domains, so search RBAC reads it as domainless. That path is not one of the endpoints in the issue, and it was like this before this PR. Closing it needs a design choice: either index the governed entity's domains and propagate them on every domain change of the entity or its parents, or post-filter the hits as TestCaseSearchMasker does for test cases. The ADR's Consequences names it. Follow-up issue: #39191.

Type of change:

  • Bug fix

High-level design:

N/A, small change. The design choice is above and in the ADR.

Tests:

Use cases covered

  • A member of domain A (a Group team with domain A and default roles DataConsumer + DomainOnlyAccessRole, as in the report) gets a 403 on every item read of the contract of a table in domain B. The same holds for a table that inherits domain B from its schema.
  • The same member does not see those contracts in GET /v1/dataContracts (paged through to the end) or in GET /v1/dataContracts/search.
  • PATCH, DELETE, PUT (update) and POST (create for a domain B table) are refused, and the stored contract is unchanged.
  • A PATCH of /entity cannot move the member's own contract onto a domain B table.
  • The member can still read and PATCH the contracts of their own domain's table and of a domainless table, and can create a contract for an own-domain table.

Unit tests

  • No new unit test. The behavior is the authorization decision over real entities, which the IT exercises end to end. The planner lists DataContractResource as having no unit test reference; its change only swaps a private helper for the repository's identical check.
  • Ran ResourceContextTest (5 passed) and RuleEvaluatorTest (32 passed) through the planner, see below.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DataContractDomainAccessIT.java. It matches the existing *DataContract*IT pattern in the impact map, and plan_local_java_tests.py --check-branch is clean.

Fails on main. I ran DataContractDomainAccessIT on the unfixed code (base 730a1e0, the first four test methods):

mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=DataContractDomainAccessIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
[ERROR] Tests run: 4, Failures: 3, Errors: 0, Skipped: 0
  • contractOfAnotherDomainsTableIsRefusedOnEveryItemRead: 16 failures, one per path, e.g. GET /v1/dataContracts/51a48444-... must be refused to a member of another domain ==> Expected org.openmetadata.sdk.exceptions.ForbiddenException to be thrown, but nothing was thrown.
  • contractOfAnotherDomainsTableIsLeftOutOfListAndSearch: GET /v1/dataContracts ==> expected: <[..._own_contract, ..._none_contract]> but was: <[..._none_contract, ..._for_contract, ..._own_contract, ..._inh_contract]>, and the same for /search.
  • contractOfAnotherDomainsTableCannotBeChanged: PATCH, DELETE and POST each Expected ...ForbiddenException to be thrown, but nothing was thrown.
  • contractsOfOwnDomainAndDomainlessTablesStayOpenToTheMember (named ...StayReadableAndEditable in that run) passed, as it should on main.

The later additions were not run against main: the PUT assertion, ownContractCannotBeMovedOntoAnotherDomainsTable and the own-domain create. On main, prepare stores the patched /entity and DomainAccessAllowRule allows the PUT, so both fail there by reading of the code.

With the fix:

Local Java test run: PASSED

  • Commit: 3fa7942c916a (base origin/main)
  • Finished: 2026-11-27 23:37 UTC · 35.2 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 7 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (2 classes) 2 37 0 0 8.3 passed
integration mysql-elasticsearch · parallel 4 488 0 26 26.9 passed
  • Impacted, not run locally: 6 classes (listed in the details)

Command:

make java_affected_run ARGS='--scope focused --add-it DataContractResourceIT,DataContractPermissionIT,DomainIsolationIT --add-unit RuleEvaluatorTest --reason "changes the domain decision for data contract reads and writes, the container domains a create is checked against, and what a contract PATCH keeps" --keep-going'
Class Tests Failed Skipped
ResourceContextTest 5 0 0
RuleEvaluatorTest 32 0 0
DataContractDomainAccessIT (new) 5 0 0
DataContractPermissionIT 11 0 1
DataContractResourceIT 451 0 25
DomainIsolationIT 21 0 0

The skips are existing @Disabled/assumption skips in those classes, not new ones. Pending: the full-scope plan (make java_affected, 23 unit classes and 253 ITs, plus PostgreSQL + OpenSearch), which the merge queue runs.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

None beyond the ITs above, which drive the REST API as the reporter's user.

Not tested: the dataContract search index path (see Still open), ODCS POST/PUT /odcs imports (they authorize through the same two contexts, but no test calls them as a domain member), Postgres + OpenSearch, and Collate (the diff adds public static methods and changes no public signature).

UI screen recording:

Not applicable: backend authorization fix, no UI change.

Checklist:

  • I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.

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

  • For JSON Schema changes: not applicable, no schema change.

  • For a UI feature or feature task: not applicable.

  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.

    • Reviewed SHA: 3fa7942. The first pass on 9ee4a4360eb found two 🔴. Fixed: a PATCH of /entity could move a contract onto another domain's table (now validatePatch, plus an IT case); I also added the PUT and own-domain create cases it asked for. Answered: the dataContract search index stays unscoped (see Still open). The second pass found no new 🔴 and rates that one non-blocking once the follow-up issue is linked.
    • Placement: every /v1/dataContracts authorization (item reads, versions, results, ODCS export, list and /search rows, POST, PUT, PATCH, DELETE, ODCS import) now decides a contract on its governed entity's domains. The UI contract tab and the ODCS merge import keep working. The dataContract search index, aggregations and search CSV export stay unscoped. Collate is not verified.
    • Trade-off: weighed by the author, holds because each decision costs one request-cached read of the governed entity's domains, listings check rows only when RowDecisionGate says rows may differ, and nothing is stored or reindexed.
    • Recommendation: approve. The search-path follow-up is Data contract search index shows other domains' contracts to domain-only users #39191.
  • Decision check: adds docs/decisions/2026-11-27-a-data-contract-is-in-the-domains-of-the-entity-it-governs.md.

  • I have added a test that covers the exact scenario we are fixing.

…domain-only users

Root cause: a data contract has no domains field, so ResourceContext.getDomains()
returned null for it and RuleEvaluator.hasDomain() treats a resource without
domains as open to everyone. DomainAccessDenyRule therefore never applied to
contracts, and DomainAccessAllowRule (allow All when hasDomain()) let a member
of one domain read, list, search, patch, delete and create the contract of
another domain's table while the table itself was refused to them.

Fix: a contract is decided in the current domains of the entity it governs.
ResourceContext.getDomains() resolves them for DATA_CONTRACT through the new
DataContractRepository.getGovernedEntityDomains, which covers item reads,
versions, results, PATCH, PUT, DELETE and the rows of the list and /search
endpoints. CreateResourceContext counts them as container domains, so a new
contract needs a domain of its entity. A PATCH keeps the governed entity, so a
contract cannot be moved onto another domain's entity past that check.
Contracts of entities in no domain are decided as before. The resource reuses
the repository's target check instead of its own copy. The decision is
recorded in ADR:2026-11-27-a-data-contract-is-in-the-domains-of-the-entity-it-governs.
@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 27, 2026 23:41
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@gitar-bot

gitar-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Changing domain-based authorization for contract reads, writes, and creation could expose or deny contracts across domain boundaries if entity resolution is wrong.

Scopes data contract authorization to the domains of the governed entity, so a domain-only user is refused another domain's contract wherever they are refused its table, and no longer sees it in lists or /dataContracts/search. DataContractRepository.validatePatch now keeps the stored entity, blocking PATCH moves onto another domain's table. No issues found.

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

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data contract of another domain's table can be read and edited

2 participants