Skip to content

Authorize Document Store writes in one place - #38196

Merged
manerow merged 2 commits into
mainfrom
refactor/docstore-resource-authorization
Nov 19, 2026
Merged

manerow merged 2 commits into
mainfrom
refactor/docstore-resource-authorization

Conversation

@manerow

@manerow manerow commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

No linked issue.

I moved the email template authorization in the Document Store into DocStoreResource, so that it sits with the other per-entity checks in the resource layer (as in PersonaResource), instead of inside the mapper.

  • DocStoreResource has one helper, requireAdminForEmailTemplates, and every write endpoint calls it.
  • DocStoreMapper only converts the request and validates the template content.
  • DocumentRepository.restorePatchAttributes keeps a document's entityType on PATCH, the same way PATCH already keeps the name and FQN.
  • The comment in PatchEntityTool that explains why document has its own patch flow now names the email template check too.

Other document types (knowledge panels, persona pages) behave as before.

Type of change:

  • Improvement

High-level design:

N/A, small change in one resource, its mapper and its repository.

Tests:

Use cases covered

  • Email templates keep the same authorization on every Document Store write endpoint.
  • A user with Document permissions can create, edit and delete other document types.
  • PATCH keeps a document's entityType.

Unit tests

Not added. The change is an HTTP authorization rule, so it is covered end to end by DocStoreResourceIT instead of a unit test that mocks the authorizer.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for the changed endpoints.
  • Files updated: DocStoreResourceIT (2 new tests).

Local Java test run: PASSED

  • Commit: 633d9c514aa3 (base origin/main)
  • Finished: 2026-11-19 09:17 UTC · 4.1 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.2 passed
integration mysql-elasticsearch · parallel 1 14 0 0 2.9 passed

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes). The UI's document PATCH (persona customization) never sends entityType.

Visual regression baselines

  • Not applicable (no rendering change).

Manual testing performed

Not applicable: backend-only, covered by DocStoreResourceIT.

UI screen recording:

Not applicable: backend-only change.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>. No linked issue for this PR.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above. No linked issue for this PR.
  • 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, backend-only.
  • 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.
    • c32a50dc477: reviewed with fresh eyes, no 🔴. One 🟡 on the test fixed in 633d9c514aa (the test editor now creates and deletes its own panel), which I reviewed myself.
  • Decision check: no record needed. Email templates were already admin-managed; this keeps that rule in one place.

RetriggerView in GreptileConfidence Score: 4/5

Add fixture cleanup before merging to meet the repository's test requirements.

Findings

  1. P2 Test accounts never get deleted ▶

Summary

This PR moves email-template write checks into DocStoreResource and keeps a document's entityType unchanged during PATCH.

  • Email-template writes require admins across the Document Store.
  • PATCH keeps each document’s original type.

Reviews (1) · Last reviewed commit: "Let the docstore test editor create and ..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner November 19, 2026 09:18
@manerow manerow added safe to test Add this label to run secure Github workflows on PRs backend skip-pr-checks Bypass PR metadata validation check labels Nov 19, 2026
@manerow
manerow requested a review from pmbrull November 19, 2026 09:18
@manerow

manerow commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Local Java test run: PASSED — details

  • Commit: 633d9c514aa3 (base origin/main)
  • 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=<62 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

@Context SecurityContext securityContext,
@Valid CreateDocument cd) {
PrivateDocumentType.requirePublic(cd.getEntityType());
requireAdminForEmailTemplates(securityContext, cd.getEntityType());

@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: New email-template auth and entityType-immutability rules lack a record

The description calls this a move of an existing check, but the diff adds two authorization rules. The old DocStoreMapper check only ran in createToEntity (POST/PUT), so PATCH and DELETE on an EmailTemplate used to need nothing beyond normal Document permissions. Now all three DELETE endpoints and both PATCH endpoints call authorizeAdmin, and DocumentRepository.restorePatchAttributes stops any caller, admins included, from changing entityType through PATCH. Without that second rule, a non-admin editor could retype a panel into an email template, so the first rule depends on it. No record in docs/decisions/ states either rule; the only docStore record is about persona layouts. The PR body says "Email templates keep the same admin-only authorization on every Document Store write endpoint" and "PATCH keeps a document's entityType", and the repo squash-merges, so that text won't reach git log. A record would say: "Only admins create, replace, patch or delete a Document whose stored or requested entityType is EmailTemplate, on every docStore write endpoint. A PATCH never changes a Document's entityType, so an edit cannot move a document into or out of the admin-only type." It would be guarded by DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly and #documentPatchKeepsEntityType.

Add a decision record stating both rules:

# Email templates are managed by admins and a patch keeps a document's type

- **Status:** Accepted
- **Guard:** DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly, DocStoreResourceIT#documentPatchKeepsEntityType

## Decision
- Every docStore write (POST, PUT, PATCH, DELETE, async DELETE) needs an admin when the requested or stored entityType is EmailTemplate.
- A PATCH never changes a Document's entityType (DocumentRepository.restorePatchAttributes).

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

Moving email-template admin authorization to DocStoreResource changes who may write templates; a bypass could alter content used in outgoing emails.

Moves the email template admin check from DocStoreMapper into DocStoreResource and blocks PATCH from changing a document's entityType in DocumentRepository. Changes requested: the new admin-only rule now also covers PATCH and DELETE, and the entityType immutability rule and the admin-only email template rule have no decision record in docs/decisions/, which should be added and linked to DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly and #documentPatchKeepsEntityType.

⚠️ Quality: New email-template auth and entityType-immutability rules lack a record

📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:323 📄 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:439 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:459 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:479 📄 openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:501 📄 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

The description calls this a move of an existing check, but the diff adds two authorization rules. The old DocStoreMapper check only ran in createToEntity (POST/PUT), so PATCH and DELETE on an EmailTemplate used to need nothing beyond normal Document permissions. Now all three DELETE endpoints and both PATCH endpoints call authorizeAdmin, and DocumentRepository.restorePatchAttributes stops any caller, admins included, from changing entityType through PATCH. Without that second rule, a non-admin editor could retype a panel into an email template, so the first rule depends on it. No record in docs/decisions/ states either rule; the only docStore record is about persona layouts. The PR body says "Email templates keep the same admin-only authorization on every Document Store write endpoint" and "PATCH keeps a document's entityType", and the repo squash-merges, so that text won't reach git log. A record would say: "Only admins create, replace, patch or delete a Document whose stored or requested entityType is EmailTemplate, on every docStore write endpoint. A PATCH never changes a Document's entityType, so an edit cannot move a document into or out of the admin-only type." It would be guarded by DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly and #documentPatchKeepsEntityType.

Add a decision record stating both rules
# Email templates are managed by admins and a patch keeps a document's type

- **Status:** Accepted
- **Guard:** DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly, DocStoreResourceIT#documentPatchKeepsEntityType

## Decision
- Every docStore write (POST, PUT, PATCH, DELETE, async DELETE) needs an admin when the requested or stored entityType is EmailTemplate.
- A PATCH never changes a Document's entityType (DocumentRepository.restorePatchAttributes).
🤖 Prompt for agents
Code Review: Moves the email template admin check from `DocStoreMapper` into `DocStoreResource` and blocks PATCH from changing a document's `entityType` in `DocumentRepository`. Changes requested: the new admin-only rule now also covers PATCH and DELETE, and the `entityType` immutability rule and the admin-only email template rule have no decision record in `docs/decisions/`, which should be added and linked to `DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly` and `#documentPatchKeepsEntityType`.

1. ⚠️ Quality: New email-template auth and entityType-immutability rules lack a record
   Files: openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:323, 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:439, openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:459, openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:479, openmetadata-service/src/main/java/org/openmetadata/service/resources/docstore/DocStoreResource.java:501, 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

   The description calls this a move of an existing check, but the diff adds two authorization rules. The old `DocStoreMapper` check only ran in `createToEntity` (POST/PUT), so PATCH and DELETE on an `EmailTemplate` used to need nothing beyond normal Document permissions. Now all three DELETE endpoints and both PATCH endpoints call `authorizeAdmin`, and `DocumentRepository.restorePatchAttributes` stops any caller, admins included, from changing `entityType` through PATCH. Without that second rule, a non-admin editor could retype a panel into an email template, so the first rule depends on it. No record in `docs/decisions/` states either rule; the only docStore record is about persona layouts. The PR body says "Email templates keep the same admin-only authorization on every Document Store write endpoint" and "PATCH keeps a document's entityType", and the repo squash-merges, so that text won't reach `git log`. A record would say: "Only admins create, replace, patch or delete a Document whose stored or requested entityType is EmailTemplate, on every docStore write endpoint. A PATCH never changes a Document's entityType, so an edit cannot move a document into or out of the admin-only type." It would be guarded by `DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly` and `#documentPatchKeepsEntityType`.

   Fix (Add a decision record stating both rules):
   # Email templates are managed by admins and a patch keeps a document's type
   
   - **Status:** Accepted
   - **Guard:** DocStoreResourceIT#emailTemplatesAreManagedByAdminsOnly, DocStoreResourceIT#documentPatchKeepsEntityType
   
   ## Decision
   - Every docStore write (POST, PUT, PATCH, DELETE, async DELETE) needs an admin when the requested or stored entityType is EmailTemplate.
   - A PATCH never changes a Document's entityType (DocumentRepository.restorePatchAttributes).

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

Comment on lines +567 to +568
User user = admin.users().create(createUser);
return SdkClients.createClient(user.getName(), user.getEmail(), new String[] {});

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.

P2 Test accounts never get deleted. documentEditor creates a policy, role, and user for each call but never registers them for cleanup. Both new tests call it, so every run leaves six entities on a shared test server, including when later setup fails. The repository review guide requires cleanup for fallible fixture creation. Pass TestNamespace into this helper and register each created entity with trackRoot, or delete them in a failure-safe cleanup block.

Context Used: CLAUDE.md (source)

@manerow
manerow merged commit af85b89 into main Nov 19, 2026
61 checks passed
@manerow
manerow deleted the refactor/docstore-resource-authorization branch November 19, 2026 09:53
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.

2 participants