Sub topic 9
Principals and ownership
This chapter assumes you can write basic SQL and know what a Unity Catalog metastore, catalog, schema, and table are. It covers who can hold privileges and who controls each object.
What a principal is
A principal is an identity that Unity Catalog can authorize. Privileges are always granted to a principal. Unity Catalog has three kinds:
- User: one person, identified by email address.
- Service principal: an identity for automation such as jobs, pipelines, and CI/CD tools. It is not a person and has no password login.
- Group: a named set of users, service principals, and other groups.
Groups are the preferred grant target. When someone joins or leaves a team, you change group membership once. You do not edit every grant. In SQL, write group names in backticks, as in data-analysts. Backticks are required when a name contains a hyphen or other special character.
What ownership means
Every securable object has exactly one owner. A securable object is anything you can govern: a catalog, schema, table, view, volume, function, or one of the storage objects. By default, the principal that creates an object owns it.
An owner can do the following:
- Use and modify the object.
- Grant and revoke privileges on it.
- Drop it.
- Transfer ownership to another principal.
Ownership does not flow downward as a privilege. Owning a catalog lets you manage the catalog itself, and you can create schemas in it. It does not make you the owner of schemas that other people create in that catalog. The owner of a schema owns the tables they create there.
Worked example
Suppose a user creates the catalog and schema from earlier chapters. That user now owns both, and nobody else can use them until they grant access.
CREATE CATALOG IF NOT EXISTS dev;
CREATE SCHEMA IF NOT EXISTS dev.sales;Check the current owner with DESCRIBE:
DESCRIBE SCHEMA EXTENDED dev.sales;The output includes an Owner row. Now transfer ownership to a group:
ALTER SCHEMA dev.sales OWNER TO `data-engineers`;Do the same for a table:
ALTER TABLE dev.sales.orders OWNER TO `data-engineers`;To run ALTER ... OWNER TO, you must be the current owner (or hold a higher-level administrative role) and you must be allowed to assign ownership to the new principal.
Why groups should own objects
An object owned by an individual is a risk. If that person leaves the company, their account is removed and the object has no active owner. Nobody can manage its grants without an administrator stepping in. Service principals have the same problem if you tie a pipeline's tables to one engineer's identity.
A common practice is to make a group the owner of production catalogs and schemas. Pipelines run as a service principal that is a member of, or is granted rights by, that group.
Owners versus administrators
Two other roles sit above ordinary ownership:
| Role | Scope | Typical use |
|---|---|---|
| Account admin | The whole account | Creates metastores and manages principals |
| Metastore admin | One metastore | Manages objects and grants across the metastore |
| Object owner | One object | Manages that object and its grants |
Keep the number of admins small. Most day-to-day governance should happen through object owners that are groups.
Common errors
- Granting to individuals. The grants pile up and are hard to audit. Grant to groups.
- Assuming the catalog owner owns everything below it. Ownership applies to one object only.
- Leaving ownership with a departed employee. Transfer ownership to a group before removing an account.
- Forgetting backticks around group names that contain hyphens.
Exercise
A data engineer creates the schema dev.sales and the table dev.sales.orders, then leaves the company. What should have been done beforehand to avoid an unmanaged object, and which SQL statement does it?
Show answer
Ownership should have been transferred to a group, for example with ALTER SCHEMA dev.sales OWNER TO data-engineers; and ALTER TABLE dev.sales.orders OWNER TO data-engineers;. Transferring the schema alone does not change the table's owner, so each object needs its own statement.
Exercise
You own the catalog dev. Another user creates a schema dev.test in it. Do you own dev.test?
Show answer
No. The creator owns dev.test. You own only the catalog itself, although you can still manage the catalog and create schemas in it.