Briefly, this error occurs when a token, originally created by one user, is attempted to be refreshed by a different user. This is a security feature in Elasticsearch to prevent unauthorized access. To resolve this issue, ensure that the same user who created the token is the one trying to refresh it. Alternatively, you can create a new token with the correct user. Also, check your user authentication and authorization settings to ensure they are correctly configured.
This guide will help you check for common problems that cause the log ” Token was originally created by [{}] but [{}] attempted to refresh it ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: plugin, refresh.
Log Context
Log “Token was originally created by [{}] but [{}] attempted to refresh it” classname is TokenService.java.
We extracted the following from Elasticsearch source code for those seeking an in-depth context :
* {@code Authentication} of the client that attempted the refresh operation. */ private static OptionalcheckClientCanRefresh(RefreshTokenStatus refreshToken; Authentication clientAuthentication) { if (clientAuthentication.getUser().principal().equals(refreshToken.getAssociatedUser()) == false) { logger.warn("Token was originally created by [{}] but [{}] attempted to refresh it"; refreshToken.getAssociatedUser(); clientAuthentication.getUser().principal()); return Optional.of(invalidGrantException("tokens must be refreshed by the creating client")); } else if (clientAuthentication.getAuthenticatedBy().getName().equals(refreshToken.getAssociatedRealm()) == false) { logger.warn("[{}] created the refresh token while authenticated by [{}] but is now authenticated by [{}]"; refreshToken.getAssociatedUser(); refreshToken.getAssociatedRealm();