Skip to content

Commit 43dbe78

Browse files
authored
CNDB-15617: ClienState checks if system before super (#2039)
### What is the issue `ClientState.isSystem()` only checks the `isInternal` field, which is false for external client states created via `forExternalCalls(user)`. This causes the method to return false even when the authenticated user is `AuthenticatedUser.SYSTEM_USER`. This leads to incorrect behavior in `isOrdinaryUser()`, which calls `isSuper()` for `SYSTEM_USER`, triggering expensive database queries via `Roles.hasSuperuserStatus()`. During system initialization when auth tables aren't fully ready, this causes `NullPointerException` because `CassandraRoleManager.loadRoleStatement` may not be initialized yet. ### What does this PR fix and why was it fixed Change `isSystem()` to check both the internal flag and the user identity, change `isOrdinaryUser()` to check system users before super users.
1 parent 5e94c3c commit 43dbe78

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/java/org/apache/cassandra/service/ClientState.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,10 @@ public void ensureNotAnonymous()
608608
*/
609609
public boolean isOrdinaryUser()
610610
{
611+
// check isSystem() before super user, system users should bypass all guardrails and permissions
611612
if (ENABLE_GUARDRAILS_FOR_ANONYMOUS_USER.getBoolean())
612-
return !isSuperIgnoreAnonymousUser() && !isSystem();
613-
return !isSuper() && !isSystem();
613+
return !isSystem() && !isSuperIgnoreAnonymousUser();
614+
return !isSystem() && !isSuper();
614615
}
615616

616617
/**
@@ -633,11 +634,14 @@ public boolean isSuperIgnoreAnonymousUser()
633634
/**
634635
* Checks if the user is the system user.
635636
*
637+
* Returns true for both internal calls (isInternal) and external calls
638+
* made by system users.
639+
*
636640
* @return {@code true} if this user is the system user, {@code false} otherwise.
637641
*/
638642
public boolean isSystem()
639643
{
640-
return isInternal;
644+
return isInternal || (user != null && user.isSystem());
641645
}
642646

643647
public void ensureIsSuperuser(String message)

0 commit comments

Comments
 (0)