Skip to content

Fix Bearer session access tracking - #28839

Merged
ShaileshParmar11 merged 3 commits into
mainfrom
harshach/bearer-session-401
Jun 9, 2026
Merged

ShaileshParmar11 merged 3 commits into
mainfrom
harshach/bearer-session-401

Conversation

@harshach

@harshach harshach commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Related to #26314

Updates session-bound Bearer-token validation to record successful session access so actively used saved tokens are not evicted as stale by the per-user session cap. The persisted access refresh is throttled to at most once every five minutes per session, while still refreshing when the recorded access is stale or idle expiry is near.

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:

N/A - small bug fix.

Tests:

Use cases covered

  • Saved session-bound Bearer token remains recently used when validated successfully.
  • Per-user session cap evicts the least recently accessed session instead of an actively used Bearer-token session.
  • Recently recorded session access skips a store write, while near-idle-expiry access still refreshes the session.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated: JwtFilterTest, SessionServiceTest
  • Coverage %: Not measured.

Backend integration tests

  • Not applicable (no backend API changes).

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • mvn -pl openmetadata-service spotless:apply
  • mvn -pl openmetadata-service -Dtest=org.openmetadata.service.security.JwtFilterTest,org.openmetadata.service.security.session.SessionServiceTest test

UI screen recording / screenshots:

Not applicable.

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: I updated the migration scripts or explained why it is not needed.
  • 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.

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Jun 9, 2026
@harshach
harshach marked this pull request as ready for review June 9, 2026 04:58
@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

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

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

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.

@harshach harshach added the skip-pr-checks Bypass PR metadata validation check label Jun 9, 2026
@harshach
harshach force-pushed the harshach/bearer-session-401 branch from c88ffed to 974c35b Compare June 9, 2026 05:05
@harshach
harshach marked this pull request as draft June 9, 2026 05:05
@harshach
harshach force-pushed the harshach/bearer-session-401 branch from 974c35b to 2ec5408 Compare June 9, 2026 05:10
@github-actions

github-actions Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

🟡 Playwright Results — all passed (12 flaky)

✅ 4272 passed · ❌ 0 failed · 🟡 12 flaky · ⏭️ 88 skipped

Shard Passed Failed Flaky Skipped
🟡 Shard 1 300 0 1 4
✅ Shard 2 806 0 0 9
🟡 Shard 3 804 0 4 8
🟡 Shard 4 841 0 2 12
🟡 Shard 5 719 0 2 47
🟡 Shard 6 802 0 3 8
🟡 12 flaky test(s) (passed on retry)
  • Features/CustomizeDetailPage.spec.ts › Container - customization should work (shard 1, 1 retry)
  • Features/KnowledgeCenterTextEditor.spec.ts › Rich Text Editor - Text Formatting (shard 3, 1 retry)
  • Features/RTL.spec.ts › Verify Following widget functionality (shard 3, 1 retry)
  • Features/Tasks/TaskNavigation.spec.ts › navigating to /table/TASK-XXXXX should show 404 (invalid URL pattern) (shard 3, 1 retry)
  • Features/Workflows/WorkflowOssRestrictions.spec.ts › schedule-type-select is disabled in OSS (shard 3, 1 retry)
  • Pages/CustomProperties.spec.ts › Should verify property name is visible for apiCollection in right panel (shard 4, 1 retry)
  • Pages/DataContracts.spec.ts › Contract Status badge should be visible on condition if Contract Tab is present/hidden by Persona (shard 4, 1 retry)
  • Pages/Entity.spec.ts › Tier Add, Update and Remove (shard 5, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard 5, 1 retry)
  • Pages/Glossary.spec.ts › Column dropdown drag-and-drop functionality for Glossary Terms table (shard 6, 1 retry)
  • Pages/Lineage/LineageFilters.spec.ts › Verify lineage schema filter selection (shard 6, 1 retry)
  • Pages/Lineage/PlatformLineage.spec.ts › Verify domain platform view (shard 6, 1 retry)

📦 Download artifacts

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

chirag-madlani
chirag-madlani previously approved these changes Jun 9, 2026

@mohityadav766 mohityadav766 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

needs changes on JwtFilter

mohityadav766 and others added 2 commits June 9, 2026 14:59
…ilter

Co-authored-by: Sriharsha Chintalapani <38649+harshach@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jun 9, 2026

Copy link
Copy Markdown

@ShaileshParmar11
ShaileshParmar11 merged commit 1a0bd90 into main Jun 9, 2026
53 of 54 checks passed
@ShaileshParmar11
ShaileshParmar11 deleted the harshach/bearer-session-401 branch June 9, 2026 12:01
@gitar-bot

gitar-bot Bot commented Jun 9, 2026

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

Updates Bearer session validation to include throttled access tracking, resolving unnecessary frequent DB writes and potential authentication failures. Includes comprehensive unit tests to ensure active sessions are correctly preserved.

✅ 2 resolved
✅ Performance: recordSessionAccess issues a DB write on every authenticated request

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java:382 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:495-509
validateSessionBoundToken now calls sessionService.recordSessionAccess(session) on every request authenticated with a session-bound Bearer token (JwtFilter.java:382). recordSessionAccess unconditionally performs a repository.updateIfVersion(...) write whenever the session is ACTIVE and not expired (SessionService.java:507-518). This is in the authentication hot path: the same code path already issues a DB read via getFreshSessionById -> reloadSession -> repository.findById (which bypasses the cache and always hits the store), so each request to an authenticated endpoint now incurs both a read and a write to the session store. For an actively used saved token (the exact scenario this PR targets), this means a database UPDATE per API call, which can dominate latency and load on high-traffic endpoints. Additionally, concurrent requests for the same session will collide on the optimistic-version check, causing one winner and N-1 wasted writes followed by reloads.

Consider throttling the update: only persist a refreshed lastAccessedAt/idleExpiresAt when the existing value is older than some threshold (e.g. a fraction of the idle window), keeping the in-memory cache fresh more cheaply. This preserves the LRU-eviction protection while avoiding a write on every request.

✅ Bug: Access-tracking DB error fails authentication of valid token

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/JwtFilter.java:382 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:496-510
recordSessionAccess(session) is invoked at the end of validateSessionBoundToken (JwtFilter.java:382) without any error handling. Inside recordSessionAccess, repository.updateIfVersion(...) (SessionService.java:518) and the fallback reloadSession(...) → repository.findById(...) (SessionService.java:522) are persistence calls that can throw on a transient DB/store error.

Because this call sits in the request authentication path (checkValidationsForToken → validateSessionBoundToken) and is not wrapped in a try/catch, a failure while recording access — which is purely best-effort metadata maintenance — will propagate out of the filter and reject an otherwise valid Bearer token (500/auth failure). Before this PR, the token was already considered valid at this point and the request would have succeeded.

Since the goal is only to keep actively-used sessions from being evicted, access recording should never break authentication. Wrap the call so any exception is logged and swallowed.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

This branch was previously deployed

1 inactive deployment
test — f135a2f8 Deployed Jun 9, 2026 by gitar-bot[bot] via playwright-ci-postgresql (3, 6) #50430
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.

5 participants