Skip to content

Conversation

sug-ghosh
Copy link

@sug-ghosh sug-ghosh commented Jul 1, 2025

Description

fixes #717

Features Implemented

  1. 15-minute Session Timeout

Backend: JWT tokens now expire after 15 minutes instead of 24 hours
Frontend: Client-side session management tracks user activity and automatically logs out after 15 minutes of inactivity
Activity Detection: Mouse movements, clicks, keyboard input, scrolling, and touch events reset the timeout

  1. Server Restart Detection

Backend: JWT tokens include a server start timestamp claim
Frontend: Checks server start time on every API call to detect server restarts immediately
Automatic Logout: Users are automatically logged out on any action after server restart

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required, with the following suggested text:

* Fix some things.

@cla-bot cla-bot bot added the cla-signed label Jul 1, 2025
@sug-ghosh sug-ghosh requested review from ebyhr and mosabua July 1, 2025 17:10
@sug-ghosh
Copy link
Author

@mosabua @ebyhr please review this pr for logout users when Trino-gateway server restarts.

@@ -38,6 +40,8 @@
public class LbFormAuthManager
{
private static final Logger log = Logger.get(LbFormAuthManager.class);
private static final long SERVER_START_TIME = System.currentTimeMillis();
private static final int SESSION_TIMEOUT_MINUTES = 15;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a specific reason for 15 min? If not, why don't we make this configurable? + docs would be welcome :)

Copy link
Author

Choose a reason for hiding this comment

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

@Chaho12 mostly pentester recommend 15 minutes for UI session. That's why. otherwise I can make it configurable. and which docs I should update?

Copy link
Member

Choose a reason for hiding this comment

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

Since Tomcat, Spring is 30 min, i thought 30 min was default.
https://trinodb.github.io/trino-gateway/security/ this page sounds fit.

Copy link
Author

Choose a reason for hiding this comment

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

@Chaho12 okay, I will make this 30. and do I make this configurable as well?

Copy link
Member

Choose a reason for hiding this comment

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

let's make this configurable

Copy link
Member

Choose a reason for hiding this comment

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

also, please use airlift's Duration class

if (formAuthManager != null) {
// Get server start time from form auth manager
try {
java.lang.reflect.Field field = formAuthManager.getClass().getDeclaredField("SERVER_START_TIME");
Copy link
Member

Choose a reason for hiding this comment

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

let's not use reflection for this

@@ -38,6 +40,8 @@
public class LbFormAuthManager
{
private static final Logger log = Logger.get(LbFormAuthManager.class);
private static final long SERVER_START_TIME = System.currentTimeMillis();
Copy link
Member

Choose a reason for hiding this comment

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

if this is intended to be shared by multiple classes, we can move it out from this class and then create a separate config class. OR we can create a getter for this field

@@ -38,6 +40,8 @@
public class LbFormAuthManager
{
private static final Logger log = Logger.get(LbFormAuthManager.class);
private static final long SERVER_START_TIME = System.currentTimeMillis();
private static final int SESSION_TIMEOUT_MINUTES = 15;
Copy link
Member

Choose a reason for hiding this comment

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

let's make this configurable

@@ -38,6 +40,8 @@
public class LbFormAuthManager
{
private static final Logger log = Logger.get(LbFormAuthManager.class);
private static final long SERVER_START_TIME = System.currentTimeMillis();
private static final int SESSION_TIMEOUT_MINUTES = 15;
Copy link
Member

Choose a reason for hiding this comment

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

also, please use airlift's Duration class

@@ -105,6 +109,21 @@ public Optional<Map<String, Claim>> getClaimsFromIdToken(String idToken)
DecodedJWT jwt = JWT.decode(idToken);

if (LbTokenUtil.validateToken(idToken, lbKeyProvider.getRsaPublicKey(), jwt.getIssuer(), Optional.empty())) {
// Check if token was issued before server restart
Claim serverStartClaim = jwt.getClaim("server_start");
Copy link
Member

Choose a reason for hiding this comment

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

can we wrap it in Optional so it's clear that it's nullable?

}
}
// Check token expiration
Date expiresAt = jwt.getExpiresAt();
Copy link
Member

Choose a reason for hiding this comment

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

can we wrap it in Optional so it's clear that it's nullable?

Copy link
Author

Choose a reason for hiding this comment

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

@andythsu I have resolved other comments in this forced pushed pr.

}
} catch (error) {
// Token validation failed, user will be logged out
throw error;
Copy link
Member

Choose a reason for hiding this comment

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

Are we doing anything in catch? Otherwise it may be unnecessary to catch the error

Copy link
Author

Choose a reason for hiding this comment

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

@andythsu yes, we are throwing error as token validation failed and user will be logged out in that case

}
} catch (error) {
console.error('Error checking server info:', error);
// Don't logout on API error, just continue
Copy link
Member

Choose a reason for hiding this comment

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

should we log out here? technically we should never end up in this state, but if we do, it means the server is having issues.

Copy link
Author

Choose a reason for hiding this comment

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

@andythsu No, we are not logging out here, we are logging the server error here

@sug-ghosh sug-ghosh requested a review from andythsu July 3, 2025 17:00
@sug-ghosh
Copy link
Author

@andythsu can you please review once?

@sug-ghosh sug-ghosh requested a review from Chaho12 July 8, 2025 04:27
@mosabua
Copy link
Member

mosabua commented Jul 11, 2025

As it stands this change is not useful. Users should NOT be logged out just because one Trino Gateway server shuts down. Trino Gateway can run as a cluster and users should not be logged out but instead remain active and continue to be able to use everything.

@sug-ghosh
Copy link
Author

As it stands this change is not useful. Users should NOT be logged out just because one Trino Gateway server shuts down. Trino Gateway can run as a cluster and users should not be logged out but instead remain active and continue to be able to use everything.

Hello @mosabua , understand, will it be helpful if I discard the changes related to logout in server detection and keep the changes of 30 minute session timeout if user remains idle. Can this be taken if Trino Gateway Run as a cluster?

@mosabua
Copy link
Member

mosabua commented Jul 12, 2025

Yes .. I think an idle logout might still be a good thing .. as long as it also works if Trino Gateway runs as cluster

@sug-ghosh
Copy link
Author

Hello @mosabua if you suggesting Gateway run as a cluster means, HA proxy above gateway cluster, then the above changes works fine. I have already validated that. If one of the server restarts it does not throw away users logged off. only if HA cluster is restarted then only it logged off the user for a new session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Trino Gateway page not getting logged out even after restart of gateway or forever until we manually click on logout
4 participants