Sub topic 6
Controlling access with READ VOLUME and WRITE VOLUME
This chapter assumes you can run SQL in a Databricks notebook, know what a catalog and schema are, and have already created a volume. It covers how Unity Catalog decides who can read and write files in a volume.
The two privileges
Access to files in a volume is controlled by two privileges on the volume itself:
READ VOLUMElets a principal list files and read their contents.WRITE VOLUMElets a principal add, overwrite, and delete files.
WRITE VOLUME does not imply READ VOLUME. A group that uploads files and also needs to check them must have both.
A principal is a user, a service principal, or a group. Granting to groups is easier to maintain than granting to individuals.
Granting and revoking
GRANT READ VOLUME, WRITE VOLUME ON VOLUME main.default.landing TO `data-engineers`;
GRANT READ VOLUME ON VOLUME main.default.landing TO `analysts`;
REVOKE WRITE VOLUME ON VOLUME main.default.landing FROM `data-engineers`;Backticks are required around group names that contain a hyphen.
To see what is granted, run:
SHOW GRANTS ON VOLUME main.default.landing;The output lists each principal, the privilege, and the object it applies to.
The parent privileges
Volume privileges are not enough on their own. Unity Catalog checks the whole path from the catalog down to the volume. A principal also needs:
USE CATALOGon the catalog (main).USE SCHEMAon the schema (main.default).
GRANT USE CATALOG ON CATALOG main TO `analysts`;
GRANT USE SCHEMA ON SCHEMA main.default TO `analysts`;Privileges are inherited. If you grant READ VOLUME on a schema, the principal can read every volume in that schema, including volumes created later. Use this for broad access and grant on the volume itself when you want to be precise.
Creating a volume requires CREATE VOLUME on the schema. The volume's owner can grant privileges on it.
Where the privileges apply
The same privileges apply no matter how you reach the files. Notebooks, Spark, open(), SQL, the CLI, and the Files API all go through Unity Catalog. You cannot bypass a grant by choosing a different tool.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Permission denied when listing a volume | Missing `READ VOLUME` | Grant it on the volume or its schema |
| Reads work but uploads fail | Missing `WRITE VOLUME` | Grant it to the uploading group |
| Volume is not found even though you have `READ VOLUME` | Missing `USE CATALOG` or `USE SCHEMA` | Grant the parent privileges |
| Grant has no effect for a user | The user is not in the group you granted to | Check group membership |
Check your understanding
Exercise
An analyst has READ VOLUME on main.default.landing but gets an error when running LIST '/Volumes/main/default/landing/'. What else should you check?
Show answer
Check that the analyst has USE CATALOG on main and USE SCHEMA on main.default. READ VOLUME alone is not enough, because Unity Catalog also requires access to the parent catalog and schema.
Exercise
Write the SQL that lets the group etl-jobs upload files to main.default.landing and also read them back.
Show answer
GRANT READ VOLUME, WRITE VOLUME ON VOLUME main.default.landing TO etl-jobs;