Manage Roles and Privileges in Apache Cloudberry
The Apache Cloudberry authorization mechanism stores roles and privileges to access database objects in the database and is administered using SQL statements or command-line utilities.
Apache Cloudberry manages database access privileges using roles. The concept of roles subsumes the concepts of users and groups. A role can be a database user, a group, or both. Roles can own database objects (for example, tables) and can assign privileges on those objects to other roles to control access to the objects. Roles can be members of other roles, thus a member role can inherit the object privileges of its parent role.
Every Apache Cloudberry system contains a set of database roles (users and groups). Those roles are separate from the users and groups managed by the operating system on which the server runs. However, for convenience you may want to maintain a relationship between operating system user names and Apache Cloudberry role names, since many of the client applications use the current operating system user name as the default.
In Apache Cloudberry, users log in and connect through the coordinator instance, which then verifies their role and access privileges. The coordinator then issues commands to the segment instances behind the scenes as the currently logged-in role.
Roles are defined at the system level, meaning they are valid for all databases in the system.
In order to bootstrap the Apache Cloudberry system, a freshly initialized system always contains one predefined superuser role (also referred to as the system user). This role will have the same name as the operating system user that initialized the Apache Cloudberry system. Customarily, this role is named gpadmin
. In order to create more roles you first have to connect as this initial role.
Security best practices for roles and privileges
- Secure the gpadmin system user. Apache Cloudberry requires a UNIX user ID to install and initialize the Apache Cloudberry system. This system user is referred to as
gpadmin
in the Apache Cloudberry documentation. Thisgpadmin
user is the default database superuser in Apache Cloudberry, as well as the file system owner of the Apache Cloudberry installation and its underlying data files. This default administrator account is fundamental to the design of Apache Cloudberry. The system cannot run without it, and there is no way to limit the access of this gpadmin user ID. Use roles to manage who has access to the database for specific purposes. You should only use thegpadmin
account for system maintenance tasks such as expansion and upgrade. Anyone who logs on to a Apache Cloudberry host as this user ID can read, alter or delete any data, including system catalog data and database access rights. Therefore, it is very important to secure the gpadmin user ID and only provide access to essential system administrators. Administrators should only log in to Apache Cloudberry asgpadmin
when performing certain system maintenance tasks (such as upgrade or expansion). Database users should never log on asgpadmin
, and ETL or production workloads should never run asgpadmin
. - Assign a distinct role to each user that logs in. For logging and auditing purposes, each user that is allowed to log in to Apache Cloudberry should be given their own database role. For applications or web services, consider creating a distinct role for each application or service. See Create New Roles (Users).
- Use groups to manage access privileges. See Role membership.
- Limit users who have the SUPERUSER role attribute. Roles that are superusers bypass all access privilege checks in Apache Cloudberry, as well as resource queuing. Only system administrators should be given superuser rights. See Altering Role Attributes.
Create new roles (users)
A user-level role is considered to be a database role that can log in to the database and initiate a database session. Therefore, when you create a new user-level role using the CREATE ROLE
command, you must specify the LOGIN
privilege. For example:
=# CREATE ROLE jsmith WITH LOGIN;
A database role may have a number of attributes that define what sort of tasks that role can perform in the database. You can set these attributes when you create the role, or later using the ALTER ROLE
command.
Alter role attributes
A database role might have a number of attributes that define what sort of tasks that role can perform in the database.
Attributes | Description |
---|---|
SUPERUSER or NOSUPERUSER | Determines if the role is a superuser. You must yourself be a superuser to create a new superuser. NOSUPERUSER is the default. |
CREATEDB or NOCREATEDB | Determines if the role is allowed to create databases. NOCREATEDB is the default. |
CREATEROLE or NOCREATEROLE | Determines if the role is allowed to create and manage other roles. NOCREATEROLE is the default. |
INHERIT or NOINHERIT | Determines whether a role inherits the privileges of roles it is a member. A role with the INHERIT attribute can automatically use whatever database privileges have been granted to all roles it is directly or indirectly a member of. INHERIT is the default. |
LOGIN or NOLOGIN | Determines whether a role is allowed to log in. A role having the LOGIN attribute can be thought of as a user. Roles without this attribute are useful for managing database privileges (groups). NOLOGIN is the default. |
CONNECTION LIMIT *connlimit* | If role can log in, this specifies how many concurrent connections the role can make. -1 (the default) means no limit. |
CREATEEXTTABLE or NOCREATEEXTTABLE | Determines whether a role is allowed to create external tables. NOCREATEEXTTABLE is the default. For a role with the CREATEEXTTABLE attribute, the default external table type is readable and the default protocol is gpfdist . Note that external tables that use the file protocol can only be created by superusers. |
PASSWORD '*password*' | Sets the role's password. If you do not plan to use password authentication you can omit this option. If no password is specified, the password will be set to null and password authentication will always fail for that user. A null password can optionally be written explicitly as PASSWORD NULL . |
DENY deny_interval or DENY deny_point | Restricts access during an interval, specified by day or day and time. For more information see Time-based authentication. |
You can set these attributes when you create the role, or later using the ALTER ROLE
command. For example:
=# ALTER ROLE jsmith WITH PASSWORD 'passwd123';
=# ALTER ROLE jsmith LOGIN;
=# ALTER ROLE jsmith DENY DAY 'Sunday';
A role can also have role-specific defaults for many of the server configuration settings. For example, to set the default schema search path for a role:
=# ALTER ROLE admin SET search_path TO myschema, public;
Role membership
It is frequently convenient to group users together to ease management of object privileges: that way, privileges can be granted to, or revoked from, a group as a whole. In Apache Cloudberry, this is done by creating a role that represents the group, and then granting membership in the group role to individual user roles.
Use the CREATE ROLE
SQL command to create a new group role. For example:
=# CREATE ROLE admin CREATEROLE CREATEDB;