How to Configure Databricks Mask Function

Published
Length
3 min read

Luis Felipe Dias

All posts

The databricks mask function rewrites sensitive column values during query execution based on user roles. You set it up by linking a SQL masking rule to specific table columns. Data teams store emails, phone numbers, card numbers, and national IDs in shared tables. Analysts and apps need to read these tables every day to do their jobs. Raw values create big privacy risks if every user can read every single field. Column masking lets teams share tables while rewriting private fields in the query

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.

The databricks mask function rewrites sensitive column values during query execution based on user roles. You set it up by linking a SQL masking rule to specific table columns.

Data teams store emails, phone numbers, card numbers, and national IDs in shared tables. Analysts and apps need to read these tables every day to do their jobs. Raw values create big privacy risks if every user can read every single field. Column masking lets teams share tables while rewriting private fields in the query results.

How the databricks mask function works in practice

The databricks mask function works by checking who runs a query at that exact moment. You write a custom SQL function that checks the group or role of the user. Then you attach that function to a table column inside your central data catalog.

When a query runs, the catalog checks the user role against your custom rule. If the user belongs to an approved group, the query returns the real column value. If the user lacks that role, the rule rewrites matched fields in the results. It swaps uppercase letters, lowercase letters, and digits with safe placeholder characters instead.

This setup affects all people, service principals, and automated workloads that query the table. A safe default rule masks the column for everyone except one specific admin group. You should never make open read permissions the default state for sensitive columns. Start by locking down every column that holds card numbers, emails, or phone numbers. Then grant clear exceptions only to the specific roles that need raw values.

How to apply column rules across your data catalog

Managing masks one table at a time takes too much effort for large teams. Modern data catalogs let you group similar columns using tags across all your schemas. You can tag every column that holds national IDs or phone numbers during table creation.

Still, schema changes can break your setup if engineers rename columns or build new tables. Data teams should review new tables every week to find untagged sensitive columns early. Keeping a clean list of role groups also stops permission drift over time. When a user changes jobs, remove them from old groups right away.

Serverless Function Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to check and audit static masking rules

After you set up a mask rule, you must test it with different roles. Log in with a test account that lacks the privileged group role first. Run a simple read query on the target table and check the returned output. Verify that the rule rewrites emails, card numbers, and national IDs as expected.

Next, check the system audit logs to see who queries these protected tables. Catalog rules only apply inside the data platform where you defined them. Static rules have clear limits once a privileged session logs in and starts running queries. If an admin account runs a query, the platform returns all raw data fields. If a shared service account has broad permissions, every person using it gets full visibility.

Static catalog masks also depend on engineers tagging every new table and column on time. If someone creates a copy of a table, the new copy might lose its mask. Teams also run ad hoc scripts, notebooks, and external tools that query many different databases. Relying only on catalog rules across dozens of separate systems leaves big operational gaps. You have to maintain separate group lists and custom SQL functions in every single database. Auditing all those separate logs takes hours of manual work during security reviews.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Does the databricks mask function change the data stored on disk?

No, the function never alters the actual data stored inside your cloud storage files. It only rewrites matched fields in the query results when a user reads the table.

What types of sensitive data should teams mask with column rules?

Teams use column rules to mask emails, phone numbers, card numbers, and national IDs. This lets analysts run group counts and joins while hiding raw values in the output.

What happens when a privileged user exports data from a masked table?

An approved role gets the unmasked values when they run a query on the table. Once they export those results to a local file, the catalog rule cannot protect them.

The query runs. The emails stay hidden.