How to Configure Databricks Column Mask

Published
Length
3 min read

Luis Felipe Dias

All posts

A databricks column mask controls who can read specific fields in a table. You set it up by linking a SQL function to a Unity Catalog column. This setup rewrites sensitive values at query time based on user group membership. Teams use these rules to hide emails, phone numbers, and card numbers in shared tables. How a databricks column mask works in Unity Catalog Unity Catalog applies column masks when a user runs a read query. First, an admin writes a custom SQL function in the catalog. That

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

A databricks column mask controls who can read specific fields in a table. You set it up by linking a SQL function to a Unity Catalog column. This setup rewrites sensitive values at query time based on user group membership. Teams use these rules to hide emails, phone numbers, and card numbers in shared tables.

How a databricks column mask works in Unity Catalog

Unity Catalog applies column masks when a user runs a read query. First, an admin writes a custom SQL function in the catalog. That function checks the user role or group for the active session. If the user belongs to an allowed group, the query returns the real value. If not, the function rewrites the matched field with a static string or null.

Next, the admin attaches this function to a specific table column. From that point on, every query against that column runs the function first. The underlying data on disk never changes during this process. Only the query result changes based on who logged in to run the job. This applies to analysts using notebooks, BI tools, and automated jobs.

Safe defaults matter when you write these catalog functions. Always set the default return value to the masked output. Grant full read rights only to specific groups, not to individual user accounts. Keep the mask function in a secure schema where analysts cannot edit it. If an analyst can change the function, they can remove the mask rule.

How to manage group rules for masked columns

Good role design keeps your catalog rules clean and easy to check. Create account-level groups in your workspace for each data sensitivity tier. Have your mask function check those group names during each query run. When a team member changes roles, you only update their group membership. You do not need to rewrite the SQL function on the table.

Watch out for performance traps when you design these functions. Keep the logic inside the function simple and fast. Avoid joining other large tables inside a mask function. Complex joins run on every row and slow down warehouse queries for everyone. Stick to basic group checks and simple text replacement rules for national IDs or card numbers.

End-to-End Encryption + Column-Level Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Testing rules and checking what static setup leaves open

You must test your mask rules before opening tables to the wider team. Log in with a test account that lacks the privileged group role. Run a select query on the protected table and check the output. Verify that emails and phone numbers appear as redacted text in the results. Also test aggregate queries and filters to see if users can guess hidden values.

Catalog audit logs help you track who changes these table rules over time. Review your system tables to see when admins alter tables or update functions. Still, static catalog setup still leaves several operational gaps open. Once a privileged user or service account logs in, they hold standing access. Every query in that session returns raw data without extra checks.

Also, Unity Catalog rules only work inside that specific workspace. Most teams also run Postgres, MySQL, and NoSQL databases alongside their lakehouse. Maintaining separate SQL functions across ten different database types takes huge effort. Static catalog masks also cannot require real-time peer approval before a user runs an ad-hoc query. They cannot block a privileged admin from dumping a full table during a live session.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Does a databricks column mask change the stored data on disk?

No, the underlying table files stay untouched on storage. The engine runs the mask function at query time and rewrites matched fields in the results.

Who can attach or remove a mask on a table?

A user needs ownership of the table or specific alter privileges in Unity Catalog. They also need execute rights on the SQL function used for the mask.

Can users bypass a column mask using filters or joins?

Unity Catalog evaluates the mask before applying user filters or joins. Still, bad function logic can still leak clues if an analyst tests specific return patterns.

The query runs. The emails stay hidden.