Sub topic 3
Who gets access: users, service principals and groups
Every permission in Unity Catalog is granted to a principal. This chapter covers the three kinds of principal, where they are defined, and how to refer to them in SQL. It assumes you can write basic SQL, know your way around a Databricks workspace or the SQL editor, and understand role-based access control. You don't need to have run a GRANT statement before.
What a principal is
A principal is an identity that can be given privileges. Unity Catalog recognizes three kinds:
| Principal | 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, identified by an application ID | Jobs, pipelines, CI/CD, applications that call Databricks APIs |
| Group | A named collection of users, service principals and other groups | The unit you grant privileges to |
Privileges attach to securable objects such as catalogs, schemas and tables. Principals are the other half of that relationship. Without a principal, a grant has no recipient.
Identities live in the account
Unity Catalog works with account-level identities. You create or sync users, service principals and groups once in the Databricks account. You then assign them to the workspaces where they should work. This is called identity federation. A grant made on a table applies in every workspace attached to the same metastore, because the identity is the same everywhere.
There are three common ways to populate the account:
- Create identities by hand in the account console.
- Provision them from your identity provider (IdP), such as Microsoft Entra ID or Okta, using SCIM. SCIM is a standard protocol for syncing users and groups.
- Use automatic identity management, where Databricks pulls identities from Microsoft Entra ID without a separate SCIM connector.
Syncing from the IdP is the better choice for most teams. When someone leaves the company and is removed from the IdP, their access disappears with them. Hand-maintained identities drift out of date.
Users
A user is identified by an email address. In SQL you refer to a user by that address, wrapped in backticks:
GRANT SELECT ON TABLE main.sales.orders TO `[email protected]`;The backticks are required. Without them, the @ and . characters cause a parse error.
Granting to individual users works, but it scales poorly. A catalog with fifty tables and forty analysts means many grants to track, and every personnel change means finding and editing each one. Reserve user-level grants for one-off cases.
Service principals
A service principal is an identity for code, not for a person. Jobs and pipelines should run as service principals so that:
- The job keeps working when an employee leaves or changes teams.
- Audit logs show clearly which actions came from automation.
- The job's access can be limited to exactly what it needs.
A service principal has a display name and an application ID, which is a UUID. In a GRANT statement you use the application ID, not the display name:
GRANT USE CATALOG ON CATALOG main TO `3f2a8c1e-5b7d-4e9a-8c42-1d6f0a9b7e55`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `3f2a8c1e-5b7d-4e9a-8c42-1d6f0a9b7e55`;
GRANT SELECT ON TABLE main.sales.orders TO `3f2a8c1e-5b7d-4e9a-8c42-1d6f0a9b7e55`;The UUID above is a placeholder. Copy the real application ID from the service principal's page in the account console or workspace settings.
Raw UUIDs are hard to read in a list of grants. A cleaner approach is to put the service principal in a group, such as etl-jobs, and grant to the group. The grants then read clearly, and swapping the service principal later requires no grant changes.
Groups
A group is a collection of principals. Granting to a group gives every member the privilege. Adding a person to the group gives them access, and removing them takes it away, with no change to the grants.
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.sales TO `data-analysts`;
GRANT SELECT ON TABLE main.sales.orders TO `data-analysts`;A group name with a hyphen needs backticks too. Without them the hyphen is read as a minus sign.
Nested groups
Groups can contain other groups. Members of the inner group inherit the privileges of the outer group. For example, finance-analysts and sales-analysts can both be members of all-analysts. A grant to all-analysts then reaches both teams. Nesting keeps the number of direct grants small, but deep nesting makes it hard to answer "why can this person see this table?". Keep it to one or two levels.
Built-in groups
Two groups exist by default and are easy to misuse:
account userscontains every user in the account. Granting a privilege to it makes that privilege available to everyone in the account.adminsis the workspace administrators group in each workspace.
Treat a grant to account users as a deliberate decision to publish data broadly. It is not a safe default.
Account groups and workspace-local groups
Older workspaces may contain workspace-local groups. These exist only inside one workspace and were created before identity federation. Unity Catalog privileges can only be granted to account-level groups. If a GRANT fails because the principal cannot be found, check that the group exists in the account and not only in the workspace. Databricks provides a way to convert workspace-local groups to account groups. Do that before you rely on them for Unity Catalog access.
Using group membership in queries
Policies sometimes need to check who is running a query. Two functions look at the caller:
current_user()returns the email or application ID of the caller.is_account_group_member('group')returnstrueif the caller belongs to the named account-level group.
SELECT
current_user() AS who,
is_account_group_member('data-analysts') AS is_analyst;Dynamic views, row filters and column masks, covered in later chapters, build on is_account_group_member. Don't use the older is_member() function for Unity Catalog policies. It checks workspace-local group membership, so it can return false for someone who is in the account group of the same name. That produces a view that hides data from people who should see it, or one that shows data to people who should not.
Inspecting what a principal can do
SHOW GRANTS lists privileges on an object, or the privileges one principal holds on it:
SHOW GRANTS ON TABLE main.sales.orders;
SHOW GRANTS `data-analysts` ON SCHEMA main.sales;The first statement answers "who has access to this table?". The second answers "what does this group have on this schema?". Note that SHOW GRANTS reports grants made on the object itself. It does not show membership. To find out which groups a person belongs to, use the account console or the SCIM API.
Common errors
- Granting to a user instead of a group. Access works until someone changes teams, then nobody knows which grants to clean up. Grant to groups and manage membership in the IdP.
- Forgetting backticks. Emails, hyphenated group names and service principal UUIDs all need them.
- Using the display name of a service principal.
GRANTexpects the application ID. - Principal not found. The group or user may exist only in the workspace, or may not have been synced from the IdP yet. Confirm it appears in the account console.
- Granting to
account usersby accident. This exposes the object to every user in the account. - Using
is_member()in policies. Useis_account_group_member(). - Granting only
SELECT. A principal also needsUSE CATALOGandUSE SCHEMAon the parent objects, as shown above. Principals and privileges are covered together in the next chapters.
Exercise
A nightly job currently runs under a data engineer's personal account and reads main.sales.orders. The engineer is leaving the company. Describe how to restructure the principals so the job keeps working, and name the form of identifier you use in the GRANT statement.
Show answer
Create a service principal for the job and run the job as that service principal. Add the service principal to a group such as etl-jobs, and grant USE CATALOG, USE SCHEMA and SELECT to the group rather than to the engineer. If you grant to the service principal directly, you refer to it by its application ID (a UUID) in backticks, not by its display name. When the engineer leaves, the job is unaffected because its access never depended on that person.
Exercise
A view uses is_member('hr') to show Social Security numbers only to HR staff. An HR analyst who belongs to the account group hr sees REDACTED. What is the likely cause and the fix?
Show answer
is_member() checks workspace-local group membership, and the analyst is a member of the account-level group hr, so the check returns false. Replace it with is_account_group_member('hr'), which checks account-level groups.