Cassandra
Database Management
User Administration
CQL Commands
Cassandra Shell

How to list all users in the Cassandra shell?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Apache Cassandra is a highly scalable, distributed, and open-source NoSQL database system. Its decentralized nature and ability to handle massive amounts of data across multiple data centers make it a popular choice for applications requiring high availability and scalability. Managing and securing Cassandra instances requires understanding how to list and manage users effectively. This article will guide you through the steps to list users within the Cassandra shell, explain the relevant technical concepts, and provide examples for better understanding.

Prerequisites

Before you start listing users, ensure you have the following:

  • Apache Cassandra installed and running.
  • Access to the Cassandra shell (cqlsh).
  • Appropriate privileges to query system tables.

Listing Users in Cassandra Shell

To list users in the Cassandra shell, you can execute specific CQL (Cassandra Query Language) commands that access the system tables where user information is stored. Follow these steps to list all users:

Step 1: Access the cqlsh

First, open your terminal and connect to the Cassandra instance using cqlsh. Use the following command:

bash
cqlsh [hostname] [port]

Replace [hostname] and [port] with appropriate values. If Cassandra is running locally and the default port is being used, you can simply run:

bash
cqlsh

Step 2: Query the system_auth Keyspace

Apache Cassandra stores user credentials and permissions in the system_auth keyspace. The roles table within this keyspace holds detailed user information.

Execute the following command to list all roles (users):

cql
SELECT role, is_superuser, can_login FROM system_auth.roles;

Explanation of Columns:

  • role: Displays the username or role name.
  • is_superuser: Indicates if the user/role has superuser privileges (true or false).
  • can_login: Specifies if the user/role can log in to the cluster or not (true or false).

Example Output

An example output from the SELECT statement may look like this:

 
1 role    | is_superuser | can_login
2---------+--------------+----------
3    admin  |         true |      true
4 bob   |        false |      true
5 alice |        false |      false

Understanding the Roles Table

The roles table contains critical information regarding user privileges and login capabilities within Cassandra. It's crucial for maintaining the security and auditability of your database environment. By evaluating the is_superuser and can_login columns, administrators can quickly identify which users have elevated privileges and which ones can access the database.

Summary of Commands and Concepts

Below is a table summarizing the key points discussed:

CommandDescription
cqlsh [hostname] [port]Connect to the Cassandra shell on the specified host and port.
SELECT role, ... FROM system_auth.roles;Query the roles table in the system_auth keyspace to list all users.
ColumnDescription
roleThe username or role name representing a user.
is_superuserA boolean value indicating if the role has superuser privileges.
can_loginA boolean value specifying if the role can log in to the Cassandra cluster.

Additional Details

User and Role Management in Cassandra

Managing users and roles in Cassandra involves creating, modifying, and deleting roles, along with assigning privileges. These operations require a good understanding of CQL commands related to role management. Some additional commands include:

  • Creating a User/Role:
cql
  CREATE ROLE IF NOT EXISTS [role_name] WITH PASSWORD = '[password]' AND LOGIN = [true|false];
  • Granting Role:
cql
  GRANT [role_name] TO [user_name];
  • Revoking Role:
cql
  REVOKE [role_name] FROM [user_name];

Best Practices

  • Regular Audits: Periodically check user permissions and clean up unused or deprecated roles.
  • Strict Superuser Assignments: Limit the number of superuser accounts to the minimum necessary for administrative tasks.
  • Secure Credentials: Ensure strong passwords and comply with security policies to protect user accounts.

Conclusion

Listing users in the Cassandra shell is a straightforward process, yet crucial for effective database management and security. By querying the system_auth.roles table, administrators can obtain a comprehensive list of users and their respective permissions. It's essential to comprehend the detailed workings of user management within Cassandra to maintain a secure, efficient, and scalable environment.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.