Apache Cassandra utilizes the roles to manage the security for various types of users with access to the cluster. In addition, Cassandra allows you to define the multiple types of roles and assign them to the users within that cluster.
Each role contains a set of permissions that any user within that role can perform. For example, a specific role can only create, alter, and select the keyspaces and tables.
This ensures that only the users with specific permission can perform the various tasks within the cluster.
This article walks you through creating a role and viewing the available roles in the cluster.
Cassandra Create Role with Password
Using the CREATE ROLE and WITH PASSWORD keywords, we can create a role with a password.
An example is as shown:
The previous command creates a role called devops with the specified password. To add the superuser privileges to an already existing role, you can use the ALTER ROLE command as shown:
The previous command adds the superuser privileges to the specified role. Superuser privileges allow that role to modify the other roles and users within the cluster.
Cassandra Create User
To create a user in Cassandra, we use the CREATE ROLE keyword and set the LOGIN to true. An example is as shown:
This creates a normal user with the specified username and password. You can then login as that user using the LOGIN keyword as:
Password:b <enter password>
cap@cqlsh>
Cassandra Grant Role to a User
To grant a role to a specific user, we can use the GRANT keyword as shown in the following example:
This grants the devops role to the username “cap”.
Cassandra List Roles
To view the roles in the cluster, we can use the LIST ROLES command as:
This should return all the available roles in the cluster.
NOTE: Any role with the login set to True is treated as a normal user.
To show the roles of a specific user, we can use the OF keyword as shown:
This should return the roles that belong to the specified username.
--------+-------+-------+---------+-------------
cap | False | True | {} | ALL
devops | True | False | {} | ALL
In this case, the username “cap” has two roles.
Conclusion
In this article, you learned how to work with roles in Apache Cassandra, create various roles, and grant a role to a specific user.
Thanks for reading!