Skip to content

Authorize every row of a CSV import, not only the import root - #36077

Merged
sonika-shah merged 11 commits into
mainfrom
fix/csv-import-row-authz
Nov 3, 2026
Merged

sonika-shah merged 11 commits into
mainfrom
fix/csv-import-row-authz

Conversation

@sonika-shah

@sonika-shah sonika-shah commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes open-metadata/openmetadata-collate#7802

Summary

CSV import now authorizes each row as its own write, the same as the matching REST call, instead of relying on the check made for the entity being imported into.

What changed

  • EntityCsv.authorizeRow runs for every EntityCsv importer row and for column rows: EDIT_ALL on an existing entity, CREATE on a new one, checked for the importing user. A refused row fails on its own and the rest of the import continues, in dry runs too.
  • A row creating an entity under a parent created earlier in the same file is checked on its own type, against that parent as the file defines it (new CreateResourceContext constructor for a parent that is not stored yet).
  • Test case rows are checked with TestCaseWriteAuthRequests, as the REST and ODCS paths are, before anything is created for the row.
  • Decision record: docs/decisions/2026-11-02-a-csv-import-authorizes-each-row-as-its-own-write.md.

Behaviour change: a row needs the same permission REST would need. For example, databases do not inherit their service's owners, so a service owner who does not own a child database gets failed rows for it.

Details
  • Authorization uses Authorizer.authorizeActor(ChangeActor, …), the mechanism authorizeImportedDomains already uses inside the import, and fails closed with no authorizer registered.
  • A created parent is recorded with the owners and domains it inherits where its row set none; the importer created it and could have named itself owner over REST. Teams do not inherit owners, so a group under a new department needs that department to name the importer as owner, as over REST.
  • Parents are matched on an FQN without quotes, because a recursive import can quote a parent's FQN as one part (e.g. "svc.db".schema).
  • EntityCsvTest.TestCsv overrides authorizeRow as a no-op; policy behaviour is covered by the ITs.
  • User import (createUserEntity) keeps its own checks and is not changed here.
  • Tests (MySQL + ES): DatabaseServiceResourceIT (test_recursiveImportCannotEditEntitiesOutsideCallerPermissions, test_recursiveImportByServiceOwnerCreatesAndUpdatesOwnHierarchy, test_recursiveImportChecksEachNewRowAgainstItsOwnType, test_recursiveImportCannotEditColumnsOfTableOutsideCallerPermissions), GlossaryResourceIT, TeamResourceIT, TestCaseCsvDomainIsolationIT.test_importCsv_rowIsCheckedAgainstItsOwnTable. The new checks fail without the change. The CSV-import IT classes (Database, DatabaseSchema, DatabaseService, DriveService, Glossary, Team, User, TestCaseCsvDomainIsolation) pass: 1745 tests, 0 failures.

RetriggerView in GreptileConfidence Score: 2/5

Do not merge yet: child creates can bypass explicit permission denies, and nested team imports still fail.

Findings

  1. P1 Security Child create denies are skipped ▶
  2. P1 Nested team imports fail ▶
  3. P2 Column checks lack focused coverage ▶

Summary

The PR adds per-row permission checks to CSV imports, including table writes made through column rows.

  • CSV imports check each row against its own target.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[New CSV row] --> B{Parent tracked as authorized?}
  B -->|No| C[Check CREATE for this row]
  B -->|Yes| D[Skip this row's CREATE check]
  C -->|Allowed| E[Queue row]
  D --> E
  E --> F[Save batch]
Loading

Reviews (2) · Last reviewed commit: "Let an import create under parents it cr..." · Reviewed by Greptile

Companion Collate PR: https://github.com/open-metadata/openmetadata-collate/pull/8214 (onboarding sample data imports as the installing user).

The import endpoint checked EDIT_ALL on the entity being imported into, but a
row can name any entity by FQN (recursive service import) or by name (teams,
glossary terms under another glossary's parent), so a caller who could edit one
entity could rewrite metadata of entities they had no rights on. Each row is now
authorized as its own write: EDIT_ALL on an existing entity, CREATE for a new
one. A denied row is reported as failed; the rest of the import continues.
@sonika-shah
sonika-shah requested a review from a team as a code owner October 23, 2026 08:29
@sonika-shah
sonika-shah requested a review from harshach October 23, 2026 08:29
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • Linked issue open-metadata/openmetadata-collate#7802 does not exist or is not accessible.

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.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Oct 23, 2026
A new row whose parent was created by an earlier row of the same import is part
of the subtree that row's check allowed; its parent cannot be loaded for owner
inheritance until the batch is written, or at all in a dry run. Adds owner-path
ITs: re-import and new hierarchy by a service owner, nested new glossary terms,
and a new sub-team, each in dry run and real run.
A row creating an entity under a parent created earlier in the same file is
checked on its own type, against that parent as the file defines it, in dry
and real runs alike.
Uses TestCaseWriteAuthRequests, as the REST and ODCS paths do, before
anything is created for the row.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:26

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI balanced review requested due to automatic review settings November 2, 2026 06:28

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

…eir table patch

An admin's import skips the per-row checks, as the authorizer does. New entities are tracked
by reference once their row succeeds, and a parent's view is built only for parents with child
rows, taking owners only where its type inherits them. Teams are checked against all parents.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 05:06

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Column rows skip the table check only when the entity this import created under that FQN is a
table; another type with the same FQN, such as a stored procedure, does not cover them.
A row passes when one permission allows it and none denies it explicitly, matching
AuthorizationLogic.ANY on the test case write endpoints.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 05:51

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@sonika-shah
sonika-shah added this pull request to the merge queue Nov 3, 2026
Copilot AI balanced review requested due to automatic review settings November 3, 2026 17:24

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@sonika-shah
sonika-shah enabled auto-merge (squash) November 3, 2026 17:24
@gitar-bot

gitar-bot Bot commented Nov 3, 2026

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

🔴 High risk · Per-row CSV authorization now governs entity and column writes; errors in row or parent checks could permit unauthorized metadata changes.

Adds per-row authorization to CSV import so each row is checked as its own write, matching the corresponding REST call, and refused rows fail individually while the rest of the import continues. Owner-based CREATE for rows under parents created earlier in the same file, test case row authorization, the decision record, and child CREATE checks for imported parents were all addressed. No open issues remain; the ADR wording about stored versus copied parents is closed without a fix.

✅ 6 closed
✅ Edge Case: Owner-based CREATE fails for rows whose new parent is only in this import

📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1418-1432 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1140 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1242 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:2168-2179
For a new row, authorizeRow builds a CreateResourceContext. Its setParents loads the parent by the reference id and turns EntityNotFoundException into parentEntities = null, so getOwners() returns null. In a dry run, a parent created earlier in the same CSV exists only in dryRunCreatedEntities or as a simulated stub with a random id. Examples are a schema or table created by createTableEntity/createColumnEntity, a new parent glossary term, or a new parent team. The child row's CREATE check therefore sees no owners. A service, glossary or team owner whose permission comes from isOwner() gets failed child rows in the dry run, but the real run passes because getEntityWithDependencyResolution flushes the parent first. The preview no longer matches the import, which contradicts the PR's "Dry runs report the same result" and the dry-run rule in ADR:2026-10-09-bulk-edits-authorize-each-entity-as-its-patch. The same happens in a real run whenever the parent is still sitting in pendingEntityOperations when the child row is authorized. Fix: when the parent was created in this import (it is in dryRunCreatedEntities/pendingEntityFQNs), authorize the child against the nearest persisted ancestor, or reuse the CREATE decision already made for the parent. Add an IT that dry-runs a nested new hierarchy as a non-admin owner.

✅ Security: Test case CSV import still writes rows without per-row authorization

📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1418
TestCaseRepository.TestCaseCsv.createEntity has its own loop and calls repository.createOrUpdateForImport(null, testCase, importedBy) directly. It never reaches EntityCsv.createEntity, so authorizeRow does not run for it. The only per-row gates are the domain filters (resolveAccessibleTargetLink, resolveAccessibleTestSuite), and they apply only when DomainAccessFilter.shouldApply holds. A caller who passes the root check can still name an existing test case on another table by its entity FQN and name, and overwrite it. This is the same cross-entity rewrite the PR closes for other importers, and it goes against the description's claim that the fix "covers every EntityCsv importer". Fix: call authorizeRow(TEST_CASE, repository.findMatchForImport(testCase), testCase) after the FQN is set and before createOrUpdateForImport or the dry-run prepareInternal, and report an AuthorizationException as a failed row.

✅ Quality: New per-row CSV import authorization rule is not recorded in docs/decisions

📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1414-1428
This PR adds an authorization contract for every CSV importer, but no record in docs/decisions/ states it. Because the repository squash-merges, the rule exists only in the PR description: "each row is authorized as its own write. Existing entities need EDIT_ALL on themselves and new entities need CREATE... A denied row is reported as failed and the rest of the import continues. Dry runs report the same result." ADR:2026-10-09-bulk-edits-authorize-each-entity-as-its-patch covers bulk edits through EntityPatchBatch and derives operations from each patch, so it does not cover CSV import's fixed EDIT_ALL/CREATE choice. That choice changes behaviour for service, glossary and team owners. The record would assert: "A CSV import authorizes each row as the importing user: EDIT_ALL on the matched existing entity, CREATE (with parent-inherited context) on a new one; a denied row fails alone and the import continues, in dry runs too; user import is excluded."

✅ Security: Children of an imported create skip their own CREATE check entirely

📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1414-1416 📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1436-1450
When the parent FQN is in authorizedCreates, authorizeRow adds the child without calling authorizeActor for the child's type (EntityCsv.java:1436-1442). The parent row only proved CREATE on the parent's type. A user whose policy allows Database:Create but denies Table:Create (or DatabaseSchema:Create) can still create schemas and tables by putting a new database row first in the CSV. The comment justifies the skip with owner inheritance, but the CSV row can set the new database's owners to someone else, so the importer may not end up owning the subtree either. REST would refuse these creates, which contradicts the PR's stated REST parity. A safer approach is to keep checking CREATE on the child's type and fill the missing owner-inheritance context from the in-memory parent row (for example, a map from FQN to the pending or dry-run entity), instead of dropping the check.

✅ Edge Case: Dry run passes children of a refused parent that the real run fails

📄 openmetadata-service/src/main/java/org/openmetadata/csv/EntityCsv.java:1445-1459
An earlier parent row that was allowed is already in authorizedCreates during a dry run, so the extra dryRun && !parentPersisted branch only changes the result in one case: the parent is not persisted and was not authorized. That happens when its row was refused, or when it is missing from the file. In that case the dry run reports the child as passing authorization, while the real run fails it. This contradicts the PR's claim that "Dry runs report the same result." Drop the dry-run branch and rely on authorizedCreates. That set is filled the same way in dry and real runs, so the child gets the same outcome in both.

...and 1 more closed from earlier reviews

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

@sonika-shah
sonika-shah merged commit d13d0ad into main Nov 3, 2026
64 of 65 checks passed
@sonika-shah
sonika-shah deleted the fix/csv-import-row-authz branch November 3, 2026 17:28
ShaileshParmar11 added a commit that referenced this pull request Nov 4, 2026
…37046)

CSV imports now authorize each row as its REST write (#36077), so a new
test case row needs Create on testCase. The EditAll user's policy lacked
it, the import refused the new row, and the flow saw 1 passed row instead
of 2 on both MySQL and PostgreSQL.
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 10, 2026
BMJLearnToHelloWorld added a commit to BMJLearnToHelloWorld/SmartMetadata that referenced this pull request Nov 10, 2026
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.

3 participants