A database role refers to a collection of permissions allocated to one or more users within a database. A database role can also be assigned to the other roles, allowing a set of groups to perform specific actions on the databases in the cluster. For example, Apache Cassandra utilizes roles and permissions to manage the user security.
In this tutorial, you will discover how to manage Cassandra’s roles by learning how to create and remove the roles from the cluster.
Cassandra Create Role
In Apache Cassandra, we can create a role using the CREATE ROLE command followed by the role’s name.
A created role does not have a login functionality or superuser privileges. The syntax for creating a role in Cassandra is as shown:
[WITH SUPERUSER = true | false
| LOGIN = true | false
| PASSWORD = 'password'
| OPTIONS = option_map]
Let us take a simple example of creating a role in a Cassandra cluster.
By default, creating a role does not assign any privileges unless you specify the SUPERUSER privilege during creation.
You can assign or remove the permissions to a specific role using the GRANT or REVOKE permissions. For example, the following command assigns all permissions to the database_admin role on a given keyspace:
Once you assign the specific permissions to a specific role, you can allocate to the various users that role in the cluster.
For example, to assign the database_admin role to a user called “linuxhint”, we can run the command as:
We can then view the permissions of the “database_admin” role with the following command:
This should return all the permissions of the database_admin role. An example output is as shown:
----------------+----------------+----------------------+------------
database_admin | database_admin | <keyspace linuxhint> | CREATE
database_admin | database_admin | <keyspace linuxhint> | ALTER
database_admin | database_admin | <keyspace linuxhint> | DROP
database_admin | database_admin | <keyspace linuxhint> | SELECT
database_admin | database_admin | <keyspace linuxhint> | MODIFY
database_admin | database_admin | <keyspace linuxhint> | AUTHORIZE
Cassandra Drop Role
Once a role is no longer relevant, you can remove it using the DROP ROLE command. The syntax is as shown:
For example, to remove the database_admin role that we created earlier, we can run the following command:
You can check the permissions of that role:
This returns an error since the role no longer exists on the cluster.
Conclusion
You learned how to create and manage the roles in Apache Cassandra in this article. We also discussed how to delete the roles from a cluster.