Sub topic 4
Privilege Types and What They Allow
This chapter covers the privileges Unity Catalog defines and what each one lets a principal do. It assumes you know basic SQL, can use the Databricks SQL editor or a notebook, and have read the chapters on the object hierarchy and on principals and groups.
The working model
A privilege is a permission on a securable object. Unity Catalog denies access by default. A principal can do nothing with an object until it owns the object or someone grants it a privilege. There is no explicit "deny" privilege. Access is the union of everything a principal has been granted, directly or through groups.
Privileges fall into three kinds:
- Navigation privileges let a principal reach an object inside a parent.
- Data privileges let a principal read or change the contents of an object.
- Creation and management privileges let a principal add objects or control access.
Navigation privileges
USE CATALOG and USE SCHEMA do not give access to data. They let a principal "see through" a catalog or schema to the objects inside it. To query main.sales.orders, a principal needs USE CATALOG on main, USE SCHEMA on main.sales, and SELECT on the table. Missing any one of the three produces a permission error.
Data privileges
| Privilege | Applies to | What it allows |
|---|---|---|
| `SELECT` | Tables, views, materialized views | Read rows and columns |
| `MODIFY` | Tables | Insert, update, delete and merge data |
| `READ VOLUME` | Volumes | Read files in the volume |
| `WRITE VOLUME` | Volumes | Add, change and remove files in the volume |
| `EXECUTE` | Functions, models | Call a function or use a registered model |
MODIFY does not include SELECT. A pipeline that runs MERGE normally needs both, because a merge must read the target table.
Creation and management privileges
| Privilege | Applies to | What it allows |
|---|---|---|
| `CREATE CATALOG` | Metastore | Create catalogs |
| `CREATE SCHEMA` | Catalog | Create schemas in the catalog |
| `CREATE TABLE` | Schema | Create tables and views in the schema |
| `CREATE VOLUME` | Schema | Create volumes in the schema |
| `CREATE FUNCTION` | Schema | Create functions in the schema |
| `MANAGE` | Any securable object | View and change grants, transfer ownership, drop or rename the object |
| `ALL PRIVILEGES` | Any securable object | Shorthand for every privilege that applies, except `MANAGE` |
MANAGE lets someone administer an object without owning it. Use it sparingly. A holder can grant privileges to others, including to themselves.
The exact list of privileges changes as Databricks adds features, so check the current documentation for the object type you work with.
Worked example
A group of analysts needs to read one table and write to a scratch volume.
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `data-analysts`;
GRANT SELECT ON TABLE main.sales.orders TO `data-analysts`;
GRANT READ VOLUME, WRITE VOLUME ON VOLUME main.sales.scratch TO `data-analysts`;The first three statements are the minimum chain for reading one table. The last statement uses one GRANT to give two privileges on the same object. The analysts can read and write files in scratch. They cannot create tables, because they have no CREATE TABLE on the schema.
Common errors
- Granting only
SELECTon a table and forgettingUSE CATALOGorUSE SCHEMA. The user gets a permission error even though the table grant exists. - Assuming
MODIFYallows reads. It does not. - Assuming
ALL PRIVILEGESincludesMANAGE. It does not, so grantMANAGEseparately when you need it. - Granting
CREATE TABLEwhen the principal only needs to write to existing tables. UseMODIFYinstead.
Exercise
A service principal must run a job that reads main.sales.orders and appends new rows to main.sales.orders_archive. The principal has no other privileges. Which privileges does it need?
Show answer
USE CATALOG on main and USE SCHEMA on main.sales. SELECT on main.sales.orders to read it. MODIFY on main.sales.orders_archive to append rows. It does not need SELECT on the archive table unless the job also reads from it, for example in a MERGE.