Skip to content

Fixes #39150: Authorize deleteLineageByType against target entity context - #39193

Open
Vamsi-klu wants to merge 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/39150-lineage-delete-by-type-authz
Open

Vamsi-klu wants to merge 1 commit into
open-metadata:mainfrom
Vamsi-klu:fix/39150-lineage-delete-by-type-authz

Conversation

@Vamsi-klu

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #39150

I updated DELETE /v1/lineage/{entityType}/{entityId}/type/{lineageSource} (LineageResource#deleteLineageByType) to authorize against the real target entity's ResourceContext (Entity.getEntityReferenceById(entityType, entityId, Include.ALL) + OperationContext(entityType, MetadataOperation.EDIT_LINEAGE)), matching its FQN-based sibling deleteLineageByTypeAndName. Previously, deleteLineageByType authorized with a dummy LineageResourceContext whose getResource() returned "lineage" and whose getDomains(), getTags(), getOwners(), and getEntity() all returned null, allowing callers with conditional policies (hasDomain(), noOwner(), or matchAnyTag(...) DENY) to bypass authorization and bulk-delete lineage on entities outside their scope.

  • openmetadata-service/src/main/java/org/openmetadata/service/resources/lineage/LineageResource.java: Added authorizeLineageReference(SecurityContext, String entityType, UUID entityId, Include) mirroring the existing FQN overload, routed deleteLineageByType through it with Include.ALL, and removed the now-dead package-private LINEAGE_FIELD constant and LineageResourceContext inner class.
  • openmetadata-service/src/test/java/org/openmetadata/service/resources/lineage/LineageResourceDeleteByTypeAuthorizationTest.java: Added unit tests verifying table and pipeline target ResourceContext binding (including entity ID resolution via the target EntityRepository), EDIT_LINEAGE operation propagation, fail-closed AuthorizationException preventing DAO delete, and 404 EntityNotFoundException skipping authorization and delete.
  • openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/LineageDeleteByTypeAuthorizationIT.java: Added 6 real HTTP integration tests exercising hasDomain() deny on another domain, hasDomain() allow on the caller's own domain (with a table-scoped rule), matchAnyTag('PII.Sensitive') DENY, noOwner() deny on an owned table, 404 on a non-existent entity ID, and 404 on a mismatched (entityType, entityId).

(Note for maintainers: as an external contributor I cannot add #39150 to the Shipping project board.)

Type of change:

  • Bug fix

High-level design:

N/A — small bug fix bringing deleteLineageByType into parity with deleteLineageByTypeAndName.

Alternatives considered:

  • Passing new ResourceContext<>(entityType, entityId, null) without first calling Entity.getEntityReferenceById was rejected because ResourceContext#resolveEntity() swallows EntityNotFoundException and leaves entity = null (causing hasDomain() / noOwner() to fail open as true and allowing mismatched (entityType, entityId) pairs to reach CoreRelationshipDAOs#deleteLineageBySourcePipeline, whose SQL does not filter on toEntity).
  • Returning 404 for unknown or mismatched (entityType, entityId) aligns with the existing @ApiResponse(404) contract on deleteLineageByType and the exact behavior of deleteLineageByTypeAndName.

Tests:

Use cases covered

  • User with an All-scoped EDIT_LINEAGE policy conditioned on hasDomain() receives 403 Forbidden when calling DELETE /v1/lineage/table/{id}/type/ViewLineage on a table in another domain, and the lineage edge remains intact.
  • User with a table-scoped EDIT_LINEAGE policy conditioned on hasDomain() succeeds (200 OK) for a table in their own domain and deletes the ViewLineage edge.
  • User with an All-scoped ALLOW + matchAnyTag('PII.Sensitive') DENY receives 403 Forbidden on a PII.Sensitive-tagged table, and the lineage edge remains intact.
  • User with an All-scoped noOwner() condition receives 403 Forbidden on an owned table, and the lineage edge remains intact.
  • Missing entity IDs and mismatched (entityType, entityId) pairs return 404 Not Found before calling deleteLineageBySource.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • openmetadata-service/src/test/java/org/openmetadata/service/resources/lineage/LineageResourceDeleteByTypeAuthorizationTest.java
  • Results: 4 passed, 0 failed, 0 skipped in LineageResourceDeleteByTypeAuthorizationTest (plus 10 passed, 0 failed in LineageResourceGetLineageEdgeAuthorizationTest during development). Every changed line in LineageResource#authorizeLineageReference(SecurityContext, String, UUID, Include) and LineageResource#deleteLineageByType is exercised by LineageResourceDeleteByTypeAuthorizationTest.

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/LineageDeleteByTypeAuthorizationIT.java
  • Full details posted as a PR comment from target/java-tests/local-pr-results-details.md.

Local Java test run: PASSED

  • Commit: 6e919ab81c94 (base origin/main)
  • Finished: 2026-11-28 05:46 UTC · 43.2 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 2 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-service (1 class) 1 4 0 0 12.2 passed
integration mysql-elasticsearch · parallel 1 6 0 0 31.0 passed
  • Impacted, not run locally: 2 classes (listed in the details)

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  1. Executed make java_affected_run ARGS="--scope focused" against a real Testcontainers stack (mysql:8.4.13 + elasticsearch:9.3.0 + full OpenMetadata Dropwizard application).
  2. Verified all 6 real HTTP RBAC scenarios (LineageDeleteByTypeAuthorizationIT) end-to-end, confirming 403/404 denials leave lineage edges intact and 200 domain-matched delete removes the edge.
  3. Verified mvn -B spotless:apply, pre-commit hooks (Google Java Code Style for Java, Decision records), and python3 .github/scripts/plan_local_java_tests.py --check-branch all pass cleanly.

UI screen recording:

Not applicable — Java backend authorization bug fix with no UI changes.

Checklist:

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

  • My PR title is Fixes #39150: Authorize deleteLineageByType against target entity context

  • My PR is linked to a GitHub issue via Fixes #39150 above.

  • I have commented on my code, particularly in hard-to-understand areas.

  • For JSON Schema changes: N/A — no JSON Schema changes.

  • For a UI feature or feature task: N/A — Java backend authorization bug fix with no UI changes.

  • I have added tests (unit + backend integration tests) and listed them above.

  • Self-review: Reviewed commit 6e919ab81c94694410db47949bf5aa8dcf722047 against REVIEW.md and .claude/rules/java.md with fresh eyes — 0 🔴 findings.

    • Placement: Reached via DELETE /v1/lineage/{entityType}/{entityId}/type/{lineageSource} (called by Python ingestion overrideLineage via ometa/mixins/lineage_mixin.py:delete_lineage_by_source and direct REST callers; no UI, Java SDK, or MCP callers exist in OSS). Removing package-private LineageResource.LINEAGE_FIELD and LineageResourceContext has zero callers in OSS; private openmetadata-collate was not on disk to verify, though package-private nested resource types are not part of the public SPI.
    • Trade-off: weighed by the author, holds because resolving the target via Entity.getEntityReferenceById(..., Include.ALL) and evaluating ResourceContext adds one cached reference lookup per call (plus one lazy repository read only when a non-admin caller has conditional policies — unconditional Allow-All ingestion bots never trigger ResourceContext.resolveEntity()) and returns 404 instead of a no-op 200 for missing or type-mismatched IDs, matching sibling deleteLineageByTypeAndName and the existing 404 OpenAPI contract while closing the conditional-RBAC bypass.
    • Recommendation: approve.
  • Decision check: No Accepted ADR is contradicted (verified ADR:2026-11-20-a-method-returns-once, ADR:2026-11-03-lineage-edge-pipeline-is-restricted-and-view-authorized, ADR:2026-11-02-domain-only-access-cannot-change-administration-resources-in-no-domain; check_decision_records.py is clean), and no new ADR is needed because this is a self-evident bug fix bringing deleteLineageByType into parity with sibling deleteLineageByTypeAndName and existing per-entity lineage authorization.

  • I have added a test that covers the exact scenario we are fixing (#39150 referenced in LineageDeleteByTypeAuthorizationIT).

@Vamsi-klu
Vamsi-klu requested a review from a team as a code owner November 28, 2026 05:55
@Vamsi-klu
Vamsi-klu requested a review from harshach November 28, 2026 05:55
@Vamsi-klu

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 6e919ab81c94 (base origin/main)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-service (1 class): LineageResourceDeleteByTypeAuthorizationTest (4 passed)
  • integration · mysql-elasticsearch · parallel: LineageDeleteByTypeAuthorizationIT (6 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=LineageResourceDeleteByTypeAuthorizationTest,LineageResourceGetLineageEdgeAuthorizationTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<31 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Impacted, not run locally (2)
  • LineagePayloadScaleIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
  • LineageScenePerformanceScaleIT → nightly: openmetadata-nightly k8s-java-it (scale-it)
Commands
mvn -B package -pl openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=LineageResourceDeleteByTypeAuthorizationTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=LineageDeleteByTypeAuthorizationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

@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 28, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Binding deleteLineageByType to target-entity authorization changes access decisions; without it, callers could delete lineage outside their permitted domain or tag scope.

Authorizes DELETE /v1/lineage/{entityType}/{entityId}/type/{lineageSource} against the real target entity's ResourceContext instead of a placeholder context, closing a conditional-policy bypass that allowed bulk lineage deletion on out-of-scope entities. 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.

[Detail Bug] Lineage API: bulk delete-by-source bypasses conditional authorization (domain/owner/tag rules)

2 participants