DCL

Updated at:

Data Control Language (DCL) manages database roles and permissions in Lindorm Cassandra Query Language (CQL). Use DCL statements to create and delete roles, list roles, and grant or revoke permissions.

Manage database roles

In Lindorm CQL, database roles control user access and permissions. Define a role name using the following grammar:

role_name ::=  identifier | string

Lindorm CQL and Apache Cassandra CQL support similar role management operations. By default, a new database role has no logon permissions and no superuser permissions.

Manage permissions

Lindorm CQL uses a permission hierarchy: granting a permission at a higher resource level automatically applies it to all lower-level resources. For example, granting SELECT on ALL KEYSPACES also grants SELECT on every table in every keyspace.

Note

After permissions change, existing client connections remain valid — clients do not need to reconnect.

Lindorm CQL supports five permission types: CREATE, ALTER, DROP, SELECT, and MODIFY.

Each permission is valid only for specific resource types. Granting a permission on an unsupported resource returns an error.

The following table maps each permission to its supported resources and statements.

PermissionResourceSupported statement
CREATEALL KEYSPACESCREATE KEYSPACES and CREATE TABLE
CREATEKEYSPACECREATE TABLE
ALTERALL KEYSPACESALTER KEYSPACES and ALTER TABLE
ALTERKEYSPACEALTER TABLE
DROPALL KEYSPACESDROP KEYSPACES and DROP TABLE
DROPKEYSPACEDROP TABLE
SELECTALL KEYSPACESSELECT KEYSPACES and SELECT TABLE
SELECTKEYSPACESELECT TABLE
SELECTTABLESELECT
MODIFYALL KEYSPACESMODIFY KEYSPACES and MODIFY TABLE
MODIFYKEYSPACEMODIFY TABLE
MODIFYTABLEMODIFY

CREATE ROLE

Creates a database role.

Syntax

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

Parameters

ParameterDescription
role_nameThe name of the database role.
PASSWORDRequired. The password the role uses to log on to the database.
LOGINSpecifies whether the role has logon permissions. Default: false. When a client connects using a role with LOGIN = true, the client assumes that role and inherits all of its permissions.
SUPERUSERSpecifies whether the role is a superuser. Default: false. A superuser can: create other superusers; run DROP KEYSPACE, DROP TABLE, and TRUNCATE; grant permissions on keyspaces and tables; and create permission hierarchies.

Examples

Create a role with logon permissions:

CREATE ROLE readonly_user WITH PASSWORD = 'password_a' AND LOGIN = true;

Create a superuser role with logon permissions:

CREATE ROLE admin_role WITH PASSWORD = 'password_b' AND LOGIN = true AND SUPERUSER = true;

DROP ROLE

Deletes a database role.

Syntax

drop_role_statement ::=  DROP ROLE [ IF EXISTS ] role_name
Note

To delete a role, you must have the DELETE permission on that role. Only a superuser can delete a role that has SUPERUSER set to true. A role that is currently logged on cannot be deleted.

The IF EXISTS clause controls behavior when the target role does not exist:

  • Without IF EXISTS: the statement returns an error.

  • With IF EXISTS: the statement is a no-op.

Parameters

ParameterDescription
role_nameThe name of the database role to delete.

Examples

Delete a role (returns an error if the role does not exist):

DROP ROLE bob;

Delete a role only if it exists:

DROP ROLE IF EXISTS bob;

LIST ROLES

Lists database roles.

Syntax

list_roles_statement ::=  LIST ROLES [ OF role_name ]

Parameters

ParameterDescription
role_name(Optional) The role to query. Returns the details of that role.

Examples

List all roles in the system (superusers only):

LIST ROLES;

List all roles granted to role1:

LIST ROLES OF role1;

GRANT PERMISSION

Grants permissions to a database role.

Syntax

grant_permission_statement ::=  GRANT permissions ON resource TO role_name
permissions                ::=  ALL [ PERMISSIONS ] | permission [ PERMISSION ]
permission                 ::=  CREATE | ALTER | DROP | SELECT | MODIFY
resource                   ::=  ALL KEYSPACES
                               | KEYSPACE keyspace_name
                               | [ TABLE ] table_name

Parameters

ParameterDescription
permissionThe permission to grant: CREATE, ALTER, DROP, SELECT, or MODIFY. Use ALL PERMISSIONS to grant all five permissions at once.
resourceThe resource scope: ALL KEYSPACES, KEYSPACE keyspace_name, or TABLE table_name (the TABLE keyword is optional).
keyspace_nameThe name of the keyspace.
table_nameThe name of the table.
role_nameThe role to receive the permission.

Examples

Grant SELECT on all keyspaces to readonly_user, so the role can run SELECT on any table in the system:

GRANT SELECT ON ALL KEYSPACES TO readonly_user;

Grant SELECT on a specific keyspace to readonly_user, so the role can run SELECT on any table in ks:

GRANT SELECT ON KEYSPACE ks TO readonly_user;

REVOKE PERMISSION

Revokes permissions from a database role.

Syntax

revoke_permission_statement ::=  REVOKE permissions ON resource FROM role_name

Parameters

ParameterDescription
permissionThe permission to revoke: CREATE, ALTER, DROP, SELECT, or MODIFY. Use ALL PERMISSIONS to revoke all five permissions at once.
resourceThe resource scope: ALL KEYSPACES, KEYSPACE keyspace_name, or TABLE table_name.
role_nameThe role from which to revoke the permission.

Examples

Revoke SELECT on all keyspaces from readonly_user:

REVOKE SELECT ON ALL KEYSPACES FROM readonly_user;

LIST PERMISSIONS

Lists permissions granted on each resource.

Syntax

list_permissions_statement ::=  LIST permissions [ ON resource ] [ OF role_name ]
Note

OF role_name is required by default. Only a superuser can run LIST PERMISSIONS without specifying a role. Without ON resource, the statement returns the role's permissions on all resources.

Parameters

ParameterDescription
permissionsThe permission types to list: CREATE, ALTER, DROP, SELECT, MODIFY, or ALL PERMISSIONS.
resource(Optional) Filter results to a specific resource: ALL KEYSPACES, KEYSPACE keyspace_name, or TABLE table_name.
role_nameThe role whose permissions to list.

Examples

List all permissions held by readonly_user across all resources:

LIST ALL PERMISSIONS OF readonly_user;

List all permissions readonly_user holds on keyspace kss:

LIST ALL PERMISSIONS ON KEYSPACE kss OF readonly_user;