Skip to content

[2.0] Authorize Document Store writes in one place (backport 2.0 #38196) - #38204

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

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

Conversation

@manerow

@manerow manerow commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Backport of #38196 to 2.0. 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 did not apply cleanly, because 2.0 does not have the private document types that main checks in the same methods. So this is a port, not a copy:

  • Same as Authorize Document Store writes in one place #38196: DocStoreMapper, DocumentRepository, the PatchEntityTool comment and DocStoreResourceIT.
  • Ported: DocStoreResource looks the stored document up with two small helpers instead of main's private-type guard.
  • Added to match main: resetEmailTemplate checks for an admin, as it does on main, with one assertion for it in DocStoreResourceIT.

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

UI screen recording:

Not applicable: backend-only change.

Checklist:

RetriggerView in GreptileConfidence Score: 4/5

Meet the repository’s Java requirements before merging; test-record cleanup is also worth fixing.

Findings

  1. P2 Test accounts are never removed ▶
  2. P2 Test setup is too large ▶
  3. P2 Unchanged bindings lack `final` ▶
  4. P2 Template type constant is duplicated ▶
  5. P2 Helper names omit actions ▶

Summary

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

  • Every email-template write path now checks for an admin.
  • Document patches keep each document’s original type.

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

@manerow
manerow requested a review from a team as a code owner November 19, 2026 10:12
@manerow
manerow requested review from IceS2 and removed request for a team November 19, 2026 10:12
@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
@gitar-bot

gitar-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk

Admin-only enforcement across email-template writes and resets changes authorization; absent checks, document editors could alter templates used in outgoing emails.

Ports the email template write authorization into DocStoreResource via a single requireAdminForEmailTemplates helper, with DocStoreMapper limited to request conversion and template validation, and PATCH preserving entityType. 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

Comment on lines +564 to +569
CreateUser createUser = new CreateUser();
createUser.setName(prefix + "_user");
createUser.setEmail(prefix + "[email protected]");
createUser.setRoles(List.of(role.getId()));
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 are never removed. Each call to documentEditor creates a policy, role, and user without arranging cleanup. Both new tests leave these records behind, so repeated runs grow the shared test cluster. Add cleanup for all three records, including when setup or assertions fail; NamespaceCleanup currently has no mapping for policies or roles.

Comment on lines +536 to +548
private static OpenMetadataClient documentEditor(String prefix) {
OpenMetadataClient admin = SdkClients.adminClient();
Rule rule =
new Rule()
.withName(prefix + "_edit")
.withResources(List.of(Entity.DOCUMENT))
.withOperations(
List.of(
MetadataOperation.CREATE,
MetadataOperation.EDIT_ALL,
MetadataOperation.DELETE,
MetadataOperation.VIEW_ALL))
.withEffect(Rule.Effect.ALLOW);

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 setup is too large. documentEditor builds a rule, policy, role, user, and client in one long method. The repository guide requires small, focused methods and asks for about 15 lines or fewer. Extract the policy and account setup into named helpers. The two added test methods also exceed that guidance.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +499 to +500
private String storedEntityType(String fullyQualifiedName) {
Document stored = repository.findByNameOrNull(fullyQualifiedName, Include.ALL);

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 Unchanged bindings lack final. The new helper parameters and local variables are never reassigned but omit final. The repository guide requires final on local variables and parameters that do not change. Apply it here and throughout the added helpers and tests.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

private static final ObjectMapper MAPPER =
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private static final String EMAIL_TEMPLATE_NAME = "testMail";
private static final String EMAIL_TEMPLATE = "EmailTemplate";

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 Template type constant is duplicated. EMAIL_TEMPLATE repeats the existing DefaultTemplateProvider.ENTITY_TYPE_EMAIL_TEMPLATE value. The repository guide requires one definition per constant across classes. Reuse the existing constant instead of adding another definition.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +495 to +499
private String storedEntityType(UUID id) {
return repository.find(id, Include.ALL).getEntityType();
}

private String storedEntityType(String fullyQualifiedName) {

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 Helper names omit actions. The new storedEntityType helpers use noun phrases, while the repository guide requires method names to be verb phrases. Rename them to getStoredEntityType or another action name. The new documentEditor factory should likewise use an action name such as createDocumentEditor.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@manerow
manerow merged commit 79cf4bc into 2.0 Nov 19, 2026
81 of 90 checks passed
@manerow
manerow deleted the refactor/docstore-resource-authorization-2.0 branch November 19, 2026 15:35
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