Sub topic 9
Principals and ownership
This chapter assumes you can run SQL in a Databricks workspace and that you know the catalog, schema, and table hierarchy from the earlier chapters. It covers who can act in Unity Catalog (principals) and who controls each object (owners). The next chapter builds on this with GRANT and REVOKE.
What a principal is
A principal is an identity that Unity Catalog can authenticate and authorize. Privileges are always granted to a principal, and every action is checked against the principal that performs it. There are three kinds:
| Principal | What it represents | How you write it in SQL |
|---|---|---|
| User | A person, identified by email address | `` `[email protected]` `` |
| Service principal | An identity for automation such as jobs and CI pipelines, identified by an application ID | `` `a1b2c3d4-0000-1111-2222-333344445555` `` |
| Group | A named set of users, service principals, and other groups | `` `data-analysts` `` |
Names that contain @, -, or other special characters must be wrapped in backticks.
These identities are defined once at the account level, not inside a single workspace. A user or group created in the account console can be used in every workspace that shares the metastore. This is why Unity Catalog grants work the same way everywhere.
Groups are the unit of administration
Groups can contain users, service principals, and other groups. A member inherits every privilege granted to the group, including privileges granted to groups that contain it.
Granting to groups instead of individuals has practical benefits:
- Joining or leaving a team changes group membership and leaves the grants alone.
SHOW GRANTSoutput stays short and readable.- Ownership does not break when one person leaves.
Unity Catalog uses account-level groups. Older workspace-local groups are not visible to Unity Catalog, so you cannot grant privileges to them. If a GRANT fails because the principal cannot be found, check that the group exists in the account and not only in one workspace.
Checking who you are
Two built-in functions help when you debug access problems.
SELECT current_user() AS me,
is_account_group_member('data-analysts') AS in_analysts;current_user() returns the identity running the query. is_account_group_member() returns true if that identity belongs to the named account group, directly or through nesting.
Administrative roles
Some principals hold roles that sit above ordinary privileges. Know these, because they explain why some people can see or change objects without any explicit grant.
- Account admin. Manages account-level identities, workspaces, and metastores. Can create and assign metastores.
- Metastore admin. An optional role on a metastore. A metastore admin can manage privileges and ownership of objects in that metastore. Databricks recommends assigning it to a group, keeping it to a small number of people, and not using it for daily work.
- Workspace admin. Manages one workspace: its users, clusters, and settings. This role does not by itself give access to data in Unity Catalog.
A common mistake is to assume that workspace admin means data admin. A workspace admin can still get PERMISSION_DENIED on a table. The data permissions come from ownership, grants, or the metastore admin role.
What ownership means
Every securable object in Unity Catalog has exactly one owner. That includes the metastore, catalogs, schemas, tables, views, volumes, functions, storage credentials, and external locations. By default, the principal that creates an object becomes its owner.
An owner can:
- use the object with all privileges that apply to it;
- grant and revoke privileges on it to others;
- transfer ownership to another principal;
- rename or drop it.
An owner of a catalog or schema can also manage privileges on the objects inside it, so owning a container carries authority over its contents. Metastore admins have the same reach across the whole metastore. A principal holding the MANAGE privilege on an object can also grant, revoke, and transfer.
Ownership is not inherited the way privileges are. If ana creates the schema dev.sales inside a catalog owned by platform-team, then ana owns the schema and platform-team owns the catalog. If someone else later creates a table in that schema, that person owns the table. The catalog and schema owners can still manage grants on it, but they are not its owner.
CREATE SCHEMA IF NOT EXISTS dev.sales;
CREATE TABLE IF NOT EXISTS dev.sales.orders (
order_id BIGINT,
amount DECIMAL(10,2)
);
-- Whoever ran these statements now owns both objects.Viewing the owner
Use DESCRIBE ... EXTENDED to see the owner of an object:
DESCRIBE CATALOG EXTENDED dev;
DESCRIBE SCHEMA EXTENDED dev.sales;
DESCRIBE EXTENDED dev.sales.orders;Each output includes an Owner row. The information_schema views expose the same data in a form you can filter and join:
SELECT table_name, table_owner
FROM dev.information_schema.tables
WHERE table_schema = 'sales';
SELECT schema_name, schema_owner
FROM dev.information_schema.schemata;This is useful for audits. For example, you can list every table in a catalog that is owned by an individual user instead of a group.
Transferring ownership
Use ALTER ... OWNER TO with the object type:
ALTER CATALOG dev OWNER TO `platform-team`;
ALTER SCHEMA dev.sales OWNER TO `sales-data-engineers`;
ALTER TABLE dev.sales.orders OWNER TO `sales-data-engineers`;You can run a transfer if you are the current owner, a metastore admin, or hold MANAGE on the object. You can set the new owner to a user, a service principal, or a group. Setting yourself as the new owner works too, which is how a metastore admin takes over an orphaned object.
Transferring ownership of a schema does not change who owns the tables inside it. Each table keeps its owner until you change it. To move a whole subtree you must transfer each object, which you can script by querying information_schema and generating the statements.
Why groups and service principals should own objects
When an individual user owns an object, that person becomes a single point of failure. If the user leaves and their account is removed, the object has an owner who can no longer act. Only a metastore admin or an account admin can then repair it.
A second problem comes from automation. Suppose a scheduled job runs as a user and creates tables. Those tables are owned by that user. When the user is offboarded, the job breaks and the tables have an inactive owner.
Recommended practice:
- Make groups the owners of catalogs and schemas, for example
platform-teamfor catalogs and one team group per schema. - Run production jobs as service principals, so the tables they create are owned by that service principal.
- If the tables should be owned by a team, have the job run as a service principal and then transfer ownership, or run the job as a member of the owning group in an environment where that is allowed.
- Keep the metastore admin role in a small group.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `PERMISSION_DENIED` on a table although you are a workspace admin | Workspace admin does not grant data access | Ask an owner or a metastore admin for a grant, or have yourself added to a group that has one |
| `GRANT` fails with a "principal not found" style error | The group exists only in one workspace, or the name is misspelled | Create or sync the group at the account level and re-check the spelling and backticks |
| Cannot drop or change a table you can query | `SELECT` does not include ownership rights | Ask the owner for ownership or `MANAGE` |
| A job fails after a colleague leaves | The objects or job ran under that user | Transfer ownership to a group or service principal, and change the job's run-as identity |
| Ownership transfer fails | You are not the owner, a metastore admin, or a holder of `MANAGE` | Ask someone who is |
Summary of the model
- Principals are users, service principals, and groups, all defined at the account level.
- Every securable has one owner, usually the creator.
- Owners have full control over an object and can manage grants on it. Owners of a parent catalog or schema can manage grants on objects inside it.
- Ownership does not cascade to child objects. Privileges can, and the chapter on inheritance covers how.
- Prefer groups and service principals as owners.
Exercise
A data engineer, [email protected], created the table dev.sales.orders and still owns it. She is leaving the company. Write the SQL statement that moves ownership to the group sales-data-engineers, and write a query that lists all tables in dev.sales that are still owned by a person instead of that group.
Show answer
Transfer: ALTER TABLE dev.sales.orders OWNER TO sales-data-engineers; Audit: SELECT tablename, tableowner FROM dev.informationschema.tables WHERE tableschema = 'sales' AND tableowner <> 'sales-data-engineers'; The audit query returns every table whose owner is anything other than the group, including any owned by individual users. Run it as a principal that can see those tables, since informationschema only shows objects the caller may access.
Exercise
You create a schema in a catalog owned by the group platform-team. Another user later creates a table in your schema. Who owns the catalog, the schema, and the table, and who can manage grants on the table?
Show answer
platform-team owns the catalog, you own the schema, and the other user owns the table. Ownership does not cascade. The table's owner can manage its grants, and so can the owner of the schema and the owner of the catalog, because owners of parent containers can manage privileges on child objects. Metastore admins and holders of MANAGE on the table can as well.