feat: column-level Dynamic Data Masking (masked_with / masks)#746
Open
Benjamin-Knight wants to merge 1 commit into
Open
feat: column-level Dynamic Data Masking (masked_with / masks)#746Benjamin-Knight wants to merge 1 commit into
Benjamin-Knight wants to merge 1 commit into
Conversation
Apply SQL Server Dynamic Data Masking as a post-materialization step, modelled on apply_grants, so masks are re-applied on every build and survive dbt's drop-and-recreate on full refresh. Two config surfaces resolve to one per-column mask map: - column-level `masked_with:` property in schema YAML (null opts out of an inherited default), and - model-level `masks` dict, registered with MergeBehavior.Update so it merges key-wise across dbt_project.yml / .yml / in-file config(). Column-level wins over model-level (warned); unknown columns are skipped with a warning; computed/FILESTREAM/COLUMN_SET/Always Encrypted columns error. The macro diffs desired masks against sys.masked_columns and emits only changed ADD / MASKED WITH / DROP MASKED DDL (idempotent). Wired into table, incremental, snapshot and both dml-refresh sub-paths, with masks applied before index creation on fresh builds (a mask cannot be added to a column an index depends on) and after reconcile on persisted tables. Base tables only: views inherit masking, seeds are not masked. Requires SQL Server 2016+. Tests: 18 unit (pure resolve/diff, red->green) + 10 functional against SQL Server (both surfaces, precedence, opt-out, validation, full-refresh survival, masked-user read, incremental idempotency, snapshot). Docs in README + CHANGELOG. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Applies SQL Server Dynamic Data Masking to columns as part of the materialization, so masks are re-applied on every build and survive a full-refresh rebuild. A principal with
SELECTbut notUNMASKsees masked values. Base tables only (table/incremental/snapshot); requires SQL Server 2016+. Resolve #572Config — two surfaces, use either or both
masked_with:— a first-class column property in schema YAML:{{ config(masks={'surname': "default()", 'nhs_number': 'partial(0,"XXXXXXXXXX",0)'}) }}Behaviour