cancel
Showing results for 
Search instead for 
Did you mean: 
Data Governance
Join discussions on data governance practices, compliance, and security within the Databricks Community. Exchange strategies and insights to ensure data integrity and regulatory compliance.
cancel
Showing results for 
Search instead for 
Did you mean: 

Masking Columns for a Client Workspace When You Can’t Use Catalog Binding

AdnanFaridKhan
New Contributor

Hi Everyone,

I am Adnan and I am a Cloudera Platform expert recently joined the Databricks Community. I will be sharing all my implementations and experience I have gained as Big Data Expert and any solutions I implement to address my current business problems. 

I am learning my way through Databricks as I find it interesting and great. There may be better solutions to what I have acheived but am trying to share my learnings with you. 

Recently I had to solve a problem that turned out to be more awkward than I expected: giving an external client query access to our data, from their own workspace, while guaranting that sensitive columns stay masked for them — and without exposing our main catalog to their workspace.

I'm writing this up because the "obvious" answer (catalog binding) wasn't an option to us for business reasons, and the path we ended up on has a few sharp edges that aren't obvious until you hit them. If you're in the same boat, hopefully this saves you a week.

The setup

A few facts that shaped everything:

  • We have one Unity Catalog metastore, not two. Our platform data lives in a single catalog I'll call base_catalog. The client queries from a separate workspace, and the data they're allowed to see is exposed through a second catalog I'll call client_catalog.
  • Both workspaces are on that same metastore.
  • The client connects with their own service principals over OAuth/JDBC — they never touch our workspace.
  • base_catalog already has ABAC column-mask and row-filter policies in place (national ID, names, contact numbers, etc.), driven by governed tags.

The goal: the client sees only what they're entitled to, and anything sensitive comes back masked — same as it would for an unprivileged user in our own workspace.

Why we didn't use catalog binding

As per Databricks advice, the recommended answer was read-only catalog binding: bind base_catalog to the client's workspace, and the existing ABAC policies apply natively, no extra work. We actually tried it, and it worked — masking carried over with zero effort on our side.

However we rolled it back anyway. The business requirement was to keep base_catalog isolated from the client workspace entirely — the client should never be able to see or reach our main catalog, even with policies in force. Binding makes the real catalog reachable from their workspace, and that was the line we weren't allowed to cross.

So if you can bind, bind — it's genuinely the simplest option and you can stop reading. This article is for when isolation is a hard requirement and binding is therefore off the table.

Why plain Delta Sharing / Open Sharing wasn't enough on its own

With binding gone, the natural next thought is Delta Sharing into client_catalog. Two things make this not "just work":

  1. On the same metastore, Delta Sharing behaves differently than the cross-account case. To share a table that's governed by ABAC policies at all, the share owner has to be exempt from those policies — otherwise Unity Catalog refuses with an error about the share owner being governed by the policy. The practical consequence: the data crosses into client_catalog unmasked. The masking does not travel with the share.

  2. Tags and policies don't travel either. The governed tags that drive our masking, and the ABAC policy definitions themselves, do not come across with a share. So on the client side you start with unmasked data, no tags, and no policies — i.e. nothing protecting it.

That second point is the real work. The data lands unmasked; you have to re-establish the masking on the client side. That's a fail-open window if you're not careful — data is exposed between the moment it lands and the moment masking is applied — so the rule we enforce is: no client principal gets access to a table until masking is applied and verified on it.

The approach that worked for us

The shape of the solution:

BASE WORKSPACE (base_catalog, isolated)        CLIENT WORKSPACE (client_catalog)
---------------------------------------        ---------------------------------
information_schema.column_tags
        │  (export job: MERGE → a table)
        ▼
governance.exported_tags ── Delta Share ──▶  client_catalog.governance.exported_tags
                                                    │
                                                    │  tag-sync job (diff → apply/remove)
                                                    ▼
                                            tags applied on the shared tables
                                                    │
                                   ABAC policies (pre-created on client_catalog,
                                   keyed to the same governed tags) bind to them
                                                    ▼
                                   client SP (non-exempt) reads MASKED

The key ideas:

  • base_catalog stays the single source of truth for which columns are sensitive (the tags).
  • The ABAC policies are created independently on client_catalog by our governance team — same definitions, same governed tags. They are not synced across catalogs; each catalog owns its own.
  • The only thing that actually moves automatically is tag assignments, and we built a job to keep them in sync.
  • The client service principals are non-exempt, so once a column on a client-side table carries the right tag, the client's own policy masks it.

Step 1 — export the tags as data

You can't "share" tags, but you can share a table that lists them. I export the tag assignments from base_catalog into a governance table, refreshed on a schedule with a MERGE so that (a) governance's deliberate "leave this unmasked" exceptions survive refreshes, and (b) tags removed at source get dropped:

MERGE INTO base_catalog.governance.exported_tags t
USING (
  SELECT schema_name, table_name, column_name, tag_name, tag_value, current_timestamp() AS exported_at
  FROM base_catalog.information_schema.column_tags
  WHERE tag_name IS NOT NULL
) s
ON  t.schema_name=s.schema_name AND t.table_name=s.table_name
AND t.column_name=s.column_name AND t.tag_name=s.tag_name
WHEN MATCHED THEN UPDATE SET t.tag_value=s.tag_value, t.exported_at=s.exported_at
WHEN NOT MATCHED THEN INSERT (schema_name, table_name, column_name, tag_name, tag_value, exported_at, is_exception)
                       VALUES (s.schema_name, s.table_name, s.column_name, s.tag_name, s.tag_value, s.exported_at, FALSE)
WHEN NOT MATCHED BY SOURCE THEN DELETE;

The is_exception column is how governance says "this column is PII but the client is entitled to see it, leave it unmasked" — a deliberate, recorded decision rather than an accidental gap.

Step 2 — share the data with an exempt owner

The share into client_catalog is owned by a dedicated service principal that's in the EXCEPT list of the policies. This is required — a non-exempt owner can't share a policy-governed table. That SP exists only to own the share and move data; it's not used to read anything on the client side.

I add both the data schemas/tables and the exported_tags table to the share, running the ALTER SHARE statements as that SP.

(This is the step where data lands unmasked. Everything after this is about putting the masking back before anyone can read it.)

Step 3 — policies live on the client catalog

Our governance team creates the same column-mask and row-filter policies on client_catalog, keyed to the same governed tags, with the client SPs not in the EXCEPT lists. These are separate objects from the base ones and are maintained per catalog.

Step 4 — the tag-sync job

A scheduled job diffs the exported tag list against what's actually on client_catalog and reconciles. The diff is a view:

CREATE OR REPLACE VIEW client_catalog.governance.tag_sync_diff AS
WITH src AS (
  SELECT schema_name, table_name, column_name, tag_name, is_exception
  FROM client_catalog.governance.exported_tags WHERE tag_name IS NOT NULL
),
cols AS (
  SELECT table_schema AS schema_name, table_name, column_name
  FROM client_catalog.information_schema.columns
),
tags AS (
  SELECT schema_name, table_name, column_name, tag_name
  FROM client_catalog.information_schema.column_tags WHERE tag_name IS NOT NULL
)
SELECT s.schema_name, s.table_name, s.column_name, s.tag_name, s.is_exception,
  CASE
    WHEN c.column_name IS NULL THEN 'SKIP'
    WHEN s.is_exception        THEN 'EXCEPTION'
    WHEN t.tag_name IS NULL     THEN 'ADD'
    ELSE 'PRESENT'
  END AS action
FROM src s
LEFT JOIN cols c USING (schema_name, table_name, column_name)
LEFT JOIN tags t USING (schema_name, table_name, column_name, tag_name)
UNION ALL
SELECT m.schema_name, m.table_name, m.column_name, m.tag_name, FALSE, 'REMOVE'
FROM tags m
LEFT JOIN src s USING (schema_name, table_name, column_name, tag_name)
WHERE s.schema_name IS NULL;

And the job applies it. One deliberate choice: additions apply automatically, removals are reported for review, not auto-applied — because removing a tag unmasks a column, and I didn't want a mistaken change in base_catalog to silently expose data on the client side. I also fingerprint the diff so a run with no changes exits immediately instead of scanning:

DIFF_VIEW   = "client_catalog.governance.tag_sync_diff"
STATE_TABLE = "client_catalog.governance.tag_sync_state"
CATALOG     = "`client_catalog`"
AUTO_REMOVE = False   # removals are reported, not auto-applied (unmask risk)

spark.sql(f"CREATE TABLE IF NOT EXISTS {STATE_TABLE} (fingerprint STRING, run_at TIMESTAMP, adds INT, removes INT, exceptions INT)")

fp = spark.sql(f"""SELECT md5(concat_ws('\\n', sort_array(collect_list(
       concat_ws('|', schema_name, table_name, column_name, tag_name, action))))) fp
     FROM {DIFF_VIEW}""").collect()[0]["fp"]

last = spark.sql(f"SELECT fingerprint FROM {STATE_TABLE} ORDER BY run_at DESC LIMIT 1").collect()
if last and last[0]["fingerprint"] == fp:
    dbutils.notebook.exit("NO_CHANGE")

def run(rows, verb):
    n, errs = 0, []
    for r in rows:
        try:
            spark.sql(f"ALTER TABLE {CATALOG}.`{r.schema_name}`.`{r.table_name}` "
                      f"ALTER COLUMN `{r.column_name}` {verb} TAGS ('{r.tag_name}')"); n += 1
        except Exception as e:
            errs.append(f"{verb} {r.schema_name}.{r.table_name}.{r.column_name}: {e}")
    return n, errs

adds = spark.sql(f"SELECT * FROM {DIFF_VIEW} WHERE action='ADD'").collect()
rems = spark.sql(f"SELECT * FROM {DIFF_VIEW} WHERE action='REMOVE'").collect()
exc  = spark.sql(f"SELECT COUNT(*) c FROM {DIFF_VIEW} WHERE action='EXCEPTION'").collect()[0]["c"]

a, errs = run(adds, "SET")
r = 0
if rems and AUTO_REMOVE:
    r, e2 = run(rems, "UNSET"); errs += e2
elif rems:
    print("REMOVE candidates (review — unmask risk):")
    for x in rems: print(f"  {x.schema_name}.{x.table_name}.{x.column_name} [{x.tag_name}]")

spark.sql(f"INSERT INTO {STATE_TABLE} VALUES ('{fp}', current_timestamp(), {a}, {r}, {exc})")
if errs: raise Exception("\n".join(errs))
print(f"adds={a} removes={r} exceptions={exc}")

The export job (base side) has to run before the sync job (client side), or the sync works off a stale snapshot.

Step 5 — verify as the client, not as yourself

This is the part I'd stress most, because it's where I nearly fooled myself. Aggregate checks lie — a hashed value can match a "looks like a 10-digit ID" regex and make your counts look wrong in either direction. So I verify by sampling actual values as a real, non-exempt client service principal:

SELECT <pii_column> FROM client_catalog.<schema>.<table> WHERE <pii_column> IS NOT NULL LIMIT 5;

Expect hashed. I also sweep for PII-looking columns that carry no tag — because an untagged sensitive column at source means unmasked data on the client:

SELECT c.table_schema, c.table_name, c.column_name
FROM client_catalog.information_schema.columns c
LEFT JOIN client_catalog.information_schema.column_tags t
  ON c.table_schema=t.schema_name AND c.table_name=t.table_name AND c.column_name=t.column_name
WHERE t.tag_name IS NULL
  AND lower(c.column_name) RLIKE 'phone|national|mrn|dob|birth|name|identifier|email|address';

Only after both checks pass does a client SP get granted on a table.

Things I learned the hard way

  • Tags don't travel with a share, and neither do policies. You re-apply tags (automated here) and pre-create policies per catalog. I assumed sharing would carry at least the tags; it doesn't.
  • Masking needs both a tag and a policy that acts on it. Either one missing means the column is clear, silently, with no error.
  • Row filters are tag-driven too. It's easy to focus on column masks and forget the row-filter tags, which fail silently if they're not applied.
  • Removing a tag unmasks data. I automate additions but keep removals manual/reviewed. When governance did a "swap the tag" (add new, remove old) on the source, the old tag lingered on the client side because my first version of the job only added — so I built a REMOVE path, but gated it.
  • Verify by sampling as the actual consumer. My own session is privileged; it tells me nothing about what the client sees.
  • The completeness of your source tagging becomes the control. Anything the governance team hasn't tagged is exposed. The PII-pattern sweep is how I catch the gaps, and it caught real ones.
  • If isolation isn't a hard requirement, use binding. This whole pattern exists because we couldn't. It's more moving parts than binding, and more responsibility on you to keep it correct.

Happy to answer questions in the comments if anyone's working through the same constraint. 

If you found this useful, a kudos goes a long way — it tells me this kind of write-up is worth doing, and I’ll keep sharing solutions as I hit new problems........ 

— Adnan
Data Platform Engineer · Cloudera → Databricks migrations, Unity Catalog, FinOps
Sharing what I learn as I solve it.
1 REPLY 1

rachelwilson
New Contributor II

did the tag-sync job cover the row-filter tags too, or just the column-mask ones? that's the bit i'd worry about drifting, since a missing row-filter tag fails silently the same way.