Skip to content

fix(mcp): run the metric write checks on mcp creates and patches - #36955

Merged
Vishnuujain merged 3 commits into
mainfrom
mcp-metric-checks
Nov 4, 2026
Merged

Vishnuujain merged 3 commits into
mainfrom
mcp-metric-checks

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36956

  • MCP create_entity and patch_entity skipped the checks the metric and metric group REST endpoints run on top of the policy check: EditAll on the metrics a move or group change touches and on the parent or group they land in, view access to the assets a new metric links, and the read-only metric fields.
  • Those checks now live in MetricAuthorization, which the REST create, PUT, PATCH and metric bulk endpoints and both MCP tools call. Metric CSV import still skips them, tracked in https://github.com/open-metadata/openmetadata-collate/issues/8228. Decision record: ADR:2026-11-03-metric-writes-run-the-same-checks-through-rest-and-mcp.
  • A whole-document replace patch on a metric now counts as a hierarchy change. It skipped the parent and group check on REST too. The checks also run on a copy loaded with the same fields the real patch uses, which fixes REST PATCH /v1/metricGroups/{id} with add /owners/- returning 400.

Behaviour change: an MCP write to a metric or group that REST refuses now gets the same 403. An MCP patch that sets a metric's assets, children or childrenCount is a 400 instead of being ignored.

Type of change:

  • Bug fix

Tests:

Unit tests

  • MetricResourceTest#wholeDocumentReplaceCountsAsAHierarchyChange. The existing MetricResourceTest / MetricGroupResourceTest cases now call the moved checks.

Backend integration tests

  • McpMetricAuthorizationIT: as a user who may edit everything except metrics tagged PII.Sensitive, patch_entity refuses moving a metric under, or adding to a group, a metric the user cannot edit, and create_entity refuses creating a metric or a group that would. Each case first does the allowed version, and all 4 fail before this change. A fifth case checks that appending an owner to a group, or to a metric while moving it, still works while the checks run.
  • MetricResourceIT#hierarchyWritesRequireEditPermissionOnParentAndGroupDestinations: a whole-document replace that sets a restricted parent is now 403. It returned 200 before this change.
  • MetricGroupResourceIT#patch_appendsAnOwnerThroughTheMembershipCheck: add /owners/- on a group succeeds. It returned 400 before this change.

Local Java test run: PASSED

  • Commit: 8af9d60ce1a2 (base origin/main)
  • Finished: 2026-11-03 13:29 UTC · 12.5 min
Step Scope Classes Tests Failed Skipped Min Result
unit openmetadata-mcp (2 classes), openmetadata-service (2 classes) 4 99 0 0 1.2 passed
integration mysql-elasticsearch · parallel 56 2910 0 226 5.7 passed
integration mysql-elasticsearch · isolated 5 23 0 0 2.6 passed
integration mysql-elasticsearch · rdf 2 43 0 0 3.0 passed

Checklist:

  • Self-review: I reviewed the final diff against REVIEW.md and fixed every 🔴 finding, or answered it on the line below.
    Reviewed 8af9d60ce1a. Not changed: a whole-document replace carrying assets, children or childrenCount is not refused, as on main, but none of them is written (assets links only on PUT, children is restored).
  • Decision check: ADR:2026-11-03-metric-writes-run-the-same-checks-through-rest-and-mcp.

@Vishnuujain
Vishnuujain requested a review from a team as a code owner November 3, 2026 13:34
@Vishnuujain
Vishnuujain requested a review from pmbrull November 3, 2026 13:34
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

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.

@Vishnuujain Vishnuujain added safe to test Add this label to run secure Github workflows on PRs Backward-Incompatible-Change labels Nov 3, 2026
@Vishnuujain Vishnuujain self-assigned this Nov 3, 2026
securityContext,
new OperationContext(entityType, jsonPatch),
new ResourceContext<>(entityType, null, fqn, ResourceContextInterface.Operation.PATCH));
MetricAuthorization.authorizePatch(authorizer, securityContext, entityType, fqn, jsonPatch);

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.

Design. PatchEntityTool and CreateEntityTool are type-blind, but they now call a metric class from the REST resources package by name (here and at CreateEntityTool.java:86). That has two costs:

  • A future resource-level write check has to be remembered here too, or its type added to DEDICATED_PATCH_LIFECYCLES / DEDICATED_CREATE_FLOWS.
  • The checks run on a separate copy of the entity, with the patch applied a second time. That copy is where the add /owners/- 400 came from.

Suggestion. There's already one place where checks like these run on every update: EntityRepository.admit(original, updated, actor, edit). Since ADR 2026-10-21-domain-moves-are-authorized-in-the-write-pipeline, it authorizes domain moves there with authorizer.authorizeActor, before the approval gate. PATCH (REST and this tool), PUT, bulk PUT and CSV import all go through it, using the original and updated entity that the write itself built.

A possible shape:

  • A protected void authorizeWrite(T original, T updated, ChangeActor actor) hook on EntityRepository, doing nothing by default. admit calls it right after the domain check, and skips system actors the way the domain check does.
  • MetricRepository and MetricGroupRepository override it with what MetricAuthorization checks today (the moved subtree and its destinations, membership changes, requested assets), through authorizeActor.
  • Create has no admit today, so createInternal calls the same hook with original == null.

With that in place, several things can go:

  • the calls in MetricResource, MetricGroupResource, CreateEntityTool and PatchEntityTool;
  • the copy-and-reapply step;
  • MCP's import of service.resources.metrics.

The read-only field check (assets, children, childrenCount) could move to the metric repository's patch path, so REST and MCP share it there too.

Two things are worth confirming first:

  • The original that reaches admit on the PUT and import paths carries parent, metricGroup and metrics. PATCH already loads them through the patch fields.
  • updated is already prepared at that point (parent resolved, group subtree expanded).

It deletes more code than it adds, so it might fit in this PR. A follow-up works too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, this is the better shape and it fixes the drift our ADR calls out. I'd keep this PR as is since it closes the gap now, and do the hook in a follow-up: it has to sit in authorizeDomainWrite (admit, previewPatch, the CSV batch and the bulk loop all call it) plus createInternal, and it overlaps with the metric CSV checks in #36792, so I'd rather sort that in one go. Both of your checks hold: PUT/import originals carry parent and metricGroup (and metrics for groups), and updated is prepared before admit.

Follow-up: #37030

@gitar-bot

gitar-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Adding EditAll checks to metric hierarchy and group writes changes authorization; users lacking access to affected metrics or destinations could have legitimate writes denied.

Moves the metric write checks (EditAll on touched metrics and destinations, asset view access, read-only field checks) into a shared MetricAuthorization so MCP create_entity and patch_entity enforce the same rules as the REST metric and metric group endpoints. Whole-document replace patches on metrics now count as hierarchy changes, and group add /owners/- no longer returns 400. 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

@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@Vishnuujain
Vishnuujain merged commit 62e4e0a into main Nov 4, 2026
66 of 71 checks passed
sonika-shah added a commit that referenced this pull request Nov 4, 2026
Resolves the conflict with #36955, which moved the metric and metric group
write checks into MetricAuthorization for REST and MCP:

- MetricAuthorization now rejects document-root metric patches, refuses a
  copy, move or test that reads a relation field into another field, requires
  view on every member for a group patch that addresses members, and masks
  JSON-P errors on group patches.
- The REST resources still authorize the patch before simulating it, and the
  group member pin with its 412 stays in MetricGroupResource.
- MCP patch_entity no longer refuses metric hierarchy and membership changes;
  it runs the same checks through MetricAuthorization.
manerow pushed a commit that referenced this pull request Nov 5, 2026
#37110)

MetricGroupResource.patch now loads the stored group with repository.get before
authorizing the patch (#36955). The test added in #36764 only stubbed
getWithMembers, so get returned null and applyPatch failed with
"Expected a JSON object or array", failing openmetadata-service unit tests on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backward-Incompatible-Change 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.

MCP create_entity and patch_entity skip the metric write checks

2 participants