Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

nodetool invalidaterolescache

Cassandra 4.1+

This command is available in Cassandra 4.1 and later.

Invalidates the roles cache on the node.


Terminal window
nodetool [connection_options] invalidaterolescache

See connection options for connection options.


nodetool invalidaterolescache clears all cached role information on the node. The roles cache stores role definitions and role hierarchy relationships from the system_auth.roles and system_auth.role_members tables, allowing Cassandra to resolve role memberships without querying the auth tables for every operation.

Role caching is essential for performance in environments with complex role hierarchies, where a single user might inherit permissions from multiple nested roles. After invalidation, subsequent operations trigger fresh role lookups from the system_auth tables.

Authentication Required

The roles cache is only relevant when authentication and authorization are enabled. If running with AllowAllAuthenticator and AllowAllAuthorizer, this cache is not used.


Terminal window
nodetool invalidaterolescache
Terminal window
# After modifying role memberships
cqlsh -e "GRANT admin_role TO power_user;"
# Invalidate to ensure changes take effect immediately
nodetool invalidaterolescache

Cached DataDescription
Role nameThe role identifier
Role propertiesSUPERUSER, LOGIN capabilities
Role membershipParent roles (inherited roles)
Membership graphComplete hierarchy for permission resolution
Without Roles Cache:
Authorization Check → Resolve role membership → Query role_members recursively → Aggregate permissions
With Roles Cache:
Authorization Check → Lookup cached membership → Aggregate permissions
(Avoids recursive auth table queries)
superadmin
/ \
admin_role dba_role
/ \ \
developer analyst operator

When checking permissions for developer, Cassandra must resolve that it inherits from admin_role, which inherits from superadmin. The roles cache stores this complete hierarchy.


Terminal window
# Create new role
cqlsh -e "CREATE ROLE analytics_team WITH LOGIN = false;"
# Invalidate cache
nodetool invalidaterolescache

When role memberships are modified:

Terminal window
# Grant role membership
cqlsh -e "GRANT analytics_team TO data_scientist;"
# Revoke role membership
cqlsh -e "REVOKE admin_role FROM former_admin;"
# Ensure changes take effect immediately
nodetool invalidaterolescache

When role properties are modified:

Terminal window
# Change superuser status
cqlsh -e "ALTER ROLE operator WITH SUPERUSER = true;"
# Change login capability
cqlsh -e "ALTER ROLE service_account WITH LOGIN = true;"
# Invalidate to reflect changes
nodetool invalidaterolescache

When immediate role changes are critical:

emergency_role_revoke.sh
#!/bin/bash
USER="$1"
ROLE_TO_REVOKE="$2"
# Revoke the role
cqlsh -e "REVOKE $ROLE_TO_REVOKE FROM $USER;"
# Invalidate cache on all nodes immediately
for node in $(nodetool status | grep "^UN" | awk '{print $2}'); do
ssh "$node" "nodetool invalidaterolescache"
ssh "$node" "nodetool invalidatepermissionscache"
done
echo "Role $ROLE_TO_REVOKE revoked from $USER on all nodes."

When users have unexpected permissions:

Terminal window
# Clear all auth caches to ensure fresh resolution
nodetool invalidaterolescache
nodetool invalidatepermissionscache
nodetool invalidatecredentialscache
# Verify permissions
cqlsh -e "LIST ALL PERMISSIONS OF problem_user;"

AspectImpact
Cached role dataAll cleared
Next operationsRequire auth table lookups
Role resolutionTemporarily slower
Permission checksMay have slight latency increase
PhaseDurationCache State
Immediately after0Empty
Initial operationsSecondsRoles being cached
Normal operationsMinutesCache populated for active roles

Low Impact Operation

Role cache invalidation typically has minimal performance impact since role lookups are relatively fast and the cache repopulates quickly with normal operations.


The cassandra.yaml parameter names vary by version:

Cassandra VersionValidity ParameterUpdate Interval Parameter
Pre-4.1roles_validity_in_msroles_update_interval_in_ms
4.1+roles_validityroles_update_interval
# cassandra.yaml (4.1+)
roles_validity: 2s
roles_update_interval: 1s
roles_cache_max_entries: 1000
# cassandra.yaml (Pre-4.1)
# roles_validity_in_ms: 2000
# roles_update_interval_in_ms: 1000
# roles_cache_max_entries: 1000
SettingLow ValueHigh Value
roles_validityFaster permission propagation, more auth queriesBetter performance, delayed propagation
roles_cache_max_entriesLower memory, more cache missesHigher memory, better hit rate

For role changes to take effect cluster-wide immediately:

invalidate_roles_cluster.sh
#!/bin/bash
echo "Invalidating roles cache cluster-wide..."
# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
for node in $nodes; do
echo -n "$node: "
ssh "$node" 'nodetool invalidaterolescache 2>/dev/null && echo "invalidated" || echo "FAILED"'
done
echo "Roles cache cleared on all nodes."

For comprehensive auth changes:

refresh_all_auth_caches.sh
#!/bin/bash
echo "Refreshing all authentication caches cluster-wide..."
# Get list of node IPs from local nodetool status
nodes=$(nodetool status | grep "^UN" | awk '{print $2}')
for node in $nodes; do
echo "Processing $node..."
ssh "$node" "nodetool invalidaterolescache 2>/dev/null"
ssh "$node" "nodetool invalidatepermissionscache 2>/dev/null"
ssh "$node" "nodetool invalidatecredentialscache 2>/dev/null"
echo " Done"
done
echo "All auth caches cleared."

Workflow: Role Modification with Validation

Section titled “Workflow: Role Modification with Validation”
role_modification_workflow.sh
#!/bin/bash
ROLE="$1"
ACTION="$2" # create, delete, grant, revoke
TARGET="$3" # target role for grant/revoke
echo "=== Role Modification Workflow ==="
# 1. Show current state
echo "1. Current roles:"
cqlsh -e "SELECT role, is_superuser, can_login, member_of FROM system_auth.roles WHERE role = '$ROLE';"
# 2. Perform action
echo ""
echo "2. Performing: $ACTION"
case $ACTION in
create)
cqlsh -e "CREATE ROLE $ROLE;"
;;
delete)
cqlsh -e "DROP ROLE $ROLE;"
;;
grant)
cqlsh -e "GRANT $TARGET TO $ROLE;"
;;
revoke)
cqlsh -e "REVOKE $TARGET FROM $ROLE;"
;;
esac
# 3. Invalidate cache
echo ""
echo "3. Invalidating roles cache..."
nodetool invalidaterolescache
# 4. Verify change
echo ""
echo "4. Role state after change:"
cqlsh -e "SELECT role, is_superuser, can_login, member_of FROM system_auth.roles WHERE role = '$ROLE';"
echo ""
echo "=== Complete ==="

Terminal window
# Invalidate on all nodes
for node in $(nodetool status | grep "^UN" | awk '{print $2}'); do
ssh "$node" "nodetool invalidaterolescache"
done
# Also clear permissions cache as they depend on roles
for node in $(nodetool status | grep "^UN" | awk '{print $2}'); do
ssh "$node" "nodetool invalidatepermissionscache"
done
Terminal window
# Check role hierarchy is correct
cqlsh -e "SELECT role, member_of FROM system_auth.roles;"
# Verify the grant was recorded
cqlsh -e "SELECT * FROM system_auth.role_members WHERE role = 'parent_role';"
# Clear cache and retry
nodetool invalidaterolescache
Terminal window
# Verify superuser flag in auth tables
cqlsh -e "SELECT role, is_superuser FROM system_auth.roles WHERE role = 'the_role';"
# Clear all auth caches
nodetool invalidaterolescache
nodetool invalidatepermissionscache
nodetool invalidatecredentialscache
Terminal window
# Check system_auth keyspace is healthy
nodetool status system_auth
# Check for auth-related errors
grep -i "auth\|role" /var/log/cassandra/system.log | tail -20
# Ensure superuser role exists
cqlsh -u cassandra -p cassandra -e "SELECT * FROM system_auth.roles;"

Roles Cache Guidelines

  1. Invalidate after hierarchy changes - Always invalidate when modifying role membership
  2. Cluster-wide for security - Invalidate all nodes when revoking role memberships
  3. Combine with permissions cache - Role changes often require both caches cleared
  4. Test role changes - Verify expected permissions after modifications
  5. Document role hierarchy - Maintain documentation of role relationships

Security Considerations

  • Role hierarchy changes can have cascading effects on permissions
  • Always invalidate cluster-wide when revoking roles
  • Consider the full inheritance chain when troubleshooting
  • Audit role changes for compliance requirements

Relationship to Other Caches

The roles cache works together with other auth caches:

  • Credentials cache: Validates login credentials
  • Roles cache: Resolves role memberships and hierarchy
  • Permissions cache: Determines allowed operations

For complete auth refresh, invalidate all three caches.


CommandRelationship
invalidatecredentialscacheClear credentials cache
invalidatepermissionscacheClear permissions cache
getauthcacheconfigView auth cache settings
setauthcacheconfigModify auth cache settings