Sub topic 3
Who gets access: users, service principals and groups
This chapter assumes you know basic SQL, can use the Databricks SQL editor or a notebook, and understand role-based access control. You should also know the securable hierarchy from the previous chapter: metastore, catalog, schema, and the objects inside a schema.
The three kinds of principal
A principal is an identity that can receive privileges in Unity Catalog. There are three kinds.
| Principal | What it represents | Typical use |
|---|---|---|
| User | A person, identified by an email address | Interactive work in notebooks and the SQL editor |
| Service principal | A non-human identity for automation | Jobs, pipelines, CI/CD and API calls |
| Group | A named collection of users, service principals and other groups | The unit you grant privileges to |
Principals are defined at the account level, not inside a single workspace. Unity Catalog sees the same identity in every workspace attached to the metastore. You manage account identities through the account console, SCIM provisioning from your identity provider, or the account APIs.
Why grant to groups
You can grant privileges directly to a user, but this does not scale. When someone changes teams, you must find and edit every grant that names them. When you grant to a group, you change membership once and the access follows.
Groups can be nested. If data-analysts contains emea-analysts, members of emea-analysts receive whatever data-analysts has been granted.
Referring to principals in SQL
In SQL, wrap a group name in backticks. Use the email address for a user. Use the application ID (a UUID) for a service principal.
GRANT SELECT ON TABLE main.sales.orders TO `data-analysts`;
GRANT SELECT ON TABLE main.sales.orders TO `[email protected]`;
GRANT SELECT ON TABLE main.sales.orders TO `3f6c1a52-8b7e-4c1d-9a5e-2d7f0b9c4e11`;The first line is the preferred pattern. The other two work, but they tie access to one identity.
Checking who you are and what groups you are in
Two built-in functions help when you test permissions. current_user() returns the identity running the query. is_account_group_member() tests membership in an account-level group.
SELECT current_user() AS me,
is_account_group_member('data-analysts') AS in_analysts;Later chapters use is_account_group_member() inside dynamic views, row filters and column masks, so it is worth trying now.
Common errors
- Granting to a workspace-local group. Unity Catalog grants need account-level groups. A group that exists only in one workspace will not be found.
- A typo in a principal name. The statement fails because the principal does not exist in the account. Check the exact spelling in the account console.
- Using a display name for a service principal. SQL needs the application ID, not the friendly name.
- Expecting a new group member to see changes at once. Membership changes can take a short while to reach running compute. If a fresh member is denied, start a new session and retry.
- Forgetting parent privileges. A group with
SELECTon a table still cannot query it withoutUSE CATALOGandUSE SCHEMAon the parents. The next chapters cover this.
A practical convention
Name groups by role or function, such as data-analysts or data-engineers. Put service principals in groups just like people, so a job gets the same access as the team it serves. Reserve direct user grants for short-lived exceptions, and remove them when the need ends.
Exercise
A new analyst joins the team, and a nightly job runs under a service principal that needs the same read access to main.sales.orders. How should you grant that access, and which function would you use in a query to confirm the analyst is covered?
Show answer
Add both the analyst and the service principal to the account-level group data-analysts, then grant SELECT (plus USE CATALOG and USE SCHEMA on the parents) to that group once. Confirm membership by running SELECT isaccountgroup_member('data-analysts'); as the analyst. A true result shows the group applies.