Wednesday
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.
A few facts that shaped everything:
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.
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.
With binding gone, the natural next thought is Delta Sharing into client_catalog. Two things make this not "just work":
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.
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 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 MASKEDThe key ideas:
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.
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.)
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.
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.
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.
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........
Saturday
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.