Identity attributes in Unity Catalog ABAC policies (Beta)
Identity attributes in ABAC policies are in Beta. To use them, an account admin must turn on the Identity Attributes in ABAC Policies preview from the account console Previews page. See Manage account-level previews.
What are identity attributes?
Identity attributes are properties of a user, such as their department or country. Each attribute has a name and a value. For example, a user's department can be hr and their country can be germany.
Use them in row filter and column mask policies to control access based on who runs the query, without creating separate groups for every combination of user properties. For example, you can mask employee addresses for everyone outside hr, or filter sales transactions by the user's country and division.
Identity attributes are synced from your identity provider. The following attributes are available: department, division, organization, costCenter, title, userType, locality, region, and country.
Identity attribute functions
Identity attributes can have multiple values. For example, a user's region attribute can contain both EMEA and US.
Use the following functions to evaluate identity attributes in a policy's WHEN clause or in its filtering or masking UDF:
Function | Use it in | Returns |
|---|---|---|
|
|
|
|
|
|
| UDF |
|
To mask data for everyone outside hr, including users without a department value, use WHEN NOT has_identity_attribute_value('department', 'hr'). See Row filter and column mask policy evaluation and runtime behavior.
user_identity_attribute_values only supports returning the attribute values of the user running the statement (session user), so its first argument must be session_user(). See Authorized user and session user. To use this function in a policy UDF, the querying users need serverless compute or Databricks Runtime 19 and above. Queries from other compute types throw an error.
Attribute names and values are case-sensitive. For example, finance and Finance don't match.
Policy examples
The following examples show how to use these functions in a policy. For the full steps, see Create a policy with identity attributes:
- Mask employee addresses for everyone outside hr. In the
WHENclause of the column mask policy:WHEN NOT has_identity_attribute_value('department', 'hr') - Filter sales transactions based on the country of the querying user. In the row filter UDF:
RETURN array_contains(user_identity_attribute_values(session_user(), 'country'), row_country); - Mask columns unless the user's department owns the table. In the
WHENclause of the column mask policy:WHEN NOT has_identity_attribute_tag_match('department', 'owning_department')
Configure attribute syncing from your identity provider
An account admin can configure attribute syncing from your identity provider through the mechanism that you already use for identity management: automatic identity management or System for Cross-domain Identity Management (SCIM) provisioning. To check which mechanism your account uses, click Security in the account console and open the Identity provider setup tab.
- SCIM
- Automatic identity management
Databricks supports only SCIM 2.1 for attribute sync.
- Check whether your SCIM connector already sends attributes:
- As an account admin, log in to the account console.
- In the sidebar, click User management.
- On the Users tab, find your own user.
- Click the Identity attributes tab.
- If the attributes that you need already have values, you don't need to configure anything else. If they show an en dash (–), Databricks hasn't received them from your identity provider. Add the missing attributes to the SCIM connector app there, and make sure that the connector uses account SCIM 2.1. For the steps for Okta and Microsoft Entra ID, see Configure a SCIM connector.
- Send a test user to Databricks, and check the user's Identity attributes tab again. Most identity providers can push a user's information on demand, such as Provision on demand in Microsoft Entra ID or Force Sync in Okta. Attributes appear about five minutes after your identity provider sends them. If it can't push on demand, attributes typically arrive within 40 minutes.
With automatic identity management, you choose which attributes to sync with the Identity Attribute Control List preview. A user's attributes are updated within about five minutes after the user signs in.
- Turn on the Identity Attribute Control List preview:
- As an account admin, log in to the account console.
- In the sidebar, click Previews.
- Turn on Identity Attribute Control List.
- Select the attributes to sync:
- In the sidebar, click Security.
- Click the Identity provider setup tab.
- In the Identity management section, under Configure identity attributes, click Manage attributes.
- Select the attributes that you want to use, such as Department and Country, and click Save.
- Confirm that the attributes synced:
- In a separate tab, log out and log back in to the workspace. Attributes are refreshed on login.
- In the account console sidebar, click User management.
- On the Users tab, find your own user.
- Click the Identity attributes tab. Attributes without a value show an en dash (–).
Create a policy with identity attributes
The following steps show how to create a row filter policy and a column mask policy with identity attributes. With the row filter policy, users see only the rows where the country column matches their own country, in every table in the prod.sales schema with a column tagged country_column. With the column mask policy, everyone outside the hr department sees **** in columns tagged pii with the value address.
Before you start, confirm with an account admin that identity attributes have been configured. See Configure attribute syncing from your identity provider.
- Row filter
- Column mask
-
Create a UDF that uses the
user_identity_attribute_valuesfunction to check whether the row's country matches any of the user's country identity attribute values. Users without a value for this attribute can't access any rows:SQLCREATE FUNCTION prod.governance.is_users_country(row_country STRING)RETURNS BOOLEANRETURN array_contains(user_identity_attribute_values(session_user(), 'country'),row_country); -
Tag the
countrycolumn and create a row filter policy. The policy uses thecountry_columntag to identify which columns to pass to the UDF:SQLALTER TABLE prod.sales.ordersALTER COLUMN country SET TAGS ('country_column' = '');CREATE POLICY orders_by_countryON SCHEMA prod.salesROW FILTER prod.governance.is_users_countryTO `account users` EXCEPT `sales_admins`FOR TABLESMATCH COLUMNS has_tag('country_column') AS country_colUSING COLUMNS (country_col);You can also create the policy in Catalog Explorer or with the REST API. See Create and manage row filter and column mask policies.
-
Test the policy. Query
prod.sales.orders. You see only the orders for your own country. Members ofsales_adminsstill see all rows, because the group is in the policy'sEXCEPTclause.
-
Create the masking UDF. This example masks a whole column.
SQLCREATE FUNCTION prod.governance.mask_value(val STRING)RETURNS STRINGRETURN '****'; -
Tag the column and create the policy. Add the condition on the user's attribute to the policy's
WHENclause. The mask applies unless the user'sdepartmentishr:SQLALTER TABLE prod.hr.employeesALTER COLUMN home_address SET TAGS ('pii' = 'address');CREATE POLICY mask_addresses_outside_hrON SCHEMA prod.hrCOLUMN MASK prod.governance.mask_valueTO `account users`FOR TABLESWHEN NOT has_identity_attribute_value('department', 'hr')MATCH COLUMNS has_tag_value('pii', 'address') AS address_colON COLUMN address_col; -
Test the policy. Query
prod.hr.employees. If yourdepartmentishr, you see the home addresses. Otherwise, you see****.
Use identity attributes to prevent group and policy explosion
When access depends on multiple user properties, such as department, country, or division, group-based access control can quickly become difficult to manage. You may need a separate group for every combination of values, along with hardcoded group checks in UDFs or separate policies. As new values are added, the number of groups and the effort to maintain access rules grow.
Identity attributes let you use user properties already available in your identity provider directly in access rules, without the need to represent every combination through groups.
The following examples show how this simplifies row filters and column masks.
Row filtering example
Suppose users should see only the rows in prod.sales.orders for their own division and country, and there are 5 divisions and 10 countries.
If you encode this through one group for each combination of division and country, you end up with 50 groups, and you need to hardcode all of them in the UDF through is_account_group_member(). This setup is cumbersome to create and maintain: when a country or division is added, you need new groups and new checks in the UDF.
-- With groups: one group and one check for each division x country combination
CREATE FUNCTION prod.governance.filter_orders(row_division STRING, row_country STRING)
RETURNS BOOLEAN
RETURN
(is_account_group_member('retail_france') AND row_division = 'retail' AND row_country = 'france')
OR (is_account_group_member('retail_germany') AND row_division = 'retail' AND row_country = 'germany')
OR (is_account_group_member('wholesale_france') AND row_division = 'wholesale' AND row_country = 'france')
-- ... 47 more checks, one for each remaining division and country group
With identity attributes you can write a single policy with a simple UDF that doesn't need to be changed when new countries or divisions are added.
-- With identity attributes: one check that covers all values for division and country
CREATE FUNCTION prod.governance.filter_orders(row_division STRING, row_country STRING)
RETURNS BOOLEAN
RETURN array_contains(user_identity_attribute_values(session_user(), 'division'), row_division)
AND array_contains(user_identity_attribute_values(session_user(), 'country'), row_country);
Column masking example
Suppose everyone can query the tables in the prod catalog, but columns tagged confidential should be visible only to users in the department that owns the table, and there are 8 departments. Each table has a governed tag owning_department.
If you encode this through groups, you need 8 policies, one for each department, that masks the confidential columns for everyone outside that department's group. When a department is added, you need a new group and a new policy.
-- With groups: one group and one policy for each department
CREATE POLICY mask_confidential_finance
ON CATALOG prod
COLUMN MASK prod.governance.mask_value
TO `account users` EXCEPT `finance` -- The finance group is exempt from the mask...
FOR TABLES
WHEN has_tag_value('owning_department', 'finance') -- ...for the tables that they own
MATCH COLUMNS has_tag('confidential') AS confidential_col
ON COLUMN confidential_col;
-- Repeated 7 more times, each with another department in both EXCEPT and WHEN
With identity attributes you can express this in a single policy that compares the table's owning_department tag with the user's department. The policy doesn't need to be changed when new departments are added.
-- With identity attributes: one policy for every department
CREATE POLICY mask_confidential_outside_owning_department
ON CATALOG prod
COLUMN MASK prod.governance.mask_value
TO `account users`
FOR TABLES
WHEN NOT has_identity_attribute_tag_match('department', 'owning_department')
MATCH COLUMNS has_tag('confidential') AS confidential_col
ON COLUMN confidential_col;
Limitations
has_identity_attribute_valueandhas_identity_attribute_tag_matchare not supported in GRANT or DENY policies.- Identity attributes are available on users only, not on service principals or groups.
Don't store sensitive information in identity attributes. Their values can be read through the account APIs.