Skip to content

Fixes #29999: Propagate active persona request context - #30000

Merged
pmbrull merged 4 commits into
mainfrom
harshach/persona-subject-context
Jul 14, 2026
Merged

pmbrull merged 4 commits into
mainfrom
harshach/persona-subject-context

Conversation

@harshach

@harshach harshach commented Jul 13, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #29999

Propagates the UI-selected persona ID on every API request and carries it through authentication into a lazily validated SubjectContext, using cached direct, inherited, and default persona references with default fallback and no per-request header lookup.
AI persona context and membership checks now consume cached subject data, persona mutations invalidate only affected user-context entries where possible, and invalid header logging is sanitized and bounded.
In-server MCP tool execution now preserves the incoming CatalogSecurityContext; this carries the active persona and, as a correctness change, also propagates impersonatedUser so impersonated MCP calls receive the normal impersonation authorization checks.

Type of change:

  • Bug fix
  • Improvement
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation

High-level design:

  • selectedPersona.id → X-OpenMetadata-Persona Axios interceptor → authentication filters
  • Canonical CatalogSecurityContext field plus a request-scoped ThreadLocal fallback for wrapped Jersey contexts
  • Lazy in-memory validation in SubjectContext against the 15-minute cached direct, inherited, and default personas
  • Persona preference explicitly excluded from RBAC/policy inputs; invalid or stale selections fall back to the default
  • Targeted persona cache invalidation that leaves the hot two-minute policy cache warm
  • AI context and in-server MCP tools consume the validated request persona

Tests:

Use cases covered

  • Persona selection by UUID, name, and FQN
  • Missing, stale, unassigned, inherited, and default persona behavior
  • Persona assignment/revocation cache invalidation
  • Combined impersonation and active-persona requests
  • Header transport without entity/database interaction
  • Control-character and length sanitization for fallback logging

Unit tests

  • Added backend tests in JwtFilterTest, SubjectContextTest, SubjectCacheTest, DefaultAuthorizerTest, and ImpersonationCleanupFilterTest
  • Added UI interceptor tests in withActivePersonaHeader.test.ts (2/2 passing)
  • Backend focused suite: 57 tests passing
  • UI ESLint, Prettier, organize-imports, and TypeScript checks passing
  • Coverage percentage: not measured

Backend integration tests

  • Added ActivePersonaHeaderIT
  • Integration test sources compile successfully
  • Runtime execution not performed because the local Docker daemon is unavailable

Ingestion integration tests

  • Not applicable (no ingestion changes)

Playwright (UI) tests

  • Not applicable (request-interceptor behavior only; no visual workflow change)

Manual testing performed

Not performed because the local Docker-backed stack is unavailable

UI screen recording / screenshots:

Not applicable — this changes request headers only and has no visual UI changes

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable; this PR does not change JSON Schema.
  • For UI changes: I attached a screen recording and/or screenshots above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

Improvement checklist

  • I have added tests around the new logic.
  • For connector/ingestion changes: not applicable.

Greptile Summary

This PR carries the selected persona through requests and server-side subject context. The main changes are:

  • Adds a UI Axios helper for the active persona header.
  • Stores active persona and impersonation hints in CatalogSecurityContext.
  • Resolves active personas from cached subject data.
  • Invalidates affected subject-context cache entries after persona changes.
  • Preserves request context during in-server MCP tool execution.
  • Adds backend, integration, and UI tests for the new persona flow.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java Adds subject-context cache invalidation for persona create, delete, default, and direct user assignment changes.
openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectCache.java Adds persona-aware user-context cache fields and targeted invalidation helpers.
openmetadata-service/src/main/java/org/openmetadata/service/mcpclient/McpClientService.java Preserves existing catalog contexts and copies request hints when wrapping MCP security contexts.
openmetadata-service/src/main/java/org/openmetadata/service/security/policyevaluator/SubjectContext.java Adds active-persona selection and persona membership checks from cached subject data.
openmetadata-ui/src/main/resources/ui/src/hoc/withActivePersonaHeader.ts Adds the selected persona ID to outgoing API requests.

Comments Outside Diff (2)

  1. openmetadata-service/src/main/java/org/openmetadata/service/mcpclient/McpClientService.java, line 568-572 (link)

    P1 security Wrapped MCP Context Drops Hints

    When Jersey passes a wrapped SecurityContext, this fallback builds a new CatalogSecurityContext without the request persona or impersonated user. Tool authorization then sees a CatalogSecurityContext and skips the ThreadLocal fallback, so wrapped MCP calls can run with the wrong persona context and without the normal impersonation checks.

  2. openmetadata-service/src/main/java/org/openmetadata/service/mcpclient/McpClientService.java, line 568-572 (link)

    P1 security Wrapped Context Loses Hints

    When MCP receives a wrapped SecurityContext, this fallback creates a new CatalogSecurityContext with no impersonatedUser or activePersona. Downstream authorization then sees a CatalogSecurityContext and reads those null fields directly, so it never uses the request-scoped fallbacks that were set by the filters. A wrapped impersonated MCP request can therefore execute tool authorization without the normal impersonation check and without the selected persona.

Reviews (4): Last reviewed commit: "Preserve security hints in wrapped MCP c..." | Re-trigger Greptile

Context used (3)

  • Context used - CLAUDE.md (source)
  • Context used - openmetadata-ui-core-components/CLAUDE.md (source)
  • Context used - AGENTS.md (source)

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jul 13, 2026
@harshach
harshach marked this pull request as ready for review July 13, 2026 17:02
@harshach
harshach requested a review from a team as a code owner July 13, 2026 17:02
Copilot AI review requested due to automatic review settings July 13, 2026 17:02

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

Jest test Coverage

UI tests summary

Lines Statements Branches Functions
Coverage: 64%
64.47% (75233/116682) 48.37% (44821/92651) 49.07% (13550/27610)

Copilot AI review requested due to automatic review settings July 13, 2026 17:35

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (36 flaky)

✅ 4500 passed · ❌ 0 failed · 🟡 36 flaky · ⏭️ 96 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 420 0 7 16
✅ Shard 2 11 0 0 0
🟡 Shard 3 816 0 11 9
🟡 Shard 4 819 0 1 18
🟡 Shard 5 825 0 4 5
🟡 Shard 6 829 0 4 46
🟡 Shard 7 780 0 9 2
🟡 36 flaky test(s) (passed on retry)
  • Features/CustomizeDetailPage.spec.ts › Table - customization should work (shard 1, 1 retry)
  • Flow/TestConnectionModal.spec.ts › modal opens with gate card and capability checks sections (shard 1, 1 retry)
  • Pages/Lineage/LineageRightPanel.spec.ts › Verify custom properties tab IS visible for supported type: metric (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › User without permission (shard 1, 2 retries)
  • Flow/SearchRBAC.spec.ts › User without permission (shard 1, 1 retry)
  • Flow/SearchRBAC.spec.ts › a fully denied user sees neither asset type when browsing (shard 1, 2 retries)
  • Flow/SearchRBAC.spec.ts › the browse tree only shows the asset-type categories a user can access (shard 1, 1 retry)
  • Features/BulkEditEntity.spec.ts › Glossary (shard 3, 1 retry)
  • Features/BulkEditEntity.spec.ts › Glossary Term (Nested) (shard 3, 1 retry)
  • Features/BulkImportWithDotInName.spec.ts › Full import cycle with dot in service name (shard 3, 1 retry)
  • Features/ColumnBulkOperations.spec.ts › should show column count for multiple column selection (shard 3, 1 retry)
  • Features/ContextCenterArchivePage.spec.ts › archive page lazy-loads more rows on scroll within its own scroll container (shard 3, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Article listing search filters, clears, and shows empty state (shard 3, 2 retries)
  • Features/ContextCenterArticles.spec.ts › Article list cards, recently viewed widget, and pagination work (shard 3, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Text formatting (shard 3, 1 retry)
  • Features/ContextCenterMemories.spec.ts › clicking a memory row adds ?memory= param to the URL (shard 3, 1 retry)
  • Features/ContextCenterPermission.spec.ts › user with deleteAll permission can see delete action but not restore action on an archived document, and can delete it (shard 3, 1 retry)
  • Features/Glossary/GlossaryAdvancedOperations.spec.ts › should remove domain from glossary (shard 3, 1 retry)
  • Features/SearchExport.spec.ts › Export queues a background job and downloads from the jobs tray (shard 4, 1 retry)
  • Flow/ExploreDiscovery.spec.ts › Should not display soft deleted assets in search suggestions (shard 5, 1 retry)
  • Flow/PersonaFlow.spec.ts › Set default persona for team should work properly (shard 5, 1 retry)
  • Pages/CustomProperties.spec.ts › Integer (shard 5, 1 retry)
  • Pages/DataContracts.spec.ts › Create Data Contract and validate for Spreadsheet (shard 5, 1 retry)
  • Pages/EntityDataConsumer.spec.ts › Tier Add, Update and Remove (shard 6, 1 retry)
  • Pages/ExploreBrowse.spec.ts › service type drill-down disables unrelated roots and query-panel Clear resets it (shard 6, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 6, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should perform CRUD and Removal operations for searchIndex (shard 6, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should allow Data Steward to edit glossary terms for dashboardDataModel (shard 7, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Glossary Bulk Import Export (shard 7, 1 retry)
  • Pages/GlossaryImportExport.spec.ts › Import partial success - some terms pass, some fail (shard 7, 1 retry)
  • ... and 6 more

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

Copilot AI review requested due to automatic review settings July 13, 2026 20:11

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 13, 2026 23:05

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Implements active persona propagation via API request headers and cached subject context, ensuring consistent authorization across the backend and MCP tools. Persona cache invalidation and user-context aggregation have been successfully resolved.

✅ 2 resolved
✅ Edge Case: Persona cache invalidation silently skips refs without name

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:366-378 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:291-298 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:340-348
invalidateUserContexts maps EntityReference::getName and filters out null/empty names, but SubjectCache user-context entries are keyed by username. User references sourced from an update/patch payload (or relationship lookups) may carry only id and no name; those users are then silently skipped, leaving their cached user context (personas/defaultPersona) stale for up to the 15-minute TTL. The integration test only exercises the fully-hydrated case (user.getEntityReference()). Consider resolving the username from the id before invalidating, or falling back to invalidateAllUserContexts() when any reference lacks a name.

✅ Quality: Duplicate affected-user aggregation in updateUsers

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:362-367 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:403-407
The inline block in updateUsers builds the combined origUsers+updatedUsers list exactly as the existing private helper invalidateUserContexts(originalUsers, updatedUsers) already does. Reusing the helper (e.g. deferReactOperation(() -> invalidateUserContexts(origUsers, updatedUsers))) removes the duplication and keeps a single source of truth for how affected users are computed.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@pmbrull
pmbrull merged commit cb1889f into main Jul 14, 2026
65 of 70 checks passed
@pmbrull
pmbrull deleted the harshach/persona-subject-context branch July 14, 2026 05:58
@gitar-bot

gitar-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Implements active persona propagation via API request headers and cached subject context, ensuring consistent authorization across the backend and MCP tools. Persona cache invalidation and user-context aggregation have been successfully resolved.

✅ 2 resolved
✅ Edge Case: Persona cache invalidation silently skips refs without name

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:366-378 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:291-298 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:340-348
invalidateUserContexts maps EntityReference::getName and filters out null/empty names, but SubjectCache user-context entries are keyed by username. User references sourced from an update/patch payload (or relationship lookups) may carry only id and no name; those users are then silently skipped, leaving their cached user context (personas/defaultPersona) stale for up to the 15-minute TTL. The integration test only exercises the fully-hydrated case (user.getEntityReference()). Consider resolving the username from the id before invalidating, or falling back to invalidateAllUserContexts() when any reference lacks a name.

✅ Quality: Duplicate affected-user aggregation in updateUsers

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:362-367 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/PersonaRepository.java:403-407
The inline block in updateUsers builds the combined origUsers+updatedUsers list exactly as the existing private helper invalidateUserContexts(originalUsers, updatedUsers) already does. Reusing the helper (e.g. deferReactOperation(() -> invalidateUserContexts(origUsers, updatedUsers))) removes the duplication and keeps a single source of truth for how affected users are computed.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch was previously deployed

1 inactive deployment
test — 57c18dcf Deployed Jul 13, 2026 by harshach via playwright-ci-postgresql (4, 7) #56243
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Propagate selected persona through request context

3 participants