cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

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

pxs132
New Contributor II

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!

1 ACCEPTED SOLUTION

Accepted Solutions

Louis_Frolio
Databricks Employee
Databricks Employee

Greetings @pxs132, I did some digging and here is what I found.

@Kashif_Inamdar's answer matches the current docs: secret() runs with the caller's permissions, and a Unity Catalog Python UDF with the SECRETS clause is the supported fix. On your four follow-ups:

  • Azure RBAC. Yes. Your read on workspace secret scopes is right (Vault access policy only). External secrets authenticate through a Unity Catalog service credential, and the docs have you grant its managed identity or service principal the Key Vault Secrets User role. An access policy with get and list works too.
  • GA and production use. External secrets are still in Beta, and no GA date has been published. Beta means not intended for production and no SLA, so I wouldn't put an enterprise masking key behind it yet. Databricks-managed Unity Catalog secrets went GA on August 3, 2026, and they use the same SECRETS clause and permission model. Start there and move to a Key Vault-backed schema at GA. A schema holds one type or the other, never both, so plan the switch around that.
  • SQL wrapper for ABAC masks. Documented and supported. The Python UDF needs environment_version 6 or above, and it runs on serverless compute, pro or serverless SQL warehouses, or Databricks Runtime 19 and above in standard access mode. On dedicated access mode the mask still works, because Databricks enforces it on serverless. Keep DETERMINISTIC on the Python UDF so filters can still push down. With Key Vault-backed secrets, each read adds latency. I haven't measured that inside a mask, so benchmark on at least a million rows first.
  • Secrets in native SQL UDFs. Not available today. The SECRETS clause covers Python and Scala UDFs only, and I'm not aware of a public roadmap item, so raise it with your account team. To trim the Python overhead, put exempt users in the policy's EXCEPT clause so the UDF never runs for them.

Plain and simple: the pattern works in production today with a Databricks-managed secret, and Key Vault backing is a Beta decision for now.

References:

If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.

Regards, Louis.

View solution in original post

4 REPLIES 4

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!

Louis_Frolio
Databricks Employee
Databricks Employee

Greetings @pxs132, I did some digging and here is what I found.

@Kashif_Inamdar's answer matches the current docs: secret() runs with the caller's permissions, and a Unity Catalog Python UDF with the SECRETS clause is the supported fix. On your four follow-ups:

  • Azure RBAC. Yes. Your read on workspace secret scopes is right (Vault access policy only). External secrets authenticate through a Unity Catalog service credential, and the docs have you grant its managed identity or service principal the Key Vault Secrets User role. An access policy with get and list works too.
  • GA and production use. External secrets are still in Beta, and no GA date has been published. Beta means not intended for production and no SLA, so I wouldn't put an enterprise masking key behind it yet. Databricks-managed Unity Catalog secrets went GA on August 3, 2026, and they use the same SECRETS clause and permission model. Start there and move to a Key Vault-backed schema at GA. A schema holds one type or the other, never both, so plan the switch around that.
  • SQL wrapper for ABAC masks. Documented and supported. The Python UDF needs environment_version 6 or above, and it runs on serverless compute, pro or serverless SQL warehouses, or Databricks Runtime 19 and above in standard access mode. On dedicated access mode the mask still works, because Databricks enforces it on serverless. Keep DETERMINISTIC on the Python UDF so filters can still push down. With Key Vault-backed secrets, each read adds latency. I haven't measured that inside a mask, so benchmark on at least a million rows first.
  • Secrets in native SQL UDFs. Not available today. The SECRETS clause covers Python and Scala UDFs only, and I'm not aware of a public roadmap item, so raise it with your account team. To trim the Python overhead, put exempt users in the policy's EXCEPT clause so the UDF never runs for them.

Plain and simple: the pattern works in production today with a Databricks-managed secret, and Key Vault backing is a Beta decision for now.

References:

If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.

Regards, Louis.

pxs132
New Contributor II

Thank you, @Louis_Frolio, very much for the detailed response and references. This is extremely helpful.

The clarification regarding the GA status of Databricks-managed UC Secrets versus the Beta status of UC External Secrets is particularly valuable for our assessment.

Your confirmation of the SQL wrapper approach is also consistent with our preliminary POC findings. However, the significant Python UDF performance overhead remains a concern for our use case.

We will continue our technical evaluation and internal discussions before determining the most appropriate approach.

Support for secure secret access directly within native SQL UDFs would be particularly valuable, and we will raise this requirement with our Databricks account team.

Thanks again for taking the time to investigate and address all our questions!