Sub topic 3
Controlling Access to Cloud Storage
Assume you know basic SQL, Databricks workspaces, and groups. Unity Catalog access is evaluated through both Unity Catalog privileges and the underlying cloud storage configuration.
Controlling access to cloud storage
A storage credential stores the identity Unity Catalog uses to access cloud storage. An external location combines that credential with a cloud path. Grant access to the external location, not directly to the storage account.
GRANT CREATE EXTERNAL TABLE
ON EXTERNAL LOCATION landing_zone
TO `data-engineers`;Use separate external locations for different trust boundaries, such as raw and curated data. Avoid granting broad storage access when a narrower location is sufficient.
Restricting data with dynamic views
A dynamic view calculates its output for each query. It can hide sensitive values based on the querying user's group membership.
CREATE VIEW main.sales.employees_redacted AS
SELECT
id,
name,
CASE
WHEN is_account_group_member('hr') THEN ssn
ELSE 'REDACTED'
END AS ssn
FROM main.sales.employees;Grant users access to the view rather than the base table. Otherwise, they may bypass the view.
Row filters and column masks
A row filter removes rows from query results. A column mask changes a column value while preserving the row.
CREATE FUNCTION main.sales.us_only(region STRING)
RETURNS BOOLEAN
RETURN is_account_group_member('admins') OR region = 'US';
ALTER TABLE main.sales.orders
SET ROW FILTER main.sales.us_only ON (region);
CREATE FUNCTION main.sales.mask_email(email STRING)
RETURNS STRING
RETURN CASE
WHEN is_account_group_member('pii_readers') THEN email
ELSE '***'
END;
ALTER TABLE main.sales.customers
ALTER COLUMN email SET MASK main.sales.mask_email;Test filtered and unfiltered paths with representative groups. Policies can fail if a user can query an unrestricted copy of the data.
Limiting catalogs to specific workspaces
Workspace bindings restrict where a catalog can be accessed. Use them to keep production data unavailable from development workspaces. Bindings complement privileges; a user needs both a permitted workspace and the required object privileges.
Compute access modes and permission enforcement
Choose compute that supports Unity Catalog enforcement, such as compatible shared or single-user access modes. Unsupported or incorrectly configured compute can prevent access or weaken the expected governance boundary. Confirm the runtime, access mode, and identity used by jobs before production use.
Auditing access with audit logs
Audit logs support investigations and access reviews.
SELECT event_time, user_identity.email, action_name
FROM system.access.audit
WHERE service_name = 'unityCatalog'
ORDER BY event_time DESC
LIMIT 20;Check failed access, privilege changes, ownership changes, and unusual reads.
Designing a least-privilege permission model
Use groups instead of individual grants. Grant the smallest privilege at the narrowest object level. Separate reader, writer, and administrator groups. Centralize ownership in service groups, review permissions regularly, and remove direct grants that bypass the model.
Exercise
Why should a user querying a dynamic view usually lack SELECT on its base table?
Show answer
Without that restriction, the user could query the base table directly and bypass the view's redaction logic.