# Role Based Access Control (RBAC) ## Summary RBAC places restrictions on what actions a user can do based on the privileges granted to that user. PostgreSQL has a rich and well tested RBAC design and implementation, which we will base our implementation off of. ## Goals - Allow users to create restrictions around who is allowed to do what. ## Non-Goals - Data governance. ## Description If you want to skim this doc, then skip to the [Phase 1 - Attributes](#phase-1---attributes) section and only look at the subsection headers, tables, and SQL statements. ### Existing RBAC Features in Materialize - Creating/Deleting roles - We currently require clients to specify the `LOGIN` and `SUPERUSER` attributes when creating a role. - We support parsing `NOLOGIN` and `NOSUPERUSER` attributes, but will fail the query if those are present. - `CREATE ROLE LOGIN SUPERUSER`. - `DROP ROLE `. - We support `CREATE USER` as is treated as an alias for `CREATE ROLE LOGIN`. - `mz_roles`: catalog table that stores role names, id, and oid. - When a new user connects, a new role is automatically created for them with `LOGIN` and `SUPERUSER`. ### PostgreSQL Background #### Docs - [Roles](https://www.postgresql.org/docs/15/user-manag.html) - [Privileges](https://www.postgresql.org/docs/15/ddl-priv.html) - [Rules and Privileges](https://www.postgresql.org/docs/15/rules-privileges.html) - [Schemas and Privileges](https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PRIV) - [`CREATE ROLE`](https://www.postgresql.org/docs/15/sql-createrole.html) - [`DROP ROLE`](https://www.postgresql.org/docs/15/sql-droprole.html) - [`ALTER ROLE`](https://www.postgresql.org/docs/15/sql-alterrole.html) - [`GRANT`](https://www.postgresql.org/docs/15/sql-grant.html) - [`REVOKE`](https://www.postgresql.org/docs/15/sql-revoke.html) - [`SET ROLE`](https://www.postgresql.org/docs/15/sql-set-role.html) - [`REASSIGN OWNED`](https://www.postgresql.org/docs/15/sql-reassign-owned.html) - [`DROP OWNED`](https://www.postgresql.org/docs/15/sql-drop-owned.html) #### Implementation - [`acl.h`](https://github.com/postgres/postgres/blob/master/src/include/utils/acl.h) - [`acl.c`](https://github.com/postgres/postgres/blob/master/src/backend/utils/adt/acl.c) - [`aclchk_internal.h`](https://github.com/postgres/postgres/blob/master/src/include/utils/aclchk_internal.h) - [`aclcheck.c`](https://github.com/postgres/postgres/blob/master/src/backend/catalog/aclchk.c) - Note: There may be more, but this is a good starting point. ### Phase 1 - Attributes See [Role Attributes](https://www.postgresql.org/docs/current/role-attributes.html) for all PostgreSQL attributes. Attributes belong to a role and describe what that role is allowed to do in the system. They are independent of any particular object. We will support the following attributes: | Name | Option Name | Description | From PostgreSQL | |---------------------------|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------| | database creation | `CREATEDB` | Can create a database. | Yes | | role creation | `CREATEROLE` | Can create, alter, drop, grant membership to, and revoke membership from roles. | Yes | | inheritance of privileges | `INHERIT` | Can inherit the privileges of roles that it is a member of. On by default. For this project we can keep this as a mandatory attribute. | Yes | | cluster creation | `CREATECLUSTER` | Can create a cluster. | No | These attributes will be added to the attributes accepted by the `CREATE ROLE` statement. We will add the following SQL statement: - `ALTER ROLE [ WITH ]