Sub topic 15
Designing a least-privilege permission model
This chapter pulls the earlier pieces together into a repeatable design. It assumes you know the object hierarchy (metastore, catalog, schema, table), how GRANT and REVOKE work, how privileges are inherited, how ownership works, and how workspace bindings limit catalogs. Least privilege means each principal gets the smallest set of privileges it needs to do its job, and nothing more.
Start from groups, not people
Grant privileges to account groups. Users join and leave groups, and the grants stay the same. Name groups by role, such as data-analysts or data-engineers, so a reviewer can read the intent of a grant.
Avoid granting to individual users except for short-lived exceptions. Individual grants are hard to find and easy to forget.
Grant high in the tree, but only what is safe to inherit
Inheritance lets one grant on a schema cover every current and future table in it. That keeps the model small. It also means a grant on a catalog reaches everything below it.
A workable pattern:
- Grant
USE CATALOGon the catalog andUSE SCHEMAon the schema. These let a principal see and reach objects but do not expose data. - Grant
SELECTon the schema for read-only consumers. - Grant write privileges such as
MODIFYonly to the engineering groups that load the data.
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `data-analysts`;
GRANT SELECT ON SCHEMA main.sales TO `data-analysts`;If one table in a schema is sensitive, do not put it in a schema that analysts can read. Move it to its own schema. Inheritance cannot exclude a single child, so the structure of your schemas is part of your security design.
Separate ownership from access
Make a group the owner of each catalog and schema, so management does not depend on one person.
ALTER TABLE main.sales.orders OWNER TO `data-engineers`;Owners can grant access on their objects, so keep owner groups small. Consumers should not own what they read.
Layer finer controls only where needed
Use the lightest control that meets the requirement.
| Requirement | Control |
|---|---|
| Whole table or schema is off limits | No grant, or `REVOKE` |
| Some users see a sensitive column | Column mask |
| Users see only their region's rows | Row filter |
| A catalog should exist only in some workspaces | Workspace binding |
| Cloud storage paths need access | External location grants |
Row filters and column masks keep one copy of the data. Dynamic views work too, but users must be granted the view and not the underlying table.
Reduce the blast radius
- Bind production catalogs only to production workspaces.
- Give service principals only the privileges their job needs, and run automated jobs as them instead of as a person.
- Keep
CREATE EXTERNAL TABLEon external locations limited to engineering groups. - Limit the number of metastore and account admins.
Verify and keep checking
Check what is in place with SHOW GRANTS, and review activity in the audit system table.
SHOW GRANTS `data-analysts` ON SCHEMA main.sales;
SELECT event_time, user_identity.email, action_name
FROM system.access.audit
WHERE service_name = 'unityCatalog'
ORDER BY event_time DESC
LIMIT 20;Review grants on a schedule. Look for grants to individual users, broad grants on catalogs, and groups that nobody uses.
Common errors
- Granting
SELECTwithoutUSE SCHEMA. The query still fails, because the parent privileges are missing. - Granting on a catalog for convenience. This exposes every schema, including ones created later.
- Letting one person own everything. Management stalls when they leave.
- Treating a row filter as the only protection. Also check who can read the underlying storage.
Exercise
Analysts need to read every table in main.sales except main.sales.salaries. Why is a SELECT grant on the schema a poor fit, and what would you do instead?
Show answer
A schema grant is inherited by every table in it, including salaries, and you cannot exclude one child. Move salaries to a separate schema that analysts cannot read, or grant SELECT table by table. A column mask or row filter can also limit what analysts see in that table.