Repository navigation
Fixes #36762: filter metric relation fields and memberships by viewer permission - #36764
Conversation
❌ PR checklist incompleteThis 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 |
Local Java test results (HEAD
|
06f08ec to
7f5947d
Compare
7f5947d to
a34c28c
Compare
A metric's relation fields (parent, children, childrenCount, relatedMetrics, metricGroup), a metric group's member list and metricCount, and the stored change descriptions that quote those references reached any caller who could view the carrying entity, without a ViewBasic check on the referenced entities. Three routes leaked the id, name, displayName and description of metrics and groups the caller was denied: the generic metric GET/list and write responses, the metric and metric group version histories, and the changeDescription / incrementalChangeDescription recorded on reparenting, regrouping and membership edits - the last one also inside the otherwise filtered hierarchy payloads. Apply the per-reference check the hierarchy endpoints already use to every Metric and MetricGroup response. MetricRepository.sanitizeMetricRelations filters the reference fields, recounts childrenCount with the visible children, and drops stored change entries for parent, relatedMetrics and metricGroup that name an entity the caller may not view; the group payloads go through MetricGroupRepository.sanitizeMembership, which filters members, recounts metricCount like the hierarchy endpoints, and drops membership change entries. Both resources resolve the caller permissions once per request, short-circuit on unconditional view, and cache per-entity decisions. Version histories are redacted through the existing snapshotRedaction hook, so unrestricted responses are unchanged. List pages recount the visible counts with one batched relationship query per page instead of a scan per row. The viewer-scoped rule and its consequences (restricted writers' change events carry only what the writer could see; relatedMetrics stays unvalidated at write time; /history endpoints stay unfiltered) are recorded in docs/decisions/2026-10-31-metric-and-metric-group-responses-hide- relations-the-viewer-cannot-see.md. Not changed: relatedMetrics is still accepted at write time without a check on the named metric, and the inherited /metrics/history and /metricGroups/history endpoints still lack a per-entity or domain filter.
098e3ea to
2060ed3
Compare
get_entity_details returns a metric's parent, children, related metrics and group, and a metric group's member count. Run them through the sanitizers the metric REST reads use, with the same ViewBasic check and unconditional-view short-circuit. Adds McpMetricRelationVisibilityIT.
There was a problem hiding this comment.
🟡 Changes recommended
Hidden-group references still leak through metric member listings and MCP write responses, and authorization failures can allow reference-bearing change entries without a successful permission check.
3 open issues
What changed in this PR
This PR addresses #36762 by applying per-reference ViewBasic checks to metric relations and metric-group memberships, extending the filtering already used by hierarchy endpoints.
Changes:
- Filters relation fields, counts, and stored change descriptions across REST responses and version histories.
- Adds metric relation filtering to MCP entity reads and batches count recalculation for list pages.
- Adds unit and integration coverage and records the visibility contract in a decision record.
| File | Description |
|---|---|
openmetadata-service/src/test/java/org/openmetadata/service/resources/metrics/MetricResourceTest.java |
Tests conditional read, PATCH, and snapshot sanitization. |
openmetadata-service/src/test/java/org/openmetadata/service/resources/metrics/MetricGroupResourceTest.java |
Tests membership sanitization in resource responses. |
openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/MetricRepositoryTest.java |
Tests relation filtering, stored changes, and visible child counts. |
openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/MetricGroupRepositoryTest.java |
Tests member filtering, batched counts, and scan limits. |
openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java |
Applies relation sanitizers to reads, writes, and snapshots. |
openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricGroupResource.java |
Applies membership sanitizers to reads, writes, and snapshots. |
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricRepository.java |
Filters metric references and changes; recalculates visible counts. |
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/MetricGroupRepository.java |
Filters memberships and changes; batches visible member counts. |
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/MetricRelationVisibility.java |
Adds permission-aware metric sanitization for MCP. |
openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/GetEntityTool.java |
Sanitizes metric relations before returning entity details. |
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/MetricResourceIT.java |
Extends restricted-reader coverage to reads, versions, and changes. |
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/mcp/McpMetricRelationVisibilityIT.java |
Tests hidden relations and visible counts through MCP reads. |
docs/decisions/2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see.md |
Records the visibility contract and deferred concerns. |
Review effort: Balanced
| MetricRelationVisibility.visibleTo( | ||
| CommonUtils.withVisibleEvidence( | ||
| CommonUtils.readEntityForCaller(entityType, fqn, "*", null, securityContext), | ||
| authorizer, | ||
| securityContext), |
| sanitizeRelationChanges(sanitized.getChangeDescription(), canViewMetric, canViewGroup); | ||
| sanitizeRelationChanges( | ||
| sanitized.getIncrementalChangeDescription(), canViewMetric, canViewGroup); |
Metric and metric group relations are filtered where every MCP tool builds the entity it answers with, so get, patch and create apply the same per-reference ViewBasic check. The group members list checks the groups its members' stored change entries name. Change-value parsing tolerates malformed payloads only; a failed visibility check propagates. Adds MCP patch and create regressions, a members-list regression for callers with conditional and unconditional metric access, and a unit test for a failing visibility check.
…fu-medium-cwe # Conflicts: # openmetadata-service/src/main/java/org/openmetadata/service/resources/metrics/MetricResource.java # openmetadata-service/src/test/java/org/openmetadata/service/resources/metrics/MetricResourceTest.java
Code Review ✅ Approved 4 closed / 4 findings🔴 High risk · Applying ViewBasic filtering to metric relations, memberships, and histories affects authorization-sensitive disclosure; faulty decisions could expose hidden entity details. Filters metric relation fields, group member lists, and stored change descriptions by the viewer's ViewBasic permission across metric and metric group reads, writes, version histories, and MCP entity details, so restricted callers no longer see hidden entity ids or names. Resolved the per-row child/member scan on generic list pages by batching the visible count recount per page and removed the per-group scan cap from the batch metricCount recount. No open issues remain; the change events permanently lacking relations from restricted writers is a disclosed accepted consequence tracked in the ADR. ✅ 4 closed✅ Performance: Generic list now runs a per-row child/member scan for restricted users
✅ Quality: Viewer-scoped relation and change-event rule is not recorded
✅ Performance: Batch metricCount recount drops the per-group scan cap
Closed: Bug: Sanitized write responses permanently strip relations from change events
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
There was a problem hiding this comment.
🟡 Changes recommended
A critical authorization bypass exposes hard-deleted related metrics’ stored names and descriptions through change and version history because missing-target resolution causes tag-based denials to stop matching.
3 open issues
Review effort: Balanced
| authorizer.authorize( | ||
| securityContext, | ||
| new OperationContext(reference.getType(), MetadataOperation.VIEW_BASIC), | ||
| new ResourceContext<>( | ||
| reference.getType(), reference.getId(), reference.getFullyQualifiedName())); |
|
#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.
…am PR open-metadata#36764 follow-up) (#154) * feat: port MetricRelationVisibility + MCP withVisibleEvidence (upstream PR open-metadata#36764 follow-up) * docs: add ADR record for Metric/MetricGroup relation visibility (2026-10-31) The two files ported in this PR cite ADR:2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see in their Javadoc, but the record did not exist in this repo, so the decision-records check in verify-rebuild failed with 2 problems. Add the record (the decision behind #153's REST read-path port, implemented here for the MCP path); the citation now resolves. * test(ui): use last-match for UsersListView overflow View item




Describe your changes:
Fixes #36762
A metric's relation fields (
parent,children,childrenCount,relatedMetrics,metricGroup), a metric group's member list andmetricCount, and the stored change descriptions that quote those references were returned to any caller who could view the carrying entity, without aViewBasiccheck on the referenced entities. A user deniedViewBasicon metrics or groups (e.g. via the shippedDomainOnlyAccessRole) could therefore read the id, name, display name and description of hidden entities through three routes: the generic metric reads and write responses, the metric and metric group version histories, and thechangeDescription/incrementalChangeDescriptionrecorded on reparenting, regrouping and membership edits — the last one also inside the otherwise filtered hierarchy payloads.relatedMetricshad no write-time check at all, so a restricted user could name a hidden metric there and read its description back.This PR applies the per-reference
ViewBasiccheck the hierarchy endpoints already use to everyMetricandMetricGroupresponse:MetricRepository.sanitizeMetricRelationsfilters the reference fields, recountschildrenCountwith the visible children, and drops stored change entries forparent,relatedMetricsandmetricGroupthat name an entity the caller may not view;sanitizeHierarchyMetric(used by the hierarchy endpoints and the members API) now also filterschildren/relatedMetricsand those change entries.MetricGroupRepository.sanitizeMembershipfilters themetricsmembers, drops membership change entries, and recountsmetricCountwithvisibleMetricCountlike the hierarchy endpoints; the group objects embedded in metric hierarchy payloads go through it.MetricResourceandMetricGroupResourcepasslist,get,getByNameand all write responses (POST/PUT/PATCH/delete/restore/vote) through these sanitizers, with thehasUnconditionalViewshort-circuit and per-request decision caching the hierarchy endpoints use. Version histories are redacted through the existingsnapshotRedactionhook, so callers with unconditional access get byte-identical responses.Behavior changes accepted: restricted callers see only viewable relations and counts;
listVersionsre-serializes versions through the POJO for those callers; change events caused by a restricted writer lack the relations that writer cannot see. Not changed:relatedMetricsis still accepted at write time without a check on the named metric (the link is stored but no longer readable back), and the inherited/metrics/historyand/metricGroups/historyendpoints still lack a per-entity or domain filter (a separate, broader issue).Type of change:
High-level design:
Approach: one sanitizer per entity type, applied at the resource boundary to every response that carries the entity, reusing the exact predicates and short-circuit the hierarchy endpoints established (
MetricResource.java:171hasUnconditionalView,canAccessEntitywithMetadataOperation.VIEW_BASIC).jdbi3/MetricRepository.java—sanitizeHierarchyMetricextended (filterschildren/relatedMetrics, strips invisible-quoting change entries); newsanitizeMetricRelationsrecountschildrenCountvia the existingvisibleChildCount;referencesOnlyVisibleEntitiesparses the JSON-encoded reference payloads stored inFieldChangevalues. The hierarchy loaders applyMetricGroupRepository.sanitizeMembershipto embedded group objects.jdbi3/MetricGroupRepository.java— newsanitizeMembership(member filter, membership-change filter,metricCountrecount via the existingvisibleMetricCount).resources/metrics/MetricResource.java/MetricGroupResource.java— per-requestRelationVisibility/MembershipVisibility(unconditional short-circuit + per-entity decision cache, shared asMetricResource.cachedDecisions); reads, writes and version snapshots (snapshotRedactionoverride) pass through the sanitizers; PATCH covered by overridingpatchInternal(id and fqn overloads), following the existingServiceEntityResourcepattern; group writes keep theirwithoutMembersstep on top. List pages recount the visiblechildrenCount/metricCountin one batched relationship query per page (sanitizeMetricRelations/sanitizeMembershiplist variants) so restricted callers don't pay a per-row scan.Alternatives considered: filtering inside
setFieldswas rejected because the repository layer has no caller context and the same loaded entity serves callers with different permissions; filtering only the REST reads was rejected because version snapshots bypass them. No migration or backward-compatibility concern: the gap exists only on the unreleased hierarchy commite4e88a41f268, and unrestricted callers see identical payloads.Tests:
Use cases covered
?fields=parent,children,childrenCount,relatedMetrics,metricGroupnow returns only viewable references, a visiblechildrenCount, and no hidden names anywhere in the payload.Unit tests
MetricRepositoryTest,MetricGroupRepositoryTest,MetricResourceTest,MetricGroupResourceTest(relation/membership filtering, change-entry parsing, count recounts, conditional vs unconditional resource paths,snapshotRedactionpresence/absence, PATCH response sanitization).MetricRepository30% (33% branches),MetricGroupRepository42% (40% branches),MetricResource46% (58% branches),MetricGroupResource68% (71% branches). The changed classes are large and mostly pre-existing; the new sanitizer methods (sanitizeMetricRelations,sanitizeMembership,referencesOnlyVisibleEntities, change filtering) and the conditional resource paths are exercised by the new unit tests, and the end-to-end routes by the integration test below.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.MetricResourceIT(extendedhierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReferencewith the generic reads, the version histories, and the change-description routes for metrics and groups).PASSED on
06f08ec8125(final HEAD).mvn -B package -pl openmetadata-service -Dtest=MetricGroupRepositoryTest,MetricGroupResourceTest,MetricObservabilityBuilderTest,MetricRepositoryTest,MetricResourceTest,PersonaContextBuilderTest: 126 tests, 0 failures. Amended commit re-run of the four metric classes: 79 tests, 0 failures.mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=ConfigResourceIT,DatabaseSmokeIT,GlossaryTermRelationUsageIT,GlossaryTermResourceIT,MetricAssetsIT,MetricGroupResourceIT,MetricResourceIT,QueryCostRecordResourceIT,QueryResourceIT,QueryVisibilityPolicyIT,SeedDataPresenceIT,TableResourceIT,UsageResourceIT,UserResourceIT: 1588 tests, 0 failures, 0 errors (108 skipped). IncludesMetricResourceITwith the extendedhierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReferenceand all ofMetricGroupResourceIT.MetricResourceIT#hierarchyEndpointsFilterAndSanitizeEveryRestrictedMetricReferencere-run on the amended HEAD: 1/1 passed.mvn -B verify -pl openmetadata-integration-tests -Pmysql-elasticsearch -DintegrationTests.lane=global-state -Dit.test=MetricMigrationIT,UserMetricsResourceIT: 11 tests, 0 failures.7f5947da2d4): unit — the four metric classes 81 tests, 0 failures; integration —MetricResourceIT,MetricGroupResourceITre-run against the new build (list paths now batch the visible count recount per page): 0 failures.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
The integration test above is the reproducer scenario, run locally against MySQL 8.3 + Elasticsearch 9.3 containers: a
DomainOnlyAccessRoleuser confined to Marketing is denied four Finance entities (403), sees none of them in the hierarchy response, and gets no hidden id/name/displayName/description from the genericfields=read, the version histories, or the change descriptions after an admin reparents a visible metric and shrinks a visible group.UI screen recording:
Not applicable — backend-only authorization fix, no UI impact.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.06f08ec8125(fresh-eyes subagent). 🟡 duplicated decision-cache predicate betweenMetricResourceandMetricGroupResource— fixed by sharingMetricResource.cachedDecisions.assetschange-description entries can likewise quote hidden data-asset references onPUT /metrics(MetricUpdater.linkRequestedAssets). Not filtered here by design: it is the separately tracked related finding of the same report, and its fix is write-side (linkRequestedAssets+MetricIndexstop recording assets in change descriptions and search documents), which a read-side filter in this PR would conflict with.docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge. — recorded asADR:2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see(docs/decisions/2026-10-31-metric-and-metric-group-responses-hide-relations-the-viewer-cannot-see.md), including the change-event consequence and therelatedMetricswrite-time gap as follow-ups.Bug fix
Summary by Gitar
get_entity_detailsnow filters metric relations and group member counts throughMetricRelationVisibilityMcpMetricRelationVisibilityITto verify restricted callers get no hidden relations via MCPThis will update automatically on new commits.