docs/RFCS/20150810_sql_privileges.md
Introduce SQL privileges for databases and tables. The aim is to provide a privilege framework familiar to users of popular SQL servers while embracing simplicity.
We intentionally do not address privileges for other granularities (columns or rows), or unsupported features (views, temporary tables, procedures, etc...).
The SQL interface needs permissioning on database and tables. For ease of migration and understanding, we wish to use common SQL privileges albeit adapted for our use, or simplified.
We use the postgres and mysql privileges as references.
SELECT to B, only
A can remove SELECT from B. If another role granted SELECT as well, it stays).SUPERUSER is a user attribute. It allows everything.PUBLIC schema granting liberal privileges to all users.\du command in psql.ALL is translated to the list of all privileges.GRANT ALL on db.* TO user1).SHOW GRANTS [FOR x].ALL is a shortcut for setting and display.root user has default ALL privileges on all new databases. It is also the only
user allowed to create databases.root user privileges cannot be removed. (This may change and be implicit ALL for root).GRANT is specified as a privilege. It may make more sense to use WITH GRANT OPTION
on the GRANT statement (similar to postgres and mysql).SHOW GRANTS [FOR x].ALL is a shortcut for setting and display.| Privilege | Level |
|---|---|
| ALL | DB, Table |
| CREATE | DB |
| DROP | DB, Table |
| GRANT | DB, Table |
| SELECT | Table |
| INSERT | Table |
| DELETE | Table |
| UPDATE | Table |
Important note: there is a lot of simplification in the following summaries. For more details, it is recommended to follow the links.
CREATE DATABASE:
CREATE privilege on the database.SUPERUSER or CREATEDB user option.root user.CREATE TABLE:
CREATE privilege on table.CREATE privilege in schema.CREATE privilege on database.DROP DATABASE:
DROP TABLE:
GRANT:
GRANT OPTION and the granted privileges.GRANT OPTION and the granted privileges.GRANT on affected object. Does not require the granted privileges.REVOKE:
GRANT OPTION and the revoked privileges (another invocation has stricter requirements).GRANT OPTION on revoked privileges. Complex rules for grantees.GRANT on affected object.SELECT:
SELECT (doc seems incomplete).SELECT if tables are read. Also requires UPDATE when using FOR UPDATE.SELECT if tables are read.INSERT:
INSERT. UPDATE or SELECT for ON DUPLICATE KEY UPDATE.INSERT. SELECT if using RETURNING.INSERT on table. SELECT if using SELECT clause on tables.DELETE:
DELETE on table. SELECT if WHERE clause operates on tables.DELETE on table. SELECT if USING or WHERE clauses operate on tables.DELETE on table. SELECT if WHERE clause operates on tables.UPDATE:
UPDATE. Also SELECT for WHERE clause with table.UPDATE. Also SELECT for WHERE clause with table.UPDATE. Also SELECT for WHERE clause with table.TRUNCATE:
SHOW:
SHOW name is supported. No privileges required.SET:
Privileges are stored in the DatabaseDescriptor and TableDescriptor using
a list sorted by user.
This gives the planner access to privileges after a descriptor lookup.
Future improvements include gossiping descriptors #1743 and potentially using a real table.
Postgres and mysql both have global user tables. We do not require users to be in the user config, only to be properly authenticated. This means that we cannot have user-defined super users.
Like all sql servers, privilege logic is very custom. This proposal closely resembles the mysql logic modified for the lack of a global privilege table.
A proper use of privileges greatly depends on proper documentation. Both postgres and mysql do an inadequate job of documenting required privileges for various operations, sometimes mentioning nothing at all.
The right balance has to be found between simplicity and familiarity.
Simplifying GRANT to be a privilege in itself may be counter-intuitive
for those familiar with other sql servers.
Two possible future features are:
Examine privilege logic for other sql servers and sql layers on top of non-transactional databases.
This is an incomplete list of statements. If approved, this RFC should be turned into a document and kept up-to-date with implementation.