Accessing secret scope keys from Unity Catalog SQL UDFs without granting users READ permission

pxs132
Visitor

We are implementing a dynamic data masking solution on Azure Databricks using Unity Catalog ABAC policies and SQL UDFs for deterministic masking.

Our masking functions retrieve a secret key from a Databricks-backed secret scope using the secret() function.

The issue is that when users query a masked table, they appear to require READ permission on the secret scope, even though they are not the owners of the masking UDF.

Granting users READ permission defeats our security objective, as users who should only see masked data would also be able to retrieve the masking key.

My questions are:

  • Is this the expected behavior of secret() within Unity Catalog SQL UDFs?

  • Is there a supported way for a masking UDF to access a secret without granting the querying user direct access to it?

  • Would Unity Catalog Secrets or Unity Catalog External Secrets address this limitation?

Has anyone encountered a similar issue or found a recommended solution?

Any guidance would be greatly appreciated. Thanks!

Kashif_Inamdar
Databricks Employee
Databricks Employee
  1. Is this expected? Yes. The SQL secret() function reads from a workspace secret scope and checks the querying user's READ permission on that scope, even inside a mask or ABAC function owned by someone else. So it can't keep the key hidden from users who query the table.

  2. Supported approach: use a Unity Catalog secret in a UC Python UDF that declares it in the SECRETS clause. The UDF reads the secret with the function owner's permissions. Callers only need EXECUTE, with no privilege on the secret (docs).

      CREATE OR REPLACE FUNCTION gov.masking.hmac_mask(value STRING)
      RETURNS STRING
      LANGUAGE PYTHON
      DETERMINISTIC
      SECRETS (gov.masking_keys.hmac_key)
      ENVIRONMENT (environment_version = '6')
      AS $$
      import hashlib, hmac
      from databricks.secrets import get
      key = get(catalog="gov", schema="masking_keys", key="hmac_key")
      return None if value is None else hmac.new(key.encode(), value.encode(), hashlib.sha256).hexdigest()
      $$;

Wrap this in a SQL function and use it as your ABAC column-mask function.

Notes:

  • environment_version must be 6 or higher.
  • Supported compute: serverless, pro or serverless SQL warehouses, or DBR 19+ in standard access mode.
  • The function owner needs READ SECRET. Masked users don't.
  • Never return the key from the UDF.
  1. UC Secrets vs. External Secrets: both work through the SECRETS clause. External (Azure Key Vault-backed) UC secrets only change where the value is stored and rotated, not the permission model. Workspace secret scopes used with secret(), including Key Vault-backed scopes, still require READ for every caller.

Thank you very much for the detailed explanation. This confirms our findings and provides a promising direction for our data masking solution.

Azure Key Vault is our organization's preferred platform for secret management, and our Key Vault instances use the Azure RBAC permission model rather than the legacy access policy model.

We have a few follow-up questions:

  1. Our understanding is that Azure Key Vault-backed workspace secret scopes do not officially support the Azure RBAC permission model. Is Azure RBAC fully supported when using Unity Catalog External Secrets?

  2. We understand that Unity Catalog External Secrets is currently in Beta. Is there an anticipated timeline for General Availability (GA)? Would Databricks recommend using this feature in an enterprise production environment at its current stage?

  3. Is the proposed approach of wrapping a secret-enabled Python UDF in a SQL UDF fully supported for ABAC column masking, or are there any known limitations?

  4. Are there any plans to support Unity Catalog secrets directly within native SQL UDFs? This would allow us to retain the performance advantages of our existing SQL-based masking implementation without introducing Python UDF execution overhead.

We would appreciate any further guidance. Thanks again for your help!