Skip to content

[2.1] Authorize Document Store writes in one place (backport 2.1 #38196) - #38227

Merged
manerow merged 1 commit into
2.1from
refactor/docstore-resource-authorization-2.1
Nov 19, 2026
Merged

manerow merged 1 commit into
2.1from
refactor/docstore-resource-authorization-2.1

Conversation

@manerow

@manerow manerow commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Backport of #38196 to 2.1. No linked issue.

The email template authorization in the Document Store moves into DocStoreResource: one helper, requireAdminForEmailTemplates, that every write endpoint calls. DocStoreMapper only converts the request and validates the template content, and PATCH keeps a document's entityType, the same way it keeps the name and FQN.

The cherry-pick applied cleanly: the change is identical to #38196.

Type of change:

  • Improvement

Tests:

Unit tests

Not added, as in #38196: the change is an HTTP authorization rule, covered end to end by DocStoreResourceIT.

Backend integration tests

Local Java test run: PASSED

  • Commit: 1ab9d6334055 (base origin/2.1)
  • Finished: 2026-11-19 15:41 UTC · 4.0 min
  • Scope: focused; merge readiness is not established. Broader steps deferred: 4 (run --scope full).
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-mcp (1 class) 1 46 0 0 1.1 passed
integration mysql-elasticsearch · parallel 1 14 0 0 2.9 passed

UI screen recording:

Not applicable: backend-only change.

Checklist:

RetriggerView in GreptileConfidence Score: 5/5

This backport appears safe to merge.

Summary

This backport puts email-template write checks in DocStoreResource and keeps a document's type unchanged during PATCH.

  • Email-template writes require admin access across Document Store routes.
  • Document patches keep each document’s original type.

No target-branch correctness issues were found. Tests were not run during this review.

Reviews (1) · Last reviewed commit: "[2.1] Authorize Document Store writes in..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner November 19, 2026 15:42
@manerow
manerow requested review from sonika-shah and removed request for a team November 19, 2026 15:42
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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.

@manerow manerow added the safe to test Add this label to run secure Github workflows on PRs label Nov 19, 2026
@manerow manerow added backend skip-pr-checks Bypass PR metadata validation check labels Nov 19, 2026
@manerow

manerow commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 1ab9d6334055 (base origin/2.1)
  • The summary is in the PR description.

Tests run locally

  • unit · openmetadata-mcp (1 class): PatchEntityToolTest (46 passed)
  • integration · mysql-elasticsearch · parallel: DocStoreResourceIT (14 passed)

Broader coverage not executed by this focused run

  • mvn -B package -pl openmetadata-mcp,openmetadata-service -am -Dspring-boot.repackage.skip=true -Dtest=OpenMetadataSavedSparqlQueryDocumentRepositoryTest,PatchEntityToolTest -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel '-Dit.test=<61 classes>' -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=ContextMemoryDerivationIT,ContextMemoryExtractionIT,ContextMemoryExtractionRequestIT,ConversationSchemaMigrationIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
  • mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=rdf -Dit.test=AgentSparqlResourceIT,RdfMcpKnowledgeGraphIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false
Commands
mvn -B package -pl openmetadata-mcp -am -Dspring-boot.repackage.skip=true -Dtest=PatchEntityToolTest -Dsurefire.failIfNoSpecifiedTests=false
mvn -B verify -pl :openmetadata-integration-tests -am -Dspring-boot.repackage.skip=true -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=DocStoreResourceIT -Dfailsafe.failIfNoSpecifiedTests=false -Dtest=NoUnitTestsInThisRun -Dsurefire.failIfNoSpecifiedTests=false

Comment on lines +348 to +349
requireAdminForEmailTemplates(
securityContext, cd.getEntityType(), storedEntityType(cd.getFullyQualifiedName()));

@gitar-bot gitar-bot Bot Nov 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Quality: Two new docStore REST rules are not in any decision record

This PR changes how /v1/docStore behaves in two ways that the UI, SDKs and Collate have to agree with. No record in docs/decisions/ states either rule (the only docStore record is 2026-11-02-persona-layouts-are-readable-through-persona-assignment, which covers reads). The repo squash-merges, so the description is the only place these rules are written down, and they will be lost after merge.

The two rules are:

  1. From the description: "one helper, requireAdminForEmailTemplates, that every write endpoint calls". As a record: A Document whose entityType, requested or stored, is EmailTemplate can only be created, replaced, patched or deleted by an admin, on every docStore write endpoint, whatever Document permissions the caller has.
  2. From the description: "PATCH keeps a document's entityType, the same way it keeps the name and FQN". As a record: A JSON Patch to a Document never changes its entityType. DocumentRepository.restorePatchAttributes restores it, the patch still returns 200, and changing the type means a PUT authorized against both the old and the new type.

Rule 2 is a real contract change. A client that sends replace /entityType now gets a success response and the change is silently dropped. Rule 1 matters because the next person to add a write endpoint has to know to call the helper. The DocStoreResourceIT tests emailTemplatesAreManagedByAdminsOnly and documentPatchKeepsEntityType are the natural guards to name.

Add a record for the two rules (or one record each), name the ITs as guards, and cite it from the helper.:

/** Email templates are rendered into outgoing emails, so only admins manage them. ADR:2026-11-19-email-templates-are-admin-managed-and-patch-keeps-document-type */
private void requireAdminForEmailTemplates(
    SecurityContext securityContext, String... entityTypes) {

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 🔴 High risk 0 closed / 1 findings

Admin-only checks across email-template writes change authorization; a missed endpoint could let non-admins alter templates used in outgoing emails.

Moves email template write authorization into DocStoreResource via a single requireAdminForEmailTemplates helper called by every docStore write endpoint, and makes PATCH preserve a document's entityType. Changes requested: two new /v1/docStore behavior rules (admin-only EmailTemplate writes, and silent entityType retention on PATCH) are not captured in any decision record, and the PATCH rule is a contract change clients must know about. Add a decision record covering both rules before merge.

⚠️ Quality: Two new docStore REST rules are not in any decision record

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:348-349 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:409 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:522-528 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DocumentRepository.java:117-121

This PR changes how /v1/docStore behaves in two ways that the UI, SDKs and Collate have to agree with. No record in docs/decisions/ states either rule (the only docStore record is 2026-11-02-persona-layouts-are-readable-through-persona-assignment, which covers reads). The repo squash-merges, so the description is the only place these rules are written down, and they will be lost after merge.

The two rules are:

  1. From the description: "one helper, requireAdminForEmailTemplates, that every write endpoint calls". As a record: A Document whose entityType, requested or stored, is EmailTemplate can only be created, replaced, patched or deleted by an admin, on every docStore write endpoint, whatever Document permissions the caller has.
  2. From the description: "PATCH keeps a document's entityType, the same way it keeps the name and FQN". As a record: A JSON Patch to a Document never changes its entityType. DocumentRepository.restorePatchAttributes restores it, the patch still returns 200, and changing the type means a PUT authorized against both the old and the new type.

Rule 2 is a real contract change. A client that sends replace /entityType now gets a success response and the change is silently dropped. Rule 1 matters because the next person to add a write endpoint has to know to call the helper. The DocStoreResourceIT tests emailTemplatesAreManagedByAdminsOnly and documentPatchKeepsEntityType are the natural guards to name.

Add a record for the two rules (or one record each), name the ITs as guards, and cite it from the helper.
/** Email templates are rendered into outgoing emails, so only admins manage them. ADR:2026-11-19-email-templates-are-admin-managed-and-patch-keeps-document-type */
private void requireAdminForEmailTemplates(
    SecurityContext securityContext, String... entityTypes) {
🤖 Prompt for agents
Code Review: Moves email template write authorization into `DocStoreResource` via a single `requireAdminForEmailTemplates` helper called by every docStore write endpoint, and makes PATCH preserve a document's `entityType`. Changes requested: two new `/v1/docStore` behavior rules (admin-only EmailTemplate writes, and silent `entityType` retention on PATCH) are not captured in any decision record, and the PATCH rule is a contract change clients must know about. Add a decision record covering both rules before merge.

1. ⚠️ Quality: Two new docStore REST rules are not in any decision record
   Files: openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:348-349, openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:409, openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:522-528, openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/DocumentRepository.java:117-121

   This PR changes how `/v1/docStore` behaves in two ways that the UI, SDKs and Collate have to agree with. No record in `docs/decisions/` states either rule (the only docStore record is `2026-11-02-persona-layouts-are-readable-through-persona-assignment`, which covers reads). The repo squash-merges, so the description is the only place these rules are written down, and they will be lost after merge.
   
   The two rules are:
   1. From the description: "one helper, `requireAdminForEmailTemplates`, that every write endpoint calls". As a record: *A Document whose entityType, requested or stored, is `EmailTemplate` can only be created, replaced, patched or deleted by an admin, on every docStore write endpoint, whatever Document permissions the caller has.*
   2. From the description: "PATCH keeps a document's `entityType`, the same way it keeps the name and FQN". As a record: *A JSON Patch to a Document never changes its `entityType`. `DocumentRepository.restorePatchAttributes` restores it, the patch still returns 200, and changing the type means a PUT authorized against both the old and the new type.*
   
   Rule 2 is a real contract change. A client that sends `replace /entityType` now gets a success response and the change is silently dropped. Rule 1 matters because the next person to add a write endpoint has to know to call the helper. The `DocStoreResourceIT` tests `emailTemplatesAreManagedByAdminsOnly` and `documentPatchKeepsEntityType` are the natural guards to name.

   Fix (Add a record for the two rules (or one record each), name the ITs as guards, and cite it from the helper.):
   /** Email templates are rendered into outgoing emails, so only admins manage them. ADR:2026-11-19-email-templates-are-admin-managed-and-patch-keeps-document-type */
   private void requireAdminForEmailTemplates(
       SecurityContext securityContext, String... entityTypes) {

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

@manerow
manerow merged commit 4f1b897 into 2.1 Nov 19, 2026
44 of 46 checks passed
@manerow
manerow deleted the refactor/docstore-resource-authorization-2.1 branch November 19, 2026 15:44
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 skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant