![]() |
VOOZH | about |
Cassandra Query Language (CQL) is the query language used to interact with Cassandra databases. Unlike traditional relational databases, Cassandra does not have a built-in concept of database roles. Instead, access control is managed at the object level, such as the keyspace, table, or column level.
Cassandra provides a set of permissions that can be granted to users or roles, such as SELECT, INSERT, ALTER, and DROP. Permissions can be granted to individual users or to roles, which are collections of users.
To create a role in Cassandra, you can use the CREATE ROLE command, followed by the name of the role and any options or permissions to be granted. For example:
This creates a new role called "analyst" with the password "password123" and grants the role login privileges.
To grant permissions to a role, you can use the GRANT command, followed by the permission and the name of the role or user to grant the permission to. For example:
This grants the SELECT permission on the "table1" table in the "keyspace1" keyspace to the "analyst" role.
To revoke permissions from a role, you can use the REVOKE command, followed by the permission and the name of the role or user to revoke the permission from. For example:
This revokes the SELECT permission on the "table1" table in the "keyspace1" keyspace from the "analyst" role.
In summary, while Cassandra does not have a concept of database roles like traditional relational databases, access control can be managed at the object level by granting and revoking permissions to users or roles.
In this article we will discuss Database Roles in Cassandra Query Language. It is very important to create different role for different type of users to provide access with a specific requirements. It is used to provide security for Database users or group of users.
A Role name can be simply defined as following.
role_name ::= identifier | string
create_role_statement ::= CREATE ROLE [ IF NOT EXISTS ] role_name [ WITH role_options ] role_options ::= role_option ( AND role_option )* role_option ::= PASSWORD '=' string | LOGIN '=' boolean | SUPERUSER '=' boolean | OPTIONS '=' map_literal | ACCESS TO DATACENTERS set_literal | ACCESS TO ALL DATACENTERS
syntax : CREATE ROLE new_role_name;
CREATE ROLE Ashish WITH PASSWORD = 'pass_a' AND LOGIN = true; CREATE ROLE Rana WITH PASSWORD = 'pass_r' AND LOGIN = true AND SUPERUSER = true;
CREATE ROLE user1 WITH OPTIONS = { 'option1' : 'option1_value',
'option2' : 98 };
CREATE ROLE Ashish WITH PASSWORD = 'pass_a'
AND LOGIN = true
AND ACCESS TO DATACENTERS {'DC1', 'DC4'};
CREATE ROLE Rana WITH PASSWORD = 'pass_r'
AND LOGIN = true
AND ACCESS TO ALL DATACENTERS;CREATE ROLE IF NOT EXISTS role_name;
Syntax : alter_role_statement ::= ALTER ROLE role_name WITH role_options
CREATE ROLE Rana WITH PASSWORD = 'pass_r' AND LOGIN = true AND SUPERUSER = true;
ALTER ROLE Rana WITH PASSWORD = 'pass_r' AND SUPERUSER = false;
drop_role_statement ::= DROP ROLE [ IF EXISTS ] role_name
DROP ROLE Ashish;
grant_role_statement ::= GRANT role_name TO role_name
GRANT user1 TO Ashish;
revoke_role_statement ::= REVOKE role_name FROM role_name
REVOKE user1 FROM Ashish;
list_roles_statement ::= LIST ROLES [ OF role_name ] [ NORECURSIVE ]
LIST ROLES;