Mask sensitive columns in a semantic model by role
Mask sensitive columns in a physical model per caller role using an access policy, column_mask_expressions, and an auth extension that maps DataOS roles to policy groups: no forked pipelines or models
A semantic model usually has more than one audience. An operator might need to query customer activity without ever seeing raw email addresses or names; a developer debugging the same pipeline needs the real values. The naive fix is two models, or two pipelines, one masked and one not, which means two things to keep in sync every time either changes.
Vulcan avoids the fork: a single semantic model can serve both audiences differently at query time. Row filters and column masks are authored once, against the physical model the semantic model wraps, as a policy under policies/access/. The semantic model inherits that policy automatically; it never authors access rules itself. The bridge between "who is calling" and "which policy group applies" is an after_authorize auth extension you write once per project.
Before you begin
Steps
1. Write the auth extension hook
Create plugins/__init__.py (empty: it just marks the folder as a package) and plugins/auth_ext.py. The hook reads DataOS role tags off the request and resolves them into a SecurityContext.
# plugins/auth_ext.py
from __future__ import annotations
from schema.auth import AuthExtensionContext, SecurityContext
ROLE_ID_TAG_PREFIX = "roles:id:"
GROUP_DELIMITER = ","
POLICY_GROUP_PRIORITY = ("operator", "developer")
async def resolve_user_groups(ctx: AuthExtensionContext) -> SecurityContext:
"""Derive policy groups from DataOS role tags."""
groups = [
tag.replace(ROLE_ID_TAG_PREFIX, "", 1)
for tag in ctx.user_tags
if tag.startswith(ROLE_ID_TAG_PREFIX)
]
group = next(
(policy_group for policy_group in POLICY_GROUP_PRIORITY if policy_group in groups),
groups[0] if groups else "",
)
return SecurityContext(group=group, groups=GROUP_DELIMITER.join(groups))ctx.user_tags carries the caller's DataOS role tags (e.g. roles:id:operator). POLICY_GROUP_PRIORITY decides which group wins when a caller holds more than one role. Reorder it to match how your roles should rank. The returned group is what policies match against; groups is the full comma-separated list, useful if a policy ever needs to check for more than one role at once.
2. Wire the hook in config.yaml
The value is <package>.<module>:<function>. Vulcan imports plugins.auth_ext and calls resolve_user_groups after DataOS authorizes each request.
3. Define the mask on the physical model
Masking is defined on the physical model, not the semantic model. Add a column_mask_expressions entry for every column you plan to mask, in the MODEL(...) block of the physical model the semantic model wraps:
Pick NULL when downstream consumers should treat the field as absent, or a fixed string like '***' when they need a visibly redacted placeholder instead. Every column a policy rule later masks must have a matching entry here, or vulcan plan fails with column_mask_expression is missing for proposed masking on column <name>.
4. Add an access policy for the physical model
Create a policy file under policies/access/, one file per physical model that needs access control. Set type: policy and a single depends_on entry pointing at the physical model. Pointing depends_on at a semantic or metric model instead fails outright with attach policy to a physical model only.
A rule with only group (here, developer) grants that group unrestricted access. group is required and must be lowercase snake_case, matching ^[a-z][a-z0-9_]{0,63}$. mask takes only bare column names; the actual masking SQL lives in column_mask_expressions on the physical model (step 3), not here. A caller resolving to operator can query the model, but email and customer_name come back masked, and rows where customer_segment = 'Churned' are filtered out entirely.
The semantic model itself doesn't declare any of this. It wraps the physical model with dimensions as usual, nothing more:
At export time, Vulcan resolves customer_profile's physical anchor (silver.dim_customer_profile) and pulls that anchor's policy and column_mask_expressions, so the semantic layer reflects the physical model's access rules without redeclaring them.
Run vulcan plan to confirm the policy and physical model validate: Vulcan checks that every policy group, masked column, and filter reference resolves to something real.
5. Confirm the same query returns different results per role
Once deployed, query the model with two identities that resolve to different groups. Same query, two bearer tokens:
The POST returns 202 Accepted with a statement id. Poll GET .../api/v1/query/statement/<id> until its status is SUCCESS, then fetch GET .../api/v1/query/statement/<id>/result?format=json. The operator's final result, abbreviated:
After the same submit, poll, and fetch, the developer's final result, abbreviated:
Same semantic model, same query, no forked pipeline: the caller's resolved role is the only thing that changed the response.
Common validation failures
Policy
depends_ondoesn't resolve to a physical model. Fails withattach policy to a physical model only. Pointdepends_onat the physical model backing the semantic model, not at the semantic or metric model itself.A masked column has no matching
column_mask_expressionsentry.vulcan planfails withcolumn_mask_expression is missing for proposed masking on column <name>. Add the expression to the physical model'sMODEL(...)block before deploying.after_authorizeisn't configured. No group ever resolves, so no policy rule matches and access is denied by default (COMMON.AUTH.FORBIDDEN). Confirm step 2 is in place first.groupisn't lowercase snake_case. Every rule'sgroupmust match^[a-z][a-z0-9_]{0,63}$.
Best practices
Keep policy groups aligned 1:1 with your role taxonomy so a caller with multiple roles resolves to one predictable group via
POLICY_GROUP_PRIORITY, not an ambiguous one.Give every masked column an explicit
column_mask_expressionsentry on the physical model. Restricted callers should get a defined placeholder, never an error.Test with two real identities against a deployed endpoint, not just by reading the YAML. Policy bugs usually only show up at query time.
Keep
plugins/auth_ext.pynarrow: it derives groups from role tags, nothing more. Masking and filtering rules belong in the physical model'scolumn_mask_expressionsand the policy file underpolicies/access/, not in the auth hook.If a masked column is also a rollup group-by dimension, keep its
column_mask_expressionsvalue constant (see the rollup hint in step 4).
Troubleshooting
Every caller is denied with COMMON.AUTH.FORBIDDEN, regardless of role
after_authorize isn't configured in config.yaml, so no group ever resolves and access is denied by default
Add after_authorize: "plugins.auth_ext:resolve_user_groups" and confirm plugins/ imports cleanly
vulcan plan fails with attach policy to a physical model only
The policy's depends_on points at a semantic or metric model instead of a physical model
Point depends_on at the physical model backing the semantic model
vulcan plan fails with column_mask_expression is missing for proposed masking on column <name>
A policy rule's mask lists a column with no matching column_mask_expressions entry
Add the expression to the physical model's MODEL(...) block
A user with two roles gets the wrong access level
POLICY_GROUP_PRIORITY resolves to the wrong role first
Reorder POLICY_GROUP_PRIORITY in auth_ext.py
A filter policy doesn't hide the expected rows
The filter's member/operator/values don't match the real data (case, exact string)
Re-check the filter block against actual column values
Masking "works" in local testing but not in production
Local test queried via fetchdf/direct connection, bypassing the API auth layer
Re-test against the deployed API endpoint with real tokens
A rollup dimension's mask is rejected at plan time
column_mask_expressions for that column references a value (e.g. CONCAT(...)) instead of a constant
Use a constant expression, such as CAST(NULL AS TIMESTAMP) or a string literal, for any column used as a rollup group-by dimension
Related recipes
Route plan and run failures to Slack or Teams - wire the same project to alert on a
vulcan planfailure, including one caused by an invalid policy.
References
Policies -
policies/access/*.yml,column_mask_expressions, rule schema, rollup constraints, and physical-model-only inheritance.Plugins and auth - the
plugins/folder,after_authorize,AuthExtensionContext, andSecurityContext.
Last updated
Was this helpful?