Skip to content

Commit ff054a2

Browse files
gwbrowncbuescher
authored andcommitted
Fix TokenService always appearing used in Feature Usage (elastic#112263)
This commit adjusts the license checks in `TokenService` so that it does not count as "used" when it checks a token, as this causes a high rate of false positives due to the authentication chain model.
1 parent b5db40b commit ff054a2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/changelog/112263.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 112263
2+
summary: Fix `TokenService` always appearing used in Feature Usage
3+
area: License
4+
type: bug
5+
issues:
6+
- 61956

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public static String hashTokenString(String accessTokenString) {
470470
* verification that the token has not been revoked or is expired.
471471
*/
472472
void tryAuthenticateToken(SecureString token, ActionListener<UserToken> listener) {
473-
if (isEnabled() && token != null) {
473+
if (shouldTryRealm() && token != null) {
474474
decodeToken(token.toString(), true, listener.delegateResponse((l, e) -> {
475475
if (isShardNotAvailableException(e)) {
476476
l.onResponse(null);
@@ -1964,8 +1964,10 @@ private static String getTokenIdFromDocumentId(String docId) {
19641964
}
19651965
}
19661966

1967-
private boolean isEnabled() {
1968-
return enabled && Security.TOKEN_SERVICE_FEATURE.check(licenseState);
1967+
private boolean shouldTryRealm() {
1968+
// Check license without tracking because this is just checking if we should *try* the realm - if this realm doesn't match,
1969+
// the next realm in the list will be checked, and that's not "using the feature"
1970+
return enabled && Security.TOKEN_SERVICE_FEATURE.checkWithoutTracking(licenseState);
19691971
}
19701972

19711973
private void ensureEnabled() {

0 commit comments

Comments
 (0)