nodetool invalidaterolescache
Cassandra 4.1+
This command is available in Cassandra 4.1 and later.
Invalidates the roles cache on the node.
Synopsis
Section titled “Synopsis”nodetool [connection_options] invalidaterolescacheSee connection options for connection options.
Description
Section titled “Description”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.
Examples
Section titled “Examples”Basic Usage
Section titled “Basic Usage”nodetool invalidaterolescacheAfter Role Hierarchy Changes
Section titled “After Role Hierarchy Changes”# After modifying role membershipscqlsh -e "GRANT admin_role TO power_user;"
# Invalidate to ensure changes take effect immediatelynodetool invalidaterolescacheRoles Cache Overview
Section titled “Roles Cache Overview”What the Cache Stores
Section titled “What the Cache Stores”| Cached Data | Description |
|---|---|
| Role name | The role identifier |
| Role properties | SUPERUSER, LOGIN capabilities |
| Role membership | Parent roles (inherited roles) |
| Membership graph | Complete hierarchy for permission resolution |
How It Improves Performance
Section titled “How It Improves Performance”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)Role Hierarchy Example
Section titled “Role Hierarchy Example” superadmin / \ admin_role dba_role / \ \ developer analyst operatorWhen checking permissions for developer, Cassandra must resolve that it inherits from admin_role, which inherits from superadmin. The roles cache stores this complete hierarchy.
When to Use
Section titled “When to Use”After Role Creation or Deletion
Section titled “After Role Creation or Deletion”# Create new rolecqlsh -e "CREATE ROLE analytics_team WITH LOGIN = false;"
# Invalidate cachenodetool invalidaterolescacheAfter Role Hierarchy Changes
Section titled “After Role Hierarchy Changes”When role memberships are modified:
# Grant role membershipcqlsh -e "GRANT analytics_team TO data_scientist;"
# Revoke role membershipcqlsh -e "REVOKE admin_role FROM former_admin;"
# Ensure changes take effect immediatelynodetool invalidaterolescacheAfter Role Property Changes
Section titled “After Role Property Changes”When role properties are modified:
# Change superuser statuscqlsh -e "ALTER ROLE operator WITH SUPERUSER = true;"
# Change login capabilitycqlsh -e "ALTER ROLE service_account WITH LOGIN = true;"
# Invalidate to reflect changesnodetool invalidaterolescacheSecurity Incident Response
Section titled “Security Incident Response”When immediate role changes are critical:
#!/bin/bashUSER="$1"ROLE_TO_REVOKE="$2"
# Revoke the rolecqlsh -e "REVOKE $ROLE_TO_REVOKE FROM $USER;"
# Invalidate cache on all nodes immediatelyfor 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."Troubleshooting Permission Issues
Section titled “Troubleshooting Permission Issues”When users have unexpected permissions:
# Clear all auth caches to ensure fresh resolutionnodetool invalidaterolescachenodetool invalidatepermissionscachenodetool invalidatecredentialscache
# Verify permissionscqlsh -e "LIST ALL PERMISSIONS OF problem_user;"Impact Assessment
Section titled “Impact Assessment”Immediate Effects
Section titled “Immediate Effects”| Aspect | Impact |
|---|---|
| Cached role data | All cleared |
| Next operations | Require auth table lookups |
| Role resolution | Temporarily slower |
| Permission checks | May have slight latency increase |
Recovery Timeline
Section titled “Recovery Timeline”| Phase | Duration | Cache State |
|---|---|---|
| Immediately after | 0 | Empty |
| Initial operations | Seconds | Roles being cached |
| Normal operations | Minutes | Cache 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.
Configuration
Section titled “Configuration”Cache Settings
Section titled “Cache Settings”The cassandra.yaml parameter names vary by version:
| Cassandra Version | Validity Parameter | Update Interval Parameter |
|---|---|---|
| Pre-4.1 | roles_validity_in_ms | roles_update_interval_in_ms |
| 4.1+ | roles_validity | roles_update_interval |
# cassandra.yaml (4.1+)roles_validity: 2sroles_update_interval: 1sroles_cache_max_entries: 1000
# cassandra.yaml (Pre-4.1)# roles_validity_in_ms: 2000# roles_update_interval_in_ms: 1000# roles_cache_max_entries: 1000Tuning Considerations
Section titled “Tuning Considerations”| Setting | Low Value | High Value |
|---|---|---|
roles_validity | Faster permission propagation, more auth queries | Better performance, delayed propagation |
roles_cache_max_entries | Lower memory, more cache misses | Higher memory, better hit rate |
Cluster-Wide Operations
Section titled “Cluster-Wide Operations”Invalidate on All Nodes
Section titled “Invalidate on All Nodes”For role changes to take effect cluster-wide immediately:
#!/bin/bashecho "Invalidating roles cache cluster-wide..."
# Get list of node IPs from local nodetool statusnodes=$(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."Complete Auth Cache Refresh
Section titled “Complete Auth Cache Refresh”For comprehensive auth changes:
#!/bin/bashecho "Refreshing all authentication caches cluster-wide..."
# Get list of node IPs from local nodetool statusnodes=$(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”#!/bin/bashROLE="$1"ACTION="$2" # create, delete, grant, revokeTARGET="$3" # target role for grant/revoke
echo "=== Role Modification Workflow ==="
# 1. Show current stateecho "1. Current roles:"cqlsh -e "SELECT role, is_superuser, can_login, member_of FROM system_auth.roles WHERE role = '$ROLE';"
# 2. Perform actionecho ""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 cacheecho ""echo "3. Invalidating roles cache..."nodetool invalidaterolescache
# 4. Verify changeecho ""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 ==="Troubleshooting
Section titled “Troubleshooting”Role Changes Not Taking Effect
Section titled “Role Changes Not Taking Effect”# Invalidate on all nodesfor node in $(nodetool status | grep "^UN" | awk '{print $2}'); do ssh "$node" "nodetool invalidaterolescache"done
# Also clear permissions cache as they depend on rolesfor node in $(nodetool status | grep "^UN" | awk '{print $2}'); do ssh "$node" "nodetool invalidatepermissionscache"doneInherited Permissions Not Working
Section titled “Inherited Permissions Not Working”# Check role hierarchy is correctcqlsh -e "SELECT role, member_of FROM system_auth.roles;"
# Verify the grant was recordedcqlsh -e "SELECT * FROM system_auth.role_members WHERE role = 'parent_role';"
# Clear cache and retrynodetool invalidaterolescacheSuperuser Status Not Recognized
Section titled “Superuser Status Not Recognized”# Verify superuser flag in auth tablescqlsh -e "SELECT role, is_superuser FROM system_auth.roles WHERE role = 'the_role';"
# Clear all auth cachesnodetool invalidaterolescachenodetool invalidatepermissionscachenodetool invalidatecredentialscacheCannot List Roles After Invalidation
Section titled “Cannot List Roles After Invalidation”# Check system_auth keyspace is healthynodetool status system_auth
# Check for auth-related errorsgrep -i "auth\|role" /var/log/cassandra/system.log | tail -20
# Ensure superuser role existscqlsh -u cassandra -p cassandra -e "SELECT * FROM system_auth.roles;"Best Practices
Section titled “Best Practices”Roles Cache Guidelines
- Invalidate after hierarchy changes - Always invalidate when modifying role membership
- Cluster-wide for security - Invalidate all nodes when revoking role memberships
- Combine with permissions cache - Role changes often require both caches cleared
- Test role changes - Verify expected permissions after modifications
- 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.
Related Commands
Section titled “Related Commands”| Command | Relationship |
|---|---|
| invalidatecredentialscache | Clear credentials cache |
| invalidatepermissionscache | Clear permissions cache |
| getauthcacheconfig | View auth cache settings |
| setauthcacheconfig | Modify auth cache settings |