How to Fetch User and Group Assignments Across Unity Catalog Workspaces in Databricks

Posted by

๐Ÿ” How to Fetch User and Group Assignments Across Unity Catalog Workspaces in Databricks

๐Ÿ“Œ Introduction

As organizations move toward centralized data governance with Databricks Unity Catalog (UC), understanding user and group access across multiple workspaces becomes critical for:

  • Access audits
  • Compliance reporting
  • Cross-team collaboration tracking

But here’s a common misconception:

โ€œIf I fetch group and user assignments from a Unity Catalogโ€“enabled workspace, Iโ€™ll get info for all workspaces using the same UC.โ€

โŒ Wrong!
Even with Unity Catalog, workspace group assignments are scoped to each workspace individually unless you query using account-level APIs.

This blog explains why this happens, and shows you how to properly fetch group-user mappings across workspaces โ€” both at the workspace level and the account level.


๐Ÿง  Understanding the Scope

ComponentScopeAPI to Use
Unity Catalog (catalogs/schemas)Account-levelGET /accounts/<account_id>/groups
Group-to-user assignmentsWorkspace-levelGET /api/2.0/preview/scim/v2/Groups
Workspace access (entitlements)Workspace-levelGET /api/2.0/workspace/<id>/permissions

๐Ÿšง Common Mistake

You run a group listing query on a Unity Catalogโ€“enabled workspace, expecting it to show group-user relationships for all other workspaces linked to the same UC.

Result: Youโ€™ll only get group membership for that specific workspace โ€” not across all.


โœ… Solution 1: Fetch User-Group Mapping via Workspace SCIM API

Use this method if you only care about one specific workspace.

Python Notebook Example:

# Setup
workspace_url = "https://<workspace>.cloud.databricks.com"
token = "Bearer <your-token>"

# Get Groups
resp = requests.get(f"{workspace_url}/api/2.0/preview/scim/v2/Groups", headers={"Authorization": token})
groups = resp.json()["Resources"]

# Loop through groups and print users
for group in groups:
    print(f"Group: {group['displayName']}")
    for member in group.get("members", []):
        user_id = member["value"]
        # Fetch user details
        user = requests.get(f"{workspace_url}/api/2.0/preview/scim/v2/Users/{user_id}", headers={"Authorization": token})
        print(user.json().get("userName", "Unknown"))

โœ… Solution 2: Use Unity Catalog Account-Level APIs

Use this method if you want full visibility across all UC-enabled workspaces:

Step-by-step:

  1. Generate Account-Level Token
  2. Use Account SCIM APIs:
GET /api/2.0/accounts/<account_id>/groups
GET /api/2.0/accounts/<account_id>/users
  1. Use Workspace Listing API to enumerate which groups are assigned to each workspace:
GET /api/2.0/accounts/<account_id>/workspaces
  1. Correlate mappings to build a full picture of which group has access to which workspace or catalog.

๐Ÿงช Bonus: Cross-Workspace Group Audit Script

Need a script to list all workspaces and users assigned per group?

We can loop like this:

# Pseudo code
for workspace in all_workspaces:
    call /scim/v2/Groups on each workspace
    collect group-user info
combine all into one CSV or Delta table

Let me know if you’d like the full working version of this!


๐Ÿ“Ž Summary

Use CaseScopeAPI Required
Audit Unity Catalog access across workspacesโœ… Account-wideAccount-level SCIM + UC Permissions APIs
Check group membership in a workspace๐Ÿšซ Local to workspaceSCIM API /Groups in that workspace only
Global group access visibilityโœ… Cross-workspaceRequires cross-querying or account token

๐ŸŽฏ Summary

Use CaseAPI EndpointToken Scope
Get global UC group-user mappingshttps://accounts.databricks.com/api/...๐Ÿ” Account-level PAT
Get group-user assignments per workspacehttps://<workspace-url>/api/2.0/preview/scim/...๐Ÿ” Workspace PAT
Get catalog/schema/table access privilegesUnity Catalog permissions APIs๐Ÿ” Account-level PAT

๐Ÿ”š Final Thoughts

With Unity Catalog, data governance is centralized โ€” but identity management is still workspace-scoped unless accessed via account APIs.

For full visibility across your enterprise data platform, make sure to:

  • Use account-level tokens
  • Query account-wide group and user APIs
  • Document and consolidate group-user relationships regularly

Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x