Sub topic 9
Controlling access to cloud storage
This chapter assumes you know the Unity Catalog object hierarchy (metastore, catalog, schema, table), and that you can run GRANT and REVOKE statements. It covers how Unity Catalog controls access to files in cloud object storage, such as S3, Azure Data Lake Storage, or Google Cloud Storage.
Why storage needs its own controls
Table permissions control SQL access to tables. The files behind a table are a separate matter. Anyone who can read the underlying path with cloud credentials can bypass every table-level rule, including row filters and column masks.
Unity Catalog closes that gap by not handing out raw cloud credentials to users. Instead, it keeps the credentials itself. When a user is allowed to touch a path, Unity Catalog issues short-lived, narrowly scoped credentials for that request.
Two securable objects make this work:
- A storage credential is a securable object that holds a cloud identity, for example an AWS IAM role, an Azure managed identity, or a Google Cloud service account. This identity has permission to reach a storage location.
- An external location is a securable object that pairs a cloud storage path (a URL such as
s3://my-bucket/landing) with one storage credential.
Users are never granted access to the storage account. They are granted privileges on an external location, and Unity Catalog uses the linked credential to reach the path on their behalf.
Managed and external storage
Unity Catalog distinguishes two kinds of table storage:
| Aspect | Managed tables | External tables |
|---|---|---|
| Where files live | In the managed storage location of the metastore, catalog, or schema | In a path you choose, covered by an external location |
| Who controls the files | Unity Catalog | You, with Unity Catalog governing access |
| Effect of `DROP TABLE` | Data files are eventually deleted | Metadata is removed. Files stay in place |
| Access to the path | No external location privileges needed | Requires privileges on the external location |
External locations are used for external tables, external volumes, and for managed storage locations assigned to catalogs or schemas. They are also used when you read raw files directly, such as ingesting from a landing zone.
Granting access on an external location
You grant privileges on an external location the same way you grant them on any other securable object. The principal is a group, as recommended throughout this tutorial.
GRANT CREATE EXTERNAL TABLE ON EXTERNAL LOCATION landing_zone TO `data-engineers`;The main privileges on an external location are:
| Privilege | What it allows |
|---|---|
| `READ FILES` | Read files directly from the path, for example with `SELECT * FROM read_files(...)` or Spark file reads |
| `WRITE FILES` | Write files directly to the path |
| `CREATE EXTERNAL TABLE` | Create external tables whose data lives in the path |
| `CREATE EXTERNAL VOLUME` | Create external volumes in the path |
| `CREATE MANAGED STORAGE` | Use the path as managed storage for a catalog or schema |
| `MANAGE` | Manage the location, including its grants |
Check what a principal holds with SHOW GRANTS:
SHOW GRANTS ON EXTERNAL LOCATION landing_zone;Path rules
Unity Catalog applies a few rules to the paths covered by external locations.
- Longest match decides. If two external locations cover a path, the more specific one governs. A location on
s3://bucket/landing/salestakes precedence over one ons3://bucket/landingfor files undersales. - No overlap with managed storage. An external location cannot overlap the managed storage of the metastore, catalog, or schema, and an external table cannot be placed there either.
- One table, one path. Do not point two external tables at the same path. Unity Catalog cannot protect against two tables writing to the same files, and the privilege model assumes one governing object per path.
- Nested locations are allowed, but plan them. A child location can sit under a parent location, but the grants on each are independent. Granting on the parent does not grant on the child.
Creating the objects
Setting up the cloud side (the IAM role, managed identity, or service account) is done in your cloud provider, and the trust relationship must allow Databricks to assume it. Then you register the objects in Databricks. The exact credential creation is usually done in Catalog Explorer or through the API, because it needs cloud-specific values. Once a storage credential exists, you can create an external location in SQL:
CREATE EXTERNAL LOCATION IF NOT EXISTS landing_zone
URL 's3://my-bucket/landing'
WITH (STORAGE CREDENTIAL landing_credential)
COMMENT 'Raw files delivered by upstream systems';You need the CREATE EXTERNAL LOCATION privilege on the metastore and CREATE EXTERNAL LOCATION on the storage credential to do this. Metastore admins hold these by default.
Before sharing a new location, test it. In Catalog Explorer, the Test connection action validates that the credential can read, write, and delete in the path. A failure here almost always points to an IAM trust policy or a role permission issue in the cloud account, not a Unity Catalog grant.
Granting access to the credential itself
Storage credentials are securable objects as well, with their own privileges:
| Privilege | What it allows |
|---|---|
| `CREATE EXTERNAL LOCATION` | Create external locations that use the credential |
| `CREATE EXTERNAL TABLE` | Create external tables directly using the credential |
| `READ FILES` | Read files directly using the credential |
| `WRITE FILES` | Write files directly using the credential |
Prefer granting on external locations over granting on credentials. A credential often has broad cloud permissions, and a grant on it applies to everything that identity can reach. An external location is limited to one path. Keep credential grants to a small admin group.
Worked example
A data engineering team ingests files from a landing path, then publishes tables for analysts. The design:
- A storage credential
landing_credentialmaps to a cloud role that can reach only the landing bucket. - An external location
landing_zonepoints ats3://my-bucket/landing. - The
data-engineersgroup getsREAD FILESandCREATE EXTERNAL TABLEon the location. - The
data-analystsgroup gets nothing on the location. They query tables in a schema, usingSELECTon the tables.
GRANT READ FILES ON EXTERNAL LOCATION landing_zone TO `data-engineers`;
GRANT CREATE EXTERNAL TABLE ON EXTERNAL LOCATION landing_zone TO `data-engineers`;
CREATE TABLE main.sales.raw_orders
USING DELTA
LOCATION 's3://my-bucket/landing/orders';
GRANT SELECT ON TABLE main.sales.raw_orders TO `data-analysts`;A member of data-engineers can create raw_orders. A member of data-analysts can query it, but cannot list or read s3://my-bucket/landing/orders as files. If an analyst tries, Unity Catalog denies the request because the analyst holds no privilege on the external location.
Common errors
- Permission denied when creating an external table. The user lacks
CREATE EXTERNAL TABLEon the covering external location, or lacksCREATE TABLEon the schema. Both are required. - No external location covers the path. The URL must fall inside a registered external location. Check for a typo in the scheme or bucket name, or a trailing path that sits outside the registered URL.
- Overlapping path error. The path overlaps another external table, a volume, or managed storage. Move the data or choose a different path.
- Test connection fails. The cloud role does not trust Databricks, or it lacks permission on the bucket. Fix it in the cloud account.
- Analysts can read files through a grant meant for tables. Review
SHOW GRANTS ON EXTERNAL LOCATIONand removeREAD FILESfrom broad groups.
Summary
Unity Catalog controls cloud storage through two objects. A storage credential holds the cloud identity, and an external location ties it to a path. Users receive privileges on the external location and never see the underlying cloud credentials. Direct file privileges bypass table-level protections, so restrict them to engineering groups and give consumers access through tables and views.
Exercise
An analyst group has SELECT on main.sales.raworders, an external table stored at s3://my-bucket/landing/orders. The group also holds READ FILES on the external location landingzone, which covers s3://my-bucket/landing. A row filter on raw_orders hides non-US rows. Can the analysts still see non-US rows, and what should you change?
Show answer
Yes. With READ FILES on landingzone, analysts can read the underlying files directly, and direct file reads bypass the row filter. Revoke READ FILES on landingzone from the analyst group (REVOKE READ FILES ON EXTERNAL LOCATION landing_zone FROM data-analysts) so they can only reach the data through the table, where the row filter applies.
Exercise
Why is it better to grant privileges on an external location than on the storage credential it uses?
Show answer
A storage credential represents a cloud identity that may reach many paths, so a grant on it can expose everything that identity can access. An external location is limited to a single path, so a grant on it gives access only to that path. Credential grants should stay with a small admin group.