Skip to content

fix: authorize metric CSV export and import rows per metric (CWE-863 authz) - #36792

Merged
sonika-shah merged 8 commits into
open-metadata:mainfrom
harshach:agent/ant-2026-3csn88ix-medium-cwe
Nov 5, 2026
Merged

sonika-shah merged 8 commits into
open-metadata:mainfrom
harshach:agent/ant-2026-3csn88ix-medium-cwe

Conversation

@harshach

@harshach harshach commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes metric CSV authorization from advisory ANT-2026-3CSN88IX (CWE-863). There is no public issue for the advisory; the PR uses skip-pr-checks following #36758.

A user allowed to export or import one metric could read or modify metrics outside their permitted scope through CSV. Exports now retain main's per-metric view filtering and also apply domain filtering. Each import row uses the shared EntityCsv CREATE/EDIT_ALL authorization, with metric-specific checks for the moved subtree and each new parent or metric-group destination. Admin imports skip per-row authorization work.

The effective group inherited from a parent is resolved before authorization, including dry runs. A parent created earlier in the same real import is persisted before its policy attributes are checked; dry runs use the successful pending row with its tags and owners. Async imports capture the impersonating bot at submission and restore/clear that attribution around execution, so impersonation-dependent denies still apply.

Type of change:

  • Bug fix

High-level design:

The generic row-target check remains in EntityCsv. MetricCsv adds only hierarchy checks through the configured authorizer. MetricRepository.hierarchyMembershipChanged and hierarchyDestinations are shared with REST/MCP authorization. Existing prerequisite flushing and job arguments are reused.

The accepted metric-writes ADR has a dated v2 amendment documenting CSV parity, effective-group resolution, pending-parent authorization, admin skipping, and async attribution, with MetricCsvAuthorizationIT as a guard.

Tests:

Verification for 0ae6e7d98ca:

MetricCsvDomainIsolationIT covers confined exports and row writes with real policies. MetricCsvAuthorizationIT covers inherited denied groups for create/move, pending-parent tag denies and owner allows, moved-subtree checks (including moving back to root), unchanged membership, and async impersonation. Each scenario exercises dry and real imports. The async denial cases also check PATCH and synchronous imports as controls.

Unit coverage checks admin skipping, the configured authorizer, and worker attribution replacement/cleanup on success and failure. Obsolete tests counting the duplicated target check were replaced by API behavior tests. The local job-argument DTO is exercised through submission/serialization/execution in the async IT; it needs no separate getter/setter test. Current coverage percentages were not measured.

Backend integration tests

The full affected-test run is not green; three failures also reproduce on clean main.

Verification Tests Result
Affected unit tests (11 classes) 219 Passed
MySQL/Elasticsearch parallel lane 6,099 2 baseline failures, 425 skipped
MySQL/Elasticsearch isolated lane 386 1 baseline failure
Redis cache ordering 1 Passed
PostgreSQL/OpenSearch search lane (8 classes) 46 Passed on retry
Final MetricCsvAuthorizationIT, including move-to-root 14 Passed

The three baseline failures are TeamResourceIT#test_importCsv_ownerDryRunReimportsNestedHierarchy, TeamResourceIT#test_impersonatedOwner_cannotChangeDefaultRolesOrPolicies, and MetricMigrationIT#mergedMigrationUpgradesPopulatedPriorShapeFixture. The same assertions/errors were independently reproduced on clean main at 4195406575cf during the rebase and recur unchanged in this run.

The first focused run passed all 108 selected unit tests, all 12 initial new authorization cases, and all 15 existing metric CSV/MCP cases. Five CsvAsyncJobResourceIT downloads returned HTTP 404 there; the broad branch run had no failures in that class. A fresh clean-main run also produced download 404s (3 of 16 cases). Concurrent admin exports exceed the existing five-results-per-user retention cap; the exact failing cases vary with timing. This pre-existing test interference is not changed here.

The search lane initially ran zero tests because its S3 image was removed during startup. After retaining the image with a temporary container, all 46 selected tests passed. The holder is removed after verification.

Commands used the reactor (-am), the planner's engine/lane profiles, and Failsafe -Dit.test; the affected plan also explicitly added BotImpersonationIT because shared CSV authorization now preserves its actor. Before the fixes, the new API tests reproduced the four requested security cases in both modes (8 failures, zero errors); the subtree controls passed.

Nightly-only tests not run locally: LineagePayloadScaleIT, LineageScenePerformanceScaleIT, EntityLoaderSmokeUIIT, SearchAvailableAllKindsDuringReindexUIIT, and SearchAvailableDuringReindexUIIT.

Other validation

Spotless, git diff --check, the Java impact-map branch check, and the decision-record validator pass. No schema, ingestion, or UI changes. The advisory's private Docker reproducer image is unavailable; verification uses real HTTP against the embedded OpenMetadata stack.

Checklist:

  • Regression tests cover the authorization failures and permitted controls.
  • The final diff was reviewed against REVIEW.md.
  • The durable CSV write contract is recorded in the accepted metric-writes ADR.
  • No generated-code or migration changes are required.

@harshach harshach added the skip-pr-checks Bypass PR metadata validation check label Nov 1, 2026
@harshach
harshach requested a review from a team as a code owner November 1, 2026 16:38
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Nov 1, 2026
@harshach
harshach force-pushed the agent/ant-2026-3csn88ix-medium-cwe branch from 6f8cf82 to cc674c1 Compare November 1, 2026 17:37
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 1, 2026
@sonika-shah
sonika-shah added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-02T06:45:34Z)

Blocked the queue: py-tests-status

  • py-tests — py-tests-status, python / Verify Expected Jobs, python / Unit Tests & Static Checks (3.12), python / Unit Tests & Static Checks (3.11), python / Unit Tests & Static Checks (3.10)

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-02T15:50:43Z)

Blocked the queue: integration-tests-mysql-elasticsearch

@harshach
harshach added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-03T02:12:45Z)

Blocked the queue: playwright-summary

Failed Playwright tests:

  • Pages/AIProfile/ProfileMembers.spec.ts › Should navigate from the users page to a role detail
  • Pages/AIProfile/ProfileTeam.spec.ts › Should confirm a team move in a popover, not a modal

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-11-03T08:14:24Z)

Blocked the queue: integration-tests-postgres-opensearch

Copilot AI balanced review requested due to automatic review settings November 3, 2026 13:31
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 3, 2026
@sonika-shah
sonika-shah enabled auto-merge November 3, 2026 13:32

Copilot AI left a comment

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.

🟡 Changes recommended

Queued hierarchy writes cause stale authorization checks that can bypass child edit restrictions or wrongly deny later rows, and integration tests leave shared-server fixtures without failure-safe cleanup.

5 open issues

Review effort: Balanced

@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

Copilot AI balanced review requested due to automatic review settings November 5, 2026 06:43
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 5, 2026

Copilot AI left a comment

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.

🔵 Needs a closer look

Authorization checks overlook queued parent updates and dry-run child creations, incorrectly rejecting valid child imports and approving dry-run moves that real imports reject.

1 open issue
4 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 07:05
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 5, 2026

Copilot AI left a comment

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.

🔵 Needs a closer look

Human assessment is needed because subtree deduplication can skip authorization of queued tag updates, allowing a root move to include a newly protected child.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

# Conflicts:
#	openmetadata-service/src/test/java/org/openmetadata/service/resources/metrics/MetricGroupResourceTest.java
Copilot AI balanced review requested due to automatic review settings November 5, 2026 08:13
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 5, 2026

Copilot AI left a comment

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.

🟡 Changes recommended

Import authorization can overlook an existing child’s queued PII.Sensitive tag when a later row assigns its root to a group, bypassing an EditAll deny.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 08:44
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 5, 2026
@gitar-bot

gitar-bot Bot commented Nov 5, 2026

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

🔴 High risk · Adds per-metric authorization and domain filtering to metric CSV exports/imports; incorrect checks could expose restricted metrics or block legitimate writes.

Adds per-metric authorization to CSV export and import, covering hierarchy moves, inherited groups, pending parents, and async impersonation to address CWE-863. Resolved this session: import hierarchy checks against stored metrics with no parent or group, duplicated base row authorization that ignored admin skip, and missing EditAll checks on children queued earlier in dry runs. No open issues found.

✅ 4 closed
✅ Bug: Import hierarchy check compares against a stored metric with no parent/group

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:725-739 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:1560-1574 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1142-1143 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1244-1245
authorizeRow gets original from findMatchForImport, which is findByNameOrNull(fqn, ALL). That call returns only the stored JSON, and MetricRepository.getFieldsStrippedFromStorageJson removes parent and metricGroup from that JSON. Your own comment at line 716 says this. Even so, authorizeHierarchyChange and hierarchyDestinations pass that relationship-less original to hierarchyMembershipChanged, so original.getParent() and original.getMetricGroup() are always null. This causes two problems:

  1. Missed checks. Take a row that clears an existing parent (an empty parent column). clearEntitySpecificRelationshipsForMany drops the CONTAINS edge, so the metric really moves to the root. But null vs. null reads as "unchanged", so the hierarchySubtree EditAll checks are skipped. PATCH requires those checks for the same move, so the import still allows more than PATCH, which is the gap this PR is meant to close.

  2. False denials. Re-importing an unchanged export of a metric that already has a parent or group always counts as a move. The user then needs EditAll on the whole subtree and on the existing parent/group just to edit a description. A user who can PATCH the metric can't re-import their own export.

The unit tests build stored without parent or group, and the IT metrics have no hierarchy, so neither case is covered. Fix: before running the hierarchy comparison, load the stored metric's real parent and metricGroup by id. Then add a test where the stored metric has a parent, for both an unchanged row and a cleared-parent row.

✅ Quality: Metric row check repeats base row authorization and ignores admin skip

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:714-728 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1186-1188 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1287-1289
After the rebase, EntityCsv.createEntity calls both the new authorizeRow(original, entity) (line 1186) and the existing authorizeRow(entityType, original, entity) (line 1188). The existing one already authorizes EDIT_ALL on the stored entity or CREATE through createContext, and createContext handles parents created earlier in the same file. MetricCsv.authorizeRow runs the same row-target check again through authorizeRowTarget, so every metric row goes through policy evaluation twice and loads its ResourceContext twice. The override also bypasses checksRowWrites(), which goes against the Accepted row-as-write ADR rule that "an admin's import skips the per-row checks". For an admin, every metric row still triggers repository.get(...parent,metricGroup...), and a hierarchy change also triggers a hierarchySubtree query, which is a per-row DB cost on large imports. The fix: drop the row-target part of the override, keep only the hierarchy checks, and return early when !checksRowWrites().

✅ Edge Case: Dry run skips EditAll check on children queued earlier in the import

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:766-780 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1833-1838 📄 openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/MetricCsvAuthorizationIT.java:208-222
authorizeQueuedDescendants only scans queuedEntities(METRIC), which reads pendingEntityOperations. Rows only reach that list on a real import. In EntityCsv.createEntity, the dry-run branch puts entities into dryRunCreatedEntities and never queues them. So in a dry run, a child with a restricted tag created a few rows earlier under the moved metric is never authorized. The dry run reports the metricGroup-change row as passing, and the real import then fails it. That breaks the PR's stated goal of dry-run parity (other checks such as importParent and destinationContext use pending dry-run entities on purpose). The new IT only runs with dryRun=false, so it doesn't catch this. Fix: in dry run, take the candidates from dryRunCreatedEntities (Metric values), and parameterize movingMetricRequiresEditOnChildrenQueuedEarlierInTheImport over dryRun.

Closed: Quality: Metric-writes ADR still says CSV import skips the hierarchy checks

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:740-754 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java:1773-1787 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricAuthorization.java:48-51 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricAuthorization.java:114-128
The Accepted metric-writes ADR says the metric write checks "live in MetricAuthorization". Its Consequences add: "Metric CSV import does not run these checks yet: a row can set parent or metricGroup without EditAll on them." This PR contradicts both statements. It moves hierarchyDestinations/hierarchyMembershipChanged into MetricRepository and re-implements the subtree and destination loop inside MetricCsv. The record needs a revision that states the rule taken from the description: "Each metric import row is authorized like a direct write of its target, including EditAll on the moved subtree and on each new parent/metric group destination, so an import never grants more than PATCH or POST." The revision should also say where those shared membership comparisons now live, and add a guard test.

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

Copilot AI left a comment

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.

🔵 Needs a closer look

Human assessment is needed because queued snapshots can bypass move authorization, while large dry-run imports incur quadratic processing and allocation costs.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@sonika-shah
sonika-shah merged commit e9c488b into open-metadata:main Nov 5, 2026
60 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.1 backend safe to test Add this label to run secure Github workflows on PRs skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants