How to Configure Dbt Snowflake Masking Policy
A dbt snowflake masking policy sets column rules to rewrite sensitive values during warehouse queries. You set it up safely by tying post-hooks and column tags to warehouse roles. Data teams build hundreds of tables every day in the cloud warehouse. Raw data often holds sensitive details like emails, phone numbers, and card numbers. If you copy these columns into reporting tables without rules, every analyst reads them. Putting masking rules into your data transformation project fixes this gap
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 dbt snowflake masking policy sets column rules to rewrite sensitive values during warehouse queries. You set it up safely by tying post-hooks and column tags to warehouse roles.
Data teams build hundreds of tables every day in the cloud warehouse. Raw data often holds sensitive details like emails, phone numbers, and card numbers. If you copy these columns into reporting tables without rules, every analyst reads them. Putting masking rules into your data transformation project fixes this gap at build time.
How a dbt snowflake masking policy works
Snowflake uses column rules to check the active role when a query runs. Based on that role, the warehouse shows the real value or rewrites matched fields. When you manage this in dbt, you store the rule logic in version control. Your project applies the rule each time it builds a model or view.
This setup affects two main groups of principals in your warehouse. First, the transformation service user needs high permissions to create and attach rules. Second, human analysts and reporting apps run under lower roles that trigger the rewrite. For example, a finance role might read full card numbers for billing checks. A marketing role querying the same table gets a masked string instead.
To keep safe defaults, start with a deny-by-default rule design. Rewrite the column value for every role except a short list of approved roles. Use column tags in your schema files to mark emails and national IDs. Then use project post-hooks to read those tags and attach the right rule.
You should also split the rule owner from the transformation role where possible. If one role owns both tables and rules, any user with that role bypasses masking. Keep your production build role locked down so humans cannot log in with it.
How to check and audit column rules
Every time your project builds a table, you must check that the rules stay attached. Note that a full table rebuild drops the old table and makes a new one. If your post-hook fails or skips a model, the new table has no masking rule. You can query the warehouse metadata views to list all columns with active rules.
Snowflake Access Control + Data Masking (Static): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To test the rule, run a sample query under a lower analyst role. Check that the query output rewrites phone numbers, emails, and national IDs as expected. Next, switch to an approved role and check that the real values appear. You should also check the warehouse query history logs to audit who queried tagged columns.
Gaps left open by static warehouse rules
Managing column rules in version control works well for planned reporting tables. Still, static rules leave gaps when engineers or apps log in with broad permissions. The transformation service account itself holds the permissions needed to read raw source tables. Anyone who uses those service keys or runs an ad-hoc session skips role checks.
Also, dbt rules only protect the warehouse where you define them. Many teams also query Postgres, MySQL, or internal tools that lack native masking rules. Maintaining separate role hierarchies and hook macros across five different data stores takes heavy effort. If a developer runs a quick fix against a raw source, static tags do not help.
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
What happens to a masking rule when dbt rebuilds a table?
When dbt runs a full refresh, it drops and recreates the permissions table. Your project must re-apply the masking rule through a post-hook or tag during that same run.
Which sensitive fields should we tag first in our project?
Start by tagging columns that hold emails, phone numbers, card numbers, and national IDs. These fields carry high risk and follow clear formats across your models.
Can the dbt service role read unmasked data during builds?
Yes, the service role needs to read raw values when it builds downstream tables. Keep this role restricted to automated build jobs so humans do not query with it.
Related guides
In this post