“Apache Cassandra, commonly known as Cassandra, is a free and open-source NoSQL database. Cassandra is well known for its simplicity, high availability, and scalability. In addition, it can handle large amounts of data with security and fault tolerance. As a result, it is a popular choice in environments where data is critical.
Popular environments where Apache Cassandra is used include Netflix, Apple, eBay, Discord, Hulu, Spotify, Yelp, Uber, and many more.
User management is one of the most fundamental roles of a database administrator. When working with Apache Cassandra, you will encounter an instance where you need to gather information about various users in the cluster.”
In this tutorial, you will learn how to view information about users in a Cassandra cluster using Cassandra CQL Shell.
Requirements
To follow along with this tutorial, you will require:
- A running Apache Cassandra cluster
- Sufficient privileges on the server
- Terminal Access.
With the above requirements met, we can proceed.
Apache Cassandra Create User
Before viewing information about users in the cluster, it’s best to ensure we have at least one user on the server.
In Apache Cassandra, we can create a user using the CREATE USER statement.
Start by logging into your CQL Shell. The command syntax is as shown:
For example, to log in as a superuser:
Once logged in, we can create a user using the statement with the syntax as shown:
[ WITH [ HASHED ] PASSWORD string ]
[ user_option ]
For to create a user account under the username “linuxhint,” we can run a query as shown:
We can also create a regular user by setting the role as NOSUPERUSER. An example query is shown:
Apache Cassandra List Users
There are two methods of showing information about users in the cluster depending on the Cassandra version.
Cassandra Version < 2.2
In Apache Cassandra version 2.2 and below, you can use the LIST USERS statement to show the list of users in the cluster.
The query above should return information as shown:
-----------+-------+-------------
cassandra | True | ALL
elastic | False | ALL
linuxhint | True | ALL
This returns information such as the username, superuser state, and the data center to which that username belongs.
Cassandra Version >= 2.2
For Cassandra version 2.2 and above, the LIST USERS; statement is deprecated. Therefore, to show user information, use the LIST ROLES; instead:
An example output is as shown:
-----------+-------+-------+---------+-------------
cassandra | True | True | {} | ALL
elastic | False | True | {} | ALL
linuxhint | True | True | {} | ALL
In this case, the command returns the username, superuser state, login state, various options, and the corresponding data center.
CQL > 3.x
In CQL version 3.x and above, you can query the system_auth table to retrieve user information. An example is as shown:
An example output:
-----------+-----------+--------------+-----------+-----------
elastic | True | False | null | $2a$10$ouaJz0U
cassandra | True | True | null | $2a$10$7U2/y/oIpjl
linuxhint | True | True | null | $2a$10$gsGThUcfMDY
Conclusion
In this article, you learned how to fetch user information in your Cassandra cluster using the CQL Shell.
Stay tuned for more!!