Skip to content

Feature #21971: Session Management in Multiple Server Pods - #26314

Merged
harshach merged 69 commits into
mainfrom
issue-21971
Jun 4, 2026
Merged

harshach merged 69 commits into
mainfrom
issue-21971

Conversation

@harshach

@harshach harshach commented Mar 8, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes

I worked on ... because ...

Type of change:

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

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • 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.

Summary by Gitar

  • Multi-node Session Management:
    • Replaced pod-local session handling with a centralized SessionService backed by JdbcSessionStore or RedisSessionStore for cross-node state consistency.
    • Added OM_SESSION cookie-based tracking to manage user authentication across distributed pods.
  • Authentication Security:
    • Implemented session-bound JWTs and centralized refresh token storage to support cross-node logout and session revocation.
    • Enhanced SocketAddressFilter to validate session status during WebSocket handshakes, preventing connections from revoked or expired sessions.
  • Configuration:
    • Added sessionExpiry and maxActiveSessionsPerUser settings in AuthenticationConfiguration to control session lifecycles.
  • Testing:
    • Added comprehensive integration tests in SessionMultiNodeIT and SessionRedisMultiNodeIT to verify multi-node session synchronization and WebSocket session validation.

This will update automatically on new commits.

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Pull request overview

Copilot reviewed 94 out of 97 changed files in this pull request and generated no new comments.

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.

Pull request overview

Copilot reviewed 94 out of 97 changed files in this pull request and generated 3 comments.

Comment on lines +220 to +223
private UUID getUserIdForPrincipal(String userName) {
EntityReference userRef =
Entity.getEntityReferenceByName(Entity.USER, userName, Include.NON_DELETED);
return userRef.getId();
Comment on lines +250 to +259
private static String trimToNull(String value) {
if (value == null || value.isBlank()) {
return null;
}
return value.trim();
}

private static boolean hasText(String value) {
return value != null && !value.isBlank();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Custom string helpers duplicate CommonUtil-style utilities

trimToNull and hasText are newly introduced private helpers (SocketAddressFilter.java:250-259). The repository conventions ask for org.openmetadata.common.utils.CommonUtil.nullOrEmpty() for string/collection emptiness checks. While hasText (which uses isBlank()) is not exactly equivalent to nullOrEmpty (which checks null/empty only), the blank-handling logic could be consolidated to reduce per-class string utilities and stay consistent with the codebase. Consider replacing hasText(x) with !nullOrEmpty(x) where whitespace-only inputs are not a concern, or centralizing these helpers if blank handling is required. Minor / optional.

Was this helpful? React with 👍 / 👎

@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2026

Copy link
Copy Markdown

@gitar-bot

gitar-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 19 resolved / 20 findings

Implements centralized session management using JDBC or Redis backends to enable cross-node state consistency. Address minor duplication by consolidating custom string helpers with existing utility classes.

💡 Quality: Custom string helpers duplicate CommonUtil-style utilities

📄 openmetadata-service/src/main/java/org/openmetadata/service/socket/SocketAddressFilter.java:250-259

trimToNull and hasText are newly introduced private helpers (SocketAddressFilter.java:250-259). The repository conventions ask for org.openmetadata.common.utils.CommonUtil.nullOrEmpty() for string/collection emptiness checks. While hasText (which uses isBlank()) is not exactly equivalent to nullOrEmpty (which checks null/empty only), the blank-handling logic could be consolidated to reduce per-class string utilities and stay consistent with the codebase. Consider replacing hasText(x) with !nullOrEmpty(x) where whitespace-only inputs are not a concern, or centralizing these helpers if blank handling is required. Minor / optional.

✅ 19 resolved
✅ Security: revokeSession silently fails on version conflict — logout may not revoke

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:316 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:334 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:281 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:302 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:472 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthServletHandler.java:133 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/SamlAuthServletHandler.java:280 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:241
When revokeSession encounters an optimistic locking conflict (another concurrent write changed the version), the updateIfVersion call fails and the method simply returns the latest DB state without retrying the revocation. The cookie is already cleared at the caller (line 313), so the user appears logged out, but the session remains ACTIVE in the database. In a multi-node deployment, this session could continue to be used from another node.

This is a security-relevant gap: a logout request can appear to succeed while the session stays active.

✅ Bug: NPE if user not found after successful authentication

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthServletHandler.java:75 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:101
In BasicAuthServletHandler.handleLogin (line 75), getUserByEmail(loginRequest.getEmail()) can return null if the user record doesn't exist in the database (e.g., the user authenticated via LDAP/external provider but hasn't been provisioned yet). The result is immediately passed to sessionService.createActiveSession() which calls user.getId().toString() (SessionService.java:101), causing an unguarded NullPointerException.

The same pattern exists in LdapAuthServletHandler where getUserByEmail is called after successful LDAP authentication.

✅ Edge Case: acquireRefreshLease may throw spurious 503 from stale cache

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:233 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java:252 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:276 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:470 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthServletHandler.java:130 📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/SamlAuthServletHandler.java:262
In acquireRefreshLease (line 233), the initial session is fetched via getSession(request) which reads from the local Caffeine cache. In a multi-node deployment, the cached session may show REFRESHING status with a non-stale lease from another node's completed refresh. This causes a spurious SessionRefreshInProgressException (503 with Retry-After), even though the session is actually ACTIVE in the database. The client will retry and succeed after cache eviction (60s), but this creates unnecessary latency.

✅ Edge Case: SAML handleRefresh passes same token without rotation

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/auth/SamlAuthServletHandler.java:280
In SamlAuthServletHandler.handleRefresh, the refresh token is read from the session and passed back to completeRefresh without rotation — sessionService.completeRefresh(session, refreshToken, null). Unlike the OIDC and Basic handlers that delete the old token and insert a new one, the SAML handler reuses the same token indefinitely. This means the refresh token is never rotated for SAML sessions, reducing the security benefit of rotating refresh tokens.

✅ Bug: OIDC expired-token fallback removed, breaking Azure AD login

📄 openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:817
The old executeAuthorizationCodeTokenRequest method had a fallback that called renewOidcCredentials when the OIDC provider returned an already-expired ID token (with a comment noting "azure on first go itself is returning an expired token sometimes"). The new code throws TechnicalException instead, which will cause the entire callback to fail for Azure AD users who hit this condition.

Since the new flow only uses the ID token for claim extraction (the actual user-facing token is an OM-generated JWT), the expiration of the ID token is irrelevant for security. The strict check should be relaxed or a warning logged instead.

...and 14 more resolved from earlier reviews

🤖 Prompt for agents
Code Review: Implements centralized session management using JDBC or Redis backends to enable cross-node state consistency. Address minor duplication by consolidating custom string helpers with existing utility classes.

1. 💡 Quality: Custom string helpers duplicate CommonUtil-style utilities
   Files: openmetadata-service/src/main/java/org/openmetadata/service/socket/SocketAddressFilter.java:250-259

   `trimToNull` and `hasText` are newly introduced private helpers (SocketAddressFilter.java:250-259). The repository conventions ask for `org.openmetadata.common.utils.CommonUtil.nullOrEmpty()` for string/collection emptiness checks. While `hasText` (which uses `isBlank()`) is not exactly equivalent to `nullOrEmpty` (which checks null/empty only), the blank-handling logic could be consolidated to reduce per-class string utilities and stay consistent with the codebase. Consider replacing `hasText(x)` with `!nullOrEmpty(x)` where whitespace-only inputs are not a concern, or centralizing these helpers if blank handling is required. Minor / optional.

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

This branch had an error being deployed

1 failed deployment
test — 647434e2 Deployed Jun 4, 2026 by harshach via playwright-ci-postgresql (6, 6) #49648
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.

Session Management in Multiple Server Pods

5 participants